Bug 12177 - Remove HTML from authorities.pl
[koha.git] / C4 / Linker.pm
blob270885976f01e7264fadc144fe528a55ade4dee7
1 package C4::Linker;
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 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.
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.
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.
20 =head1 NAME
22 C4::Linker - Base class for linking authorities to bibliographic records
24 =head1 SYNOPSIS
26 use C4::Linker (%params );
28 =head1 DESCRIPTION
30 Base class for C4::Linker::X. Subclasses need to provide the following methods
32 B<get_link ($field)> - return the authid for the authority that should be
33 linked to the provided MARC::Field object, and a boolean to indicate whether
34 the match is "fuzzy" (the semantics of "fuzzy" are up to the individual plugin).
35 In order to handle authority limits, get_link should always end with:
36 return $self->SUPER::_handle_auth_limit($authid), $fuzzy;
38 B<update_cache ($heading, $authid)> - updates internal linker cache for
39 $heading with $authid of a new created authotiry record
41 B<flip_heading ($field)> - return a MARC::Field object with the heading flipped
42 to the preferred form.
44 =head1 FUNCTIONS
46 =cut
48 use strict;
49 use warnings;
50 use Carp;
51 use C4::Context;
53 use base qw(Class::Accessor);
55 __PACKAGE__->mk_accessors(qw( ));
57 sub new {
58 my $class = shift;
59 my $param = shift;
61 my $self = {};
63 while ( my ( $key, $value ) = each %$param ) {
64 if ( $key eq 'auth_limit' && $value ) {
65 my $dbh = C4::Context->dbh;
66 my $sql =
67 "SELECT authid FROM auth_header WHERE $value ORDER BY authid ASC";
68 my $sth = $dbh->prepare($sql);
69 $sth->execute();
70 while ( my ($authid) = $sth->fetchrow_array() ) {
71 push @{ $self->{'auths_to_link'} }, $authid;
74 elsif ( $key eq 'options' && $value ) {
75 foreach my $opt ( split( /\|/, $value ) ) {
76 $self->{$opt} = 1;
79 elsif ($value) {
80 $self->{$key} = $value;
84 bless $self, $class;
85 return $self;
88 =head2 _handle_auth_limit
90 return $self->SUPER::_handle_auth_limit($authid), $fuzzy;
92 Function to be called by subclasses to handle authority record limits.
94 =cut
96 sub _handle_auth_limit {
97 my $self = shift;
98 my $authid = shift;
100 if ( defined $self->{'auths_to_link'} && defined $authid && !grep { $_ == $authid }
101 @{ $self->{'auths_to_link'} } )
103 undef $authid;
105 return $authid;
108 =head2 EXPORT
110 None by default.
112 =head1 SEE ALSO
114 C4::Linker::Default
116 =head1 AUTHOR
118 Jared Camins-Esakov, C & P Bibliography Services, E<lt>jcamins@cpbibliography.comE<gt>
120 =cut
124 __END__