X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=Koha%2FAuthority.pm;h=ac2b25c310e10c10c22c559eba47388b85c9bc4d;hb=662a98345a71fb170bc6ae5b3679e3edf4eee96f;hp=b07db92895f96e813020ca9b019177ecd097e370;hpb=84825be42adf4a50b77360cf016cd5bfee15c072;p=koha.git diff --git a/Koha/Authority.pm b/Koha/Authority.pm index b07db92895..ac2b25c310 100644 --- a/Koha/Authority.pm +++ b/Koha/Authority.pm @@ -1,12 +1,12 @@ package Koha::Authority; -# Copyright 2012 C & P Bibliography Services +# Copyright 2015 Koha Development Team # # This file is part of Koha. # # Koha is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later +# Foundation; either version 3 of the License, or (at your option) any later # version. # # Koha is distributed in the hope that it will be useful, but WITHOUT ANY @@ -17,76 +17,56 @@ package Koha::Authority; # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -=head1 NAME +use Modern::Perl; -Koha::Authority - class to encapsulate authority records in Koha +use base qw(Koha::Object); +use Koha::SearchEngine::Search; -=head1 SYNOPSIS +=head1 NAME -Object-oriented class that encapsulates authority records in Koha. +Koha::Authority - Koha Authority Object class -=head1 DESCRIPTION +=head1 API -Authority data. +=head2 Instance Methods -=cut +=head3 get_usage_count -use strict; -use warnings; -use C4::Context; -use MARC::Record; -use MARC::File::XML; -use C4::Charset; + $count = $self->get_usage_count; -use base qw(Class::Accessor); + Returns the number of linked biblio records. -__PACKAGE__->mk_accessors(qw( authid authtype record marcflavour )); +=cut -=head2 new +sub get_usage_count { + my ( $self ) = @_; + return Koha::Authorities->get_usage_count({ authid => $self->authid }); +} - my $auth = Koha::Authority->new($record); +=head3 linked_biblionumbers -Create a new Koha::Authority object based on the provided record. + my @biblios = $self->linked_biblionumbers({ + [ max_results => $max ], [ offset => $offset ], + }); -=cut -sub new { - my $class = shift; - my $record = shift; + Returns an array of biblionumbers. - my $self = $class->SUPER::new( { record => $record }); +=cut - bless $self, $class; - return $self; +sub linked_biblionumbers { + my ( $self, $params ) = @_; + $params->{authid} = $self->authid; + return Koha::Authorities->linked_biblionumbers( $params ); } -=head2 get_from_authid +=head2 Class Methods - my $auth = Koha::Authority->get_from_authid($authid); - -Create the Koha::Authority object associated with the provided authid. +=head3 type =cut -sub get_from_authid { - my $class = shift; - my $authid = shift; - my $marcflavour = C4::Context->preference("marcflavour"); - - my $dbh=C4::Context->dbh; - my $sth=$dbh->prepare("select authtypecode, marcxml from auth_header where authid=?"); - $sth->execute($authid); - my ($authtypecode, $marcxml) = $sth->fetchrow; - my $record=eval {MARC::Record->new_from_xml(StripNonXmlChars($marcxml),'UTF-8', - (C4::Context->preference("marcflavour") eq "UNIMARC"?"UNIMARCAUTH":C4::Context->preference("marcflavour")))}; - return if ($@); - $record->encoding('UTF-8'); - - my $self = $class->SUPER::new( { authid => $authid, - marcflavour => $marcflavour, - authtype => $authtypecode, - record => $record }); - - bless $self, $class; - return $self; + +sub _type { + return 'AuthHeader'; } 1;