Bug 17600: Standardize our EXPORT_OK
[koha.git] / Koha / SearchField.pm
1 package Koha::SearchField;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20
21 use Koha::Database;
22
23 use base qw(Koha::Object);
24
25 =head1 NAME
26
27 Koha::SearchField - Koha SearchField Object class
28
29 =head1 API
30
31 =head2 Class Methods
32
33 =cut
34
35 sub add_to_search_marc_maps {
36     my ( $self, $search_field, $params ) = @_;
37     return $self->_result()->add_to_search_marc_maps($search_field->_result, $params);
38 }
39
40 =head3 search_marc_maps
41
42 my $search_marc_maps = $search_field->search_marc_maps;
43
44 =cut
45
46 sub search_marc_maps {
47     my ( $self ) = @_;
48
49     my $marc_type = lc C4::Context->preference('marcflavour');
50
51     my $schema = Koha::Database->new->schema;
52     my $marc_map_fields = $schema->resultset('SearchMarcToField')->search(
53         {
54             'me.search_field_id'        => $self->id,
55             'search_marc_map.marc_type' => $marc_type
56         },
57         {
58             select => [
59                 'search_marc_map.index_name',
60                 'search_marc_map.marc_type',
61                 'search_marc_map.marc_field'
62             ],
63             as => [ 'index_name', 'marc_type', 'marc_field' ],
64             join => 'search_marc_map'
65         }
66     );
67
68     return $marc_map_fields;
69 }
70
71 =head3 is_mapped_biblios
72
73 my $is_mapped_biblios = $search_field->is_mapped_biblios
74
75 =cut
76
77 sub is_mapped_biblios {
78     my ( $self ) = @_;
79
80     return $self->search_marc_maps->search(
81         {
82             index_name => 'biblios'
83         }
84     )->count ? 1 : 0;
85 }
86
87 =head3 type
88
89 =cut
90
91 sub _type {
92     return 'SearchField';
93 }
94
95 1;