1 package Koha
::Authority
;
3 # Copyright 2012 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 3 of the License, or (at your option) any later
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.
22 Koha::Authority - class to encapsulate authority records in Koha
26 Object-oriented class that encapsulates authority records in Koha.
42 use base
qw(Koha::MetadataRecord);
44 __PACKAGE__
->mk_accessors(qw( authid authtype ));
48 my $auth = Koha::Authority->new($record);
50 Create a new Koha::Authority object based on the provided record.
58 my $self = $class->SUPER::new
(
61 'schema' => lc C4
::Context
->preference("marcflavour")
70 =head2 get_from_authid
72 my $auth = Koha::Authority->get_from_authid($authid);
74 Create the Koha::Authority object associated with the provided authid.
75 Note that this routine currently retrieves a MARC record because
76 authorities in Koha are MARC records by definition. This is an
77 unfortunate but unavoidable fact.
84 my $marcflavour = lc C4
::Context
->preference("marcflavour");
86 my $dbh=C4
::Context
->dbh;
87 my $sth=$dbh->prepare("select authtypecode, marcxml from auth_header where authid=?");
88 $sth->execute($authid);
89 my ($authtypecode, $marcxml) = $sth->fetchrow;
90 my $record=eval {MARC
::Record
->new_from_xml(StripNonXmlChars
($marcxml),'UTF-8',
91 (C4
::Context
->preference("marcflavour") eq "UNIMARC"?
"UNIMARCAUTH":C4
::Context
->preference("marcflavour")))};
93 $record->encoding('UTF-8');
95 # NOTE: GuessAuthTypeCode has no business in Koha::Authority, which is an
96 # object-oriented class. Eventually perhaps there will be utility
97 # classes in the Koha:: namespace, but there are not at the moment,
98 # so this shim seems like the best option all-around.
99 require C4
::AuthoritiesMarc
;
100 $authtypecode ||= C4
::AuthoritiesMarc
::GuessAuthTypeCode
($record);
102 my $self = $class->SUPER::new
( { authid
=> $authid,
103 authtype
=> $authtypecode,
104 schema
=> $marcflavour,
105 record
=> $record });
111 =head2 get_from_breeding
113 my $auth = Koha::Authority->get_from_authid($authid);
115 Create the Koha::Authority object associated with the provided authid.
119 sub get_from_breeding
{
121 my $import_record_id = shift;
122 my $marcflavour = lc C4
::Context
->preference("marcflavour");
124 my $dbh=C4
::Context
->dbh;
125 my $sth=$dbh->prepare("select marcxml from import_records where import_record_id=? and record_type='auth';");
126 $sth->execute($import_record_id);
127 my $marcxml = $sth->fetchrow;
128 my $record=eval {MARC
::Record
->new_from_xml(StripNonXmlChars
($marcxml),'UTF-8',
129 (C4
::Context
->preference("marcflavour") eq "UNIMARC"?
"UNIMARCAUTH":C4
::Context
->preference("marcflavour")))};
131 $record->encoding('UTF-8');
133 # NOTE: GuessAuthTypeCode has no business in Koha::Authority, which is an
134 # object-oriented class. Eventually perhaps there will be utility
135 # classes in the Koha:: namespace, but there are not at the moment,
136 # so this shim seems like the best option all-around.
137 require C4
::AuthoritiesMarc
;
138 my $authtypecode = C4
::AuthoritiesMarc
::GuessAuthTypeCode
($record);
140 my $self = $class->SUPER::new
( {
141 schema
=> $marcflavour,
142 authtype
=> $authtypecode,
143 record
=> $record });
149 sub authorized_heading
{
151 if ($self->schema =~ m/marc/) {
152 return Koha
::Util
::MARC
::getAuthorityAuthorizedHeading
($self->record, $self->schema);