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