1 package Koha
::Authority
::ControlledIndicators
;
3 # Copyright 2018 Rijksmuseum
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>.
25 Koha::Authority::ControlledIndicators - Obtain biblio indicators, controlled by authority record
33 Instantiate new object.
38 my ( $class, $params ) = @_;
39 $params = {} if ref($params) ne 'HASH';
40 return bless $params, $class;
45 Obtain biblio indicators for given authority record and biblio field tag
48 auth_record => $record,
49 report_tag => $authtype->auth_tag_to_report,
57 my ( $self, $params ) = @_;
58 my $flavour = $params->{flavour
} // q{};
59 my $tag = $params->{biblio_tag
} // q{};
60 my $record = $params->{auth_record
};
61 my $report_tag = $params->{report_tag
} // q{};
63 $flavour = uc($flavour);
64 $flavour = 'UNIMARC' if $flavour eq 'UNIMARCAUTH';
66 $self->{_parsed
} //= _load_pref
();
68 return $result if !exists $self->{_parsed
}->{$flavour};
69 my $rule = $self->{_parsed
}->{$flavour}->{$tag} //
70 $self->{_parsed
}->{$flavour}->{'*'} //
72 my $report_fld = $record ?
$record->field( $report_tag ) : undef;
74 foreach my $ind ( 'ind1', 'ind2' ) {
75 if( exists $rule->{$ind} ) {
76 if( !$rule->{$ind} ) {
77 $result->{$ind} = $rule->{$ind}; # undef or empty string
78 } elsif( $rule->{$ind} eq 'auth1' ) {
79 $result->{$ind} = $report_fld->indicator(1) if $report_fld;
80 } elsif( $rule->{$ind} eq 'auth2' ) {
81 $result->{$ind} = $report_fld->indicator(2) if $report_fld;
82 } elsif( $rule->{$ind} eq 'thesaurus' ) {
83 my @info = _thesaurus_info
( $record );
84 $result->{$ind} = $info[0];
85 $result->{sub2
} = $info[1];
87 $result->{$ind} = substr( $rule->{$ind}, 0, 1);
96 my $pref = C4
::Context
->preference('AuthorityControlledIndicators') // q{};
97 my @lines = split /\r?\n/, $pref;
100 foreach my $line (@lines) {
101 $line =~ s/^\s*|\s*$//g;
102 next if $line =~ /^#/;
103 # line should be of the form: marcflavour,fld,ind1:val,ind2:val
104 my @temp = split /\s*,\s*/, $line;
106 my $flavour = uc($temp[0]);
107 $flavour = 'UNIMARC' if $flavour eq 'UNIMARCAUTH';
108 next if $temp[1] !~ /(\d{3}|\*)/;
110 if( $temp[2] =~ /ind1\s*:\s*(.*)/ ) {
111 $res->{$flavour}->{$tag}->{ind1
} = $1;
113 if( $temp[3] && $temp[3] =~ /ind2\s*:\s*(.*)/ ) {
114 $res->{$flavour}->{$tag}->{ind2
} = $1;
120 sub _thesaurus_info
{
121 # This sub is triggered by the term 'thesaurus' in the controlling pref.
122 # The indicator of some MARC21 fields (like 600 ind2) is controlled by
123 # authority field 008/11 and 040$f. Additionally, it may also control $2.
125 my $code = $record->field('008')
126 ?
substr($record->field('008')->data, 11, 1)
128 my %thes_mapping = ( a
=> 0, b
=> 1, c
=> 2, d
=> 3, k
=> 5, n
=> 4, r
=> 7, s
=> 7, v
=> 6, z
=> 7, '|' => 4 );
129 my $ind = $thes_mapping{ $code } // '4';
131 # Determine optional subfield $2
134 # Important now to return a defined value
139 : $code eq 'z' # pick from 040$f
140 ?
$record->subfield( '040', 'f' ) // q{}
143 return ( $ind, $sub2 );
148 Marcel de Rooy, Rijksmuseum Amsterdam, The Netherlands
150 Koha Development Team