File Coverage

File:C4/Linker.pm
Coverage:30.3%

linestmtbrancondsubtimecode
1package C4::Linker;
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 - 43
=head1 NAME

C4::Linker - Base class for linking authorities to bibliographic records

=head1 SYNOPSIS

  use C4::Linker (%params );

=head1 DESCRIPTION

Base class for C4::Linker::X. Subclasses need to provide the following methods

B<get_link ($field)> - return the authid for the authority that should be
linked to the provided MARC::Field object, and a boolean to indicate whether
the match is "fuzzy" (the semantics of "fuzzy" are up to the individual plugin).
In order to handle authority limits, get_link should always end with:
    return $self->SUPER::_handle_auth_limit($authid), $fuzzy;

B<flip_heading ($field)> - return a MARC::Field object with the heading flipped
to the preferred form.

=head1 FUNCTIONS

=cut
44
45
19
19
19
71
22
461
use strict;
46
19
19
19
96
21
725
use warnings;
47
19
19
19
78
21
1162
use Carp;
48
19
19
19
78
22
215
use C4::Context;
49
50
19
19
19
77
25
6813
use base qw(Class::Accessor);
51
52__PACKAGE__->mk_accessors(qw( ));
53
54sub new {
55
0
    my $class = shift;
56
0
    my $param = shift;
57
58
0
    my $self = {};
59
60
0
    while ( my ( $key, $value ) = each %$param ) {
61
0
        if ( $key eq 'auth_limit' && $value ) {
62
0
            my $dbh = C4::Context->dbh;
63
0
            my $sql =
64              "SELECT authid FROM auth_header WHERE $value ORDER BY authid ASC";
65
0
            my $sth = $dbh->prepare($sql);
66
0
            $sth->execute();
67
0
            while ( my ($authid) = $sth->fetchrow_array() ) {
68
0
0
                push @{ $self->{'auths_to_link'} }, $authid;
69            }
70        }
71        elsif ( $key eq 'options' && $value ) {
72
0
            foreach my $opt ( split( /\|/, $value ) ) {
73
0
                $self->{$opt} = 1;
74            }
75        }
76        elsif ($value) {
77
0
            $self->{$key} = $value;
78        }
79    }
80
81
0
    bless $self, $class;
82
0
    return $self;
83}
84
85 - 91
=head2 _handle_auth_limit

    return $self->SUPER::_handle_auth_limit($authid), $fuzzy;

Function to be called by subclasses to handle authority record limits.

=cut
92
93sub _handle_auth_limit {
94
0
    my $self = shift;
95
0
    my $authid = shift;
96
97
0
0
0
    if ( defined $self->{'auths_to_link'} && defined $authid && !grep { $_ == $authid }
98        @{ $self->{'auths_to_link'} } )
99    {
100
0
        undef $authid;
101    }
102
0
    return $authid;
103}
104
105 - 117
=head2 EXPORT

None by default.

=head1 SEE ALSO

C4::Linker::Default

=head1 AUTHOR

Jared Camins-Esakov, C & P Bibliography Services, E<lt>jcamins@cpbibliography.comE<gt>

=cut
118
1191;
120