Bug 24603: Allow to cancel charges in patron accounting
[koha.git] / C4 / Linker / Default.pm
blob934e87536a2c38592de44ced3cf11d6cc7571e7a
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 $auth_type = $heading->auth_type();
34 my $authid;
35 my $fuzzy = 0;
36 my $match_count;
38 if ( $self->{'cache'}->{$search_form.$auth_type}->{'cached'} ) {
39 $authid = $self->{'cache'}->{$search_form.$auth_type}->{'authid'};
40 $fuzzy = $self->{'cache'}->{$search_form.$auth_type}->{'fuzzy'};
42 else {
44 # look for matching authorities
45 my $authorities = $heading->authorities(1); # $skipmetadata = true
46 $match_count = scalar @$authorities;
48 if ( $behavior eq 'default' && $#{$authorities} == 0 ) {
49 $authid = $authorities->[0]->{'authid'};
51 elsif ( $behavior eq 'first' && $#{$authorities} >= 0 ) {
52 $authid = $authorities->[0]->{'authid'};
53 $fuzzy = $#{$authorities} > 0;
55 elsif ( $behavior eq 'last' && $#{$authorities} >= 0 ) {
56 $authid = $authorities->[ $#{$authorities} ]->{'authid'};
57 $fuzzy = $#{$authorities} > 0;
60 if ( !defined $authid && $self->{'broader_headings'} ) {
61 my $field = $heading->field();
62 my @subfields = grep { $_->[0] ne '9' } $field->subfields();
63 if ( scalar @subfields > 1 ) {
64 pop @subfields;
65 $field =
66 MARC::Field->new(
67 $field->tag,
68 $field->indicator(1),
69 $field->indicator(2),
70 map { $_->[0] => $_->[1] } @subfields
72 ( $authid, $fuzzy ) =
73 $self->get_link( C4::Heading->new_from_field($field),
74 $behavior );
78 $self->{'cache'}->{$search_form.$auth_type}->{'cached'} = 1;
79 $self->{'cache'}->{$search_form.$auth_type}->{'authid'} = $authid;
80 $self->{'cache'}->{$search_form.$auth_type}->{'fuzzy'} = $fuzzy;
82 return $self->SUPER::_handle_auth_limit($authid), $fuzzy, $match_count;
85 sub update_cache {
86 my $self = shift;
87 my $heading = shift;
88 my $authid = shift;
89 my $search_form = $heading->search_form();
90 my $auth_type = $heading->auth_type();
91 my $fuzzy = 0;
93 $self->{'cache'}->{$search_form.$auth_type}->{'cached'} = 1;
94 $self->{'cache'}->{$search_form.$auth_type}->{'authid'} = $authid;
95 $self->{'cache'}->{$search_form.$auth_type}->{'fuzzy'} = $fuzzy;
98 sub flip_heading {
99 my $self = shift;
100 my $heading = shift;
102 # TODO: implement
106 __END__
108 =head1 NAME
110 C4::Linker::Default - match only if there is a single matching auth
112 =cut