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
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>.
22 use base qw(Koha::Object);
24 use Koha::Authority::ControlledIndicators;
25 use Koha::SearchEngine::Search;
27 use C4::Heading qw( new_from_field );
31 Koha::Authority - Koha Authority Object class
37 =head3 get_usage_count
39 $count = $self->get_usage_count;
41 Returns the number of linked biblio records.
47 return Koha::Authorities->get_usage_count({ authid => $self->authid });
50 =head3 linked_biblionumbers
52 my @biblios = $self->linked_biblionumbers({
53 [ max_results => $max ], [ offset => $offset ],
56 Returns an array of biblionumbers.
60 sub linked_biblionumbers {
61 my ( $self, $params ) = @_;
62 $params->{authid} = $self->authid;
63 return Koha::Authorities->linked_biblionumbers( $params );
68 Routine to return the C4::Heading object for this authority
74 my ( $self, $params ) = @_;
75 my $record = $params->{record};
77 if ( !$self->{_report_tag} ) {
78 my $authtype = Koha::Authority::Types->find( $self->authtypecode );
79 return {} if !$authtype; # very exceptional
80 $self->{_report_tag} = $authtype->auth_tag_to_report;
84 $record = $self->record;
86 my $field = $record->field( $self->{_report_tag} );
87 my $heading = C4::Heading->new_from_field( $field, undef, 1 ); #new auth heading
92 =head3 controlled_indicators
94 Some authority types control the indicators of some corresponding
95 biblio fields (especially in MARC21).
96 For example, if you have a PERSO_NAME authority (report tag 100), the
97 first indicator of biblio field 600 directly comes from the authority,
98 and the second indicator depends on thesaurus settings in the authority
99 record. Use this method to obtain such controlled values. In this example
100 you should pass 600 in the biblio_tag parameter.
102 my $result = $self->controlled_indicators({
103 record => $auth_marc, biblio_tag => $bib_tag
105 my $ind1 = $result->{ind1};
106 my $ind2 = $result->{ind2};
107 my $subfield_2 = $result->{sub2}; # Optional subfield 2 when ind==7
109 If an indicator is not controlled, the result hash does not contain a key
110 for its value. (Same for the sub2 key for an optional subfield $2.)
112 Note: The record parameter is a temporary bypass in order to prevent
113 needless conversion of $self->marcxml.
117 sub controlled_indicators {
118 my ( $self, $params ) = @_;
119 my $tag = $params->{biblio_tag} // q{};
120 my $record = $params->{record};
122 my $flavour = C4::Context->preference('marcflavour') eq 'UNIMARC'
126 $record = $self->record;
129 if( !$self->{_report_tag} ) {
130 my $authtype = Koha::Authority::Types->find( $self->authtypecode );
131 return {} if !$authtype; # very exceptional
132 $self->{_report_tag} = $authtype->auth_tag_to_report;
135 $self->{_ControlledInds} //= Koha::Authority::ControlledIndicators->new;
136 return $self->{_ControlledInds}->get({
137 auth_record => $record,
138 report_tag => $self->{_report_tag},
144 =head3 get_identifiers_and_information
146 my $information = $author->get_identifiers_and_information;
148 Return a list of information of the authors (syspref OPACAuthorIdentifiersAndInformation)
152 sub get_identifiers_and_information {
155 my $record = $self->record;
157 # FIXME UNIMARC not supported yet.
158 return if C4::Context->preference('marcflavour') eq 'UNIMARC';
161 for my $info ( split ',', C4::Context->preference('OPACAuthorIdentifiersAndInformation') ) {
162 if ( $info eq 'identifiers' ) {
164 # identifiers (024$2$a)
165 for my $field ( $record->field('024') ) {
166 my $sf_2 = $field->subfield('2');
167 my $sf_a = $field->subfield('a');
168 next unless $sf_2 && $sf_a;
169 push @{ $information->{identifiers} }, { source => $sf_2, number => $sf_a, };
171 } elsif ( $info eq 'activity' ) {
173 # activity: Activity (372$a$s$t)
174 for my $field ( $record->field('372') ) {
175 my $sf_a = $field->subfield('a');
176 my $sf_s = $field->subfield('s');
177 my $sf_t = $field->subfield('t');
178 push @{ $information->{activity} },
179 { field_of_activity => $sf_a, start_period => $sf_s, end_period => $sf_t, };
181 } elsif ( $info eq 'address' ) {
183 # address: Address (371$a$b$d$e)
184 for my $field ( $record->field('371') ) {
185 my $sf_a = $field->subfield('a');
186 my $sf_b = $field->subfield('b');
187 my $sf_d = $field->subfield('d');
188 my $sf_e = $field->subfield('e');
189 push @{ $information->{address} },
190 { address => $sf_a, city => $sf_b, country => $sf_d, postal_code => $sf_e, };
192 } elsif ( $info eq 'associated_group' ) {
194 # associated_group: Associated group (373$a$s$t$u$v$0)
195 for my $field ( $record->field('373') ) {
196 my $sf_a = $field->subfield('a');
197 my $sf_s = $field->subfield('s');
198 my $sf_t = $field->subfield('t');
199 my $sf_u = $field->subfield('u');
200 my $sf_v = $field->subfield('v');
201 my $sf_0 = $field->subfield('0');
202 push @{ $information->{associated_group} },
204 associated_group => $sf_a, start_period => $sf_s, end_period => $sf_t, uri => $sf_u,
205 source_of_information => $sf_v, authority_record_number => $sf_0,
208 } elsif ( $info eq 'email_address' ) {
210 # email_address: Electronic mail address (371$m)
211 for my $field ( $record->field('371') ) {
212 my $sf_m = $field->subfield('m');
213 push @{ $information->{email_address} }, { email_address => $sf_m, };
215 } elsif ( $info eq 'occupation' ) {
217 # occupation: Occupation (374$a$s$t$u$v$0)
218 for my $field ( $record->field('374') ) {
219 my $sf_a = $field->subfield('a');
220 my $sf_s = $field->subfield('s');
221 my $sf_t = $field->subfield('t');
222 my $sf_u = $field->subfield('u');
223 my $sf_v = $field->subfield('v');
224 my $sf_0 = $field->subfield('0');
225 push @{ $information->{occupation} },
227 occupation => $sf_a, start_period => $sf_s, end_period => $sf_t, uri => $sf_u,
228 source_of_information => $sf_v, authority_record_number => $sf_0,
231 } elsif ( $info eq 'place_of_birth' ) {
233 # place_of_birth: Place of birth (370$a)
234 for my $field ( $record->field('370') ) {
235 my $sf_a = $field->subfield('a');
236 push @{ $information->{place_of_birth} }, { place_of_birth => $sf_a, };
238 } elsif ( $info eq 'place_of_death' ) {
240 # place_of_death: Place of death (370$b)
241 for my $field ( $record->field('370') ) {
242 my $sf_b = $field->subfield('b');
243 push @{ $information->{place_of_death} }, { place_of_death => $sf_b, };
245 } elsif ( $info eq 'uri' ) {
248 for my $field ( $record->field('371') ) {
249 my $sf_u = $field->subfield('u');
250 push @{ $information->{uri} }, { uri => $sf_u, };
261 my $record = $authority->record()
263 Return the MARC::Record for this authority
270 my $flavour = $self->record_schema;
271 return MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $flavour );
276 my $schema = $biblio->record_schema();
278 Returns the record schema (MARC21 or UNIMARCAUTH).
285 return C4::Context->preference('marcflavour') eq 'UNIMARC'
290 =head3 to_api_mapping
292 This method returns the mapping for representing a Koha::Authority object
299 authid => 'authority_id',
301 authtypecode => 'framework_id',
302 datecreated => 'created_date',
306 modification_time => 'modified_date',
311 =head2 Internal methods