File Coverage

File:C4/Linker/Default.pm
Coverage:27.3%

linestmtbrancondsubtimecode
1package C4::Linker::Default;
2
3# Copyright 2011 C & P Bibliography Services
4#
5# This file is part of Koha.
6#
7# Koha is free software; you can redistribute it and/or modify it under the
8# terms of the GNU General Public License as published by the Free Software
9# Foundation; either version 2 of the License, or (at your option) any later
10# version.
11#
12# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with Koha; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
1
1
1
7
5
67
use strict;
21
1
1
1
5
1
29
use warnings;
22
1
1
1
5
2
52
use Carp;
23
1
1
1
5
1
21
use MARC::Field;
24
1
1
1
29
2
45
use C4::Heading;
25
26
1
1
1
5
1
91
use base qw(C4::Linker);
27
28sub get_link {
29
0
    my $self = shift;
30
0
    my $heading = shift;
31
0
    my $behavior = shift || 'default';
32
0
    my $search_form = $heading->search_form();
33
0
    my $authid;
34
0
    my $fuzzy = 0;
35
36
0
    if ( $self->{'cache'}->{$search_form}->{'cached'} ) {
37
0
        $authid = $self->{'cache'}->{$search_form}->{'authid'};
38
0
        $fuzzy = $self->{'cache'}->{$search_form}->{'fuzzy'};
39    }
40    else {
41
42        # look for matching authorities
43
0
        my $authorities = $heading->authorities(1); # $skipmetadata = true
44
45
0
0
0
        if ( $behavior eq 'default' && $#{$authorities} == 0 ) {
46
0
            $authid = $authorities->[0]->{'authid'};
47        }
48
0
        elsif ( $behavior eq 'first' && $#{$authorities} >= 0 ) {
49
0
            $authid = $authorities->[0]->{'authid'};
50
0
0
            $fuzzy = $#{$authorities} > 0;
51        }
52        elsif ( $behavior eq 'last' && $#{$authorities} >= 0 ) {
53
0
0
            $authid = $authorities->[ $#{$authorities} ]->{'authid'};
54
0
0
            $fuzzy = $#{$authorities} > 0;
55        }
56
57
0
        if ( !defined $authid && $self->{'broader_headings'} ) {
58
0
            my $field = $heading->field();
59
0
            my @subfields = $field->subfields();
60
0
            if ( scalar @subfields > 1 ) {
61
0
                pop @subfields;
62
0
                $field->replace_with(
63                    MARC::Field->new(
64                        $field->tag,
65                        $field->indicator(1),
66                        $field->indicator(2),
67
0
                        map { $_[0] => $_[1] } @subfields
68                    )
69                );
70
0
                ( $authid, $fuzzy ) =
71                  $self->get_link( C4::Heading->new_from_bib_field($field),
72                    $behavior );
73            }
74        }
75
76
0
        $self->{'cache'}->{$search_form}->{'cached'} = 1;
77
0
        $self->{'cache'}->{$search_form}->{'authid'} = $authid;
78
0
        $self->{'cache'}->{$search_form}->{'fuzzy'} = $fuzzy;
79    }
80
0
    return $self->SUPER::_handle_auth_limit($authid), $fuzzy;
81}
82
83sub flip_heading {
84
0
    my $self = shift;
85
0
    my $heading = shift;
86
87    # TODO: implement
88}
89
901;