1 package Koha
::Authorities
;
3 # Copyright 2015 Koha Development Team
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>.
28 use base
qw(Koha::Objects);
32 Koha::Authorities - Koha Authority object set class
38 =head3 get_usage_count
40 $count = Koha::Authorities->get_usage_count({ authid => $i });
42 Returns the number of linked biblio records.
44 Note: Code originates from C4::AuthoritiesMarc::CountUsage.
46 This is a class method, since the authid may refer to a deleted record.
51 my ( $class, $params ) = @_;
52 my $authid = $params->{authid
} || return;
54 my $searcher = Koha
::SearchEngine
::Search
->new({ index => $Koha::SearchEngine
::BIBLIOS_INDEX
});
55 my ( $err, $result, $count ) = $searcher->simple_search_compat( 'an:' . $authid, 0, 0 );
57 warn "Error: $err from search for " . $authid;
63 =head3 linked_biblionumbers
65 my @biblios = Koha::Authorities->linked_biblionumbers({
66 authid => $id, [ max_results => $max ], [ offset => $offset ],
69 Returns array of biblionumbers, as extracted from the result records of
72 This is a class method, since the authid may refer to a deleted record.
76 sub linked_biblionumbers
{
77 my ( $self, $params ) = @_;
78 my $authid = $params->{authid
} || return;
80 my $searcher = Koha
::SearchEngine
::Search
->new({ index => $Koha::SearchEngine
::BIBLIOS_INDEX
});
81 # if max_results is undefined, we will get all results
82 my ( $err, $result, $count ) = $searcher->simple_search_compat( 'an:' . $authid, $params->{offset
} // 0, $params->{max_results
} );
85 warn "Error: $err from search for " . $authid;
90 foreach my $res ( @
$result ) {
91 my $bibno = $searcher->extract_biblionumber( $res );
92 push @biblionumbers, $bibno if $bibno;
94 return @biblionumbers;
110 return 'Koha::Authority';