Bug 17047: add a dedicated page for Mana setup
[koha.git] / Koha / Authority.pm
blobb4cf9465cd815e6201108e362b5b9b173d3f92b8
1 package Koha::Authority;
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 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.
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 use Modern::Perl;
22 use base qw(Koha::Object);
24 use Koha::Authority::ControlledIndicators;
25 use Koha::SearchEngine::Search;
27 =head1 NAME
29 Koha::Authority - Koha Authority Object class
31 =head1 API
33 =head2 Instance Methods
35 =head3 get_usage_count
37 $count = $self->get_usage_count;
39 Returns the number of linked biblio records.
41 =cut
43 sub get_usage_count {
44 my ( $self ) = @_;
45 return Koha::Authorities->get_usage_count({ authid => $self->authid });
48 =head3 linked_biblionumbers
50 my @biblios = $self->linked_biblionumbers({
51 [ max_results => $max ], [ offset => $offset ],
52 });
54 Returns an array of biblionumbers.
56 =cut
58 sub linked_biblionumbers {
59 my ( $self, $params ) = @_;
60 $params->{authid} = $self->authid;
61 return Koha::Authorities->linked_biblionumbers( $params );
64 =head3 controlled_indicators
66 Some authority types control the indicators of some corresponding
67 biblio fields (especially in MARC21).
68 For example, if you have a PERSO_NAME authority (report tag 100), the
69 first indicator of biblio field 600 directly comes from the authority,
70 and the second indicator depends on thesaurus settings in the authority
71 record. Use this method to obtain such controlled values. In this example
72 you should pass 600 in the biblio_tag parameter.
74 my $result = $self->controlled_indicators({
75 record => $auth_marc, biblio_tag => $bib_tag
76 });
77 my $ind1 = $result->{ind1};
78 my $ind2 = $result->{ind2};
79 my $subfield_2 = $result->{sub2}; # Optional subfield 2 when ind==7
81 If an indicator is not controlled, the result hash does not contain a key
82 for its value. (Same for the sub2 key for an optional subfield $2.)
84 Note: The record parameter is a temporary bypass in order to prevent
85 needless conversion of $self->marcxml.
87 =cut
89 sub controlled_indicators {
90 my ( $self, $params ) = @_;
91 my $tag = $params->{biblio_tag} // q{};
92 my $record = $params->{record};
94 my $flavour = C4::Context->preference('marcflavour') eq 'UNIMARC'
95 ? 'UNIMARCAUTH'
96 : 'MARC21';
97 if( !$record ) {
98 $record = MARC::Record->new_from_xml(
99 $self->marcxml, 'UTF-8', $flavour );
102 if( !$self->{_report_tag} ) {
103 my $authtype = Koha::Authority::Types->find( $self->authtypecode );
104 return {} if !$authtype; # very exceptional
105 $self->{_report_tag} = $authtype->auth_tag_to_report;
108 $self->{_ControlledInds} //= Koha::Authority::ControlledIndicators->new;
109 return $self->{_ControlledInds}->get({
110 auth_record => $record,
111 report_tag => $self->{_report_tag},
112 biblio_tag => $tag,
113 flavour => $flavour,
117 =head2 Class Methods
119 =head3 type
121 =cut
123 sub _type {
124 return 'AuthHeader';