Bug 18316: Ability to weight search fields
[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 use Koha::SearchMarcMaps;
24
25 use base qw(Koha::Object);
26
27 =head1 NAME
28
29 Koha::SearchField - Koha SearchField Object class
30
31 =head1 API
32
33 =head2 Class Methods
34
35 =cut
36
37 sub add_to_search_marc_maps {
38     my ( $self, $search_field, $params ) = @_;
39     return $self->_result()->add_to_search_marc_maps($search_field->_result, $params);
40 }
41
42 =head3 search_marc_maps
43
44 my $search_marc_maps = $search_field->search_marc_maps;
45
46 =cut
47
48 sub search_marc_maps {
49     my ( $self ) = @_;
50
51     my $marc_type = lc C4::Context->preference('marcflavour');
52     my @marc_maps = ();
53
54     my $schema = Koha::Database->new->schema;
55     my @marc_map_fields = $schema->resultset('SearchMarcToField')->search({
56         search_field_id => $self->id
57     });
58
59     return @marc_maps unless @marc_map_fields;
60
61     foreach my $marc_field ( @marc_map_fields ) {
62         my $marc_map = Koha::SearchMarcMaps->find( $marc_field->search_marc_map_id );
63         push @marc_maps, $marc_map if $marc_map->marc_type eq $marc_type;
64     }
65
66     return @marc_maps;
67
68 }
69
70 =head3 is_mapped_biblios
71
72 my $is_mapped_biblios = $search_field->is_mapped_biblios
73
74 =cut
75
76 sub is_mapped_biblios {
77     my ( $self ) = @_;
78
79     foreach my $marc_map ( $self->search_marc_maps ) {
80         return 1 if $marc_map->index_name eq 'biblios';
81     }
82
83     return 0;
84 }
85
86 =head3 type
87
88 =cut
89
90 sub _type {
91     return 'SearchField';
92 }
93
94 1;