Bug 15395: Allow correct handling of plural translation
[koha.git] / C4 / Linker / Default.pm
blobb39557cbb7c5f03e45e3be4ef7321a098b22e7f0
1 package C4::Linker::Default;
3 # Copyright 2011 C & P Bibliography Services
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use strict;
21 use warnings;
22 use Carp;
23 use MARC::Field;
24 use C4::Heading;
26 use base qw(C4::Linker);
28 sub get_link {
29 my $self = shift;
30 my $heading = shift;
31 my $behavior = shift || 'default';
32 my $search_form = $heading->search_form();
33 my $authid;
34 my $fuzzy = 0;
36 if ( $self->{'cache'}->{$search_form}->{'cached'} ) {
37 $authid = $self->{'cache'}->{$search_form}->{'authid'};
38 $fuzzy = $self->{'cache'}->{$search_form}->{'fuzzy'};
40 else {
42 # look for matching authorities
43 my $authorities = $heading->authorities(1); # $skipmetadata = true
45 if ( $behavior eq 'default' && $#{$authorities} == 0 ) {
46 $authid = $authorities->[0]->{'authid'};
48 elsif ( $behavior eq 'first' && $#{$authorities} >= 0 ) {
49 $authid = $authorities->[0]->{'authid'};
50 $fuzzy = $#{$authorities} > 0;
52 elsif ( $behavior eq 'last' && $#{$authorities} >= 0 ) {
53 $authid = $authorities->[ $#{$authorities} ]->{'authid'};
54 $fuzzy = $#{$authorities} > 0;
57 if ( !defined $authid && $self->{'broader_headings'} ) {
58 my $field = $heading->field();
59 my @subfields = grep { $_->[0] ne '9' } $field->subfields();
60 if ( scalar @subfields > 1 ) {
61 pop @subfields;
62 $field =
63 MARC::Field->new(
64 $field->tag,
65 $field->indicator(1),
66 $field->indicator(2),
67 map { $_->[0] => $_->[1] } @subfields
69 ( $authid, $fuzzy ) =
70 $self->get_link( C4::Heading->new_from_bib_field($field),
71 $behavior );
75 $self->{'cache'}->{$search_form}->{'cached'} = 1;
76 $self->{'cache'}->{$search_form}->{'authid'} = $authid;
77 $self->{'cache'}->{$search_form}->{'fuzzy'} = $fuzzy;
79 return $self->SUPER::_handle_auth_limit($authid), $fuzzy;
82 sub update_cache {
83 my $self = shift;
84 my $heading = shift;
85 my $authid = shift;
86 my $search_form = $heading->search_form();
87 my $fuzzy = 0;
89 $self->{'cache'}->{$search_form}->{'cached'} = 1;
90 $self->{'cache'}->{$search_form}->{'authid'} = $authid;
91 $self->{'cache'}->{$search_form}->{'fuzzy'} = $fuzzy;
94 sub flip_heading {
95 my $self = shift;
96 my $heading = shift;
98 # TODO: implement
102 __END__
104 =head1 NAME
106 C4::Linker::Default - match only if there is a single matching auth
108 =cut