Bug 19528: Fix a few typos like corrosponding
[koha.git] / Koha / Authorities.pm
1 package Koha::Authorities;
2
3 # Copyright 2015 Koha Development Team
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 3 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 use Modern::Perl;
21
22 use Carp;
23
24 use Koha::Database;
25
26 use Koha::Authority;
27
28 use base qw(Koha::Objects);
29
30 =head1 NAME
31
32 Koha::Authorities - Koha Authority object set class
33
34 =head1 API
35
36 =head2 Class Methods
37
38 =head3 get_usage_count
39
40     $count = Koha::Authorities->get_usage_count({ authid => $i });
41
42     Returns the number of linked biblio records.
43
44     Note: Code originates from C4::AuthoritiesMarc::CountUsage.
45
46     This is a class method, since the authid may refer to a deleted record.
47
48 =cut
49
50 sub get_usage_count {
51     my ( $class, $params ) = @_;
52     my $authid = $params->{authid} || return;
53
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 );
56     if( $err ) {
57         warn "Error: $err from search for " . $authid;
58         return;
59     }
60     return $count;
61 }
62
63 =head3 linked_biblionumbers
64
65     my @biblios = Koha::Authorities->linked_biblionumbers({
66         authid => $id, [ max_results => $max ], [ offset => $offset ],
67     });
68
69     Returns array of biblionumbers, as extracted from the result records of
70     the search engine.
71
72     This is a class method, since the authid may refer to a deleted record.
73
74 =cut
75
76 sub linked_biblionumbers {
77     my ( $self, $params ) = @_;
78     my $authid = $params->{authid} || return;
79
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} );
83
84     if( $err ) {
85         warn "Error: $err from search for " . $authid;
86         return;
87     }
88
89     my @biblionumbers;
90     foreach my $res ( @$result ) {
91         my $bibno = $searcher->extract_biblionumber( $res );
92         push @biblionumbers, $bibno if $bibno;
93     }
94     return @biblionumbers;
95 }
96
97 =head3 type
98
99 =cut
100
101 sub _type {
102     return 'AuthHeader';
103 }
104
105 =head3 object_class
106
107 =cut
108
109 sub object_class {
110     return 'Koha::Authority';
111 }
112
113 1;