From cf148642b39b0eb2289b4d78556049408c867369 Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Fri, 24 Nov 2017 22:21:48 +0100 Subject: [PATCH] Bug 14769: Biblio indicators based on authority's thesaurus code Content-Type: text/plain; charset=utf-8 Original patch from Janusz Kaczmarek on November 24, 2017. Amended by Marcel de Rooy on February 6, 2018. Code moved from AuthoritiesMarc.pm to ControlledIndicators.pm. Special attention has been paid to the proper application of 008/11 while controlling 6XX in MARC 21, specially if 008/11 =~ /[rsz]/ (and if it is 'z' and 040 $f is defined). Test plan: See next patch. Signed-off-by: Marcel de Rooy The construction $thes_mapping{ $code } // $code // '4' will still get some attention on a follow-up. Signed-off-by: Julian Maurice --- Koha/Authority/ControlledIndicators.pm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Koha/Authority/ControlledIndicators.pm b/Koha/Authority/ControlledIndicators.pm index bdadaad..87ae796 100644 --- a/Koha/Authority/ControlledIndicators.pm +++ b/Koha/Authority/ControlledIndicators.pm @@ -83,6 +83,9 @@ sub get { } elsif( $rule->{$ind} eq 'auth2' ) { $result->{$ind} = $report_fld->indicator(2) if $report_fld; } elsif( $rule->{$ind} eq 'thesaurus' ) { + my @info = _thesaurus_info( $record ); + $result->{$ind} = $info[0]; + $result->{sub2} = $info[1]; } else { $result->{$ind} = substr( $rule->{$ind}, 0, 1); } @@ -117,6 +120,32 @@ sub _load_pref { return $res; } +sub _thesaurus_info { + # This sub is triggered by the term 'thesaurus' in the controlling pref. + # The indicator of some MARC21 fields (like 600 ind2) is controlled by + # authority field 008/11 and 040$f. Additionally, it may also control $2. + my ( $record ) = @_; + my $code = $record->field('008') + ? substr($record->field('008')->data, 11, 1) + : q{}; + my %thes_mapping = ( a => 0, b => 1, c => 2, d => 3, k => 5, n => 4, r => 7, s => 7, v => 6, z => 7, '|' => 4 ); + my $ind = $thes_mapping{ $code } // $code // '4'; + + # Determine optional subfield $2 + my $sub2; + if( $ind eq '7' ) { + # Important now to return a defined value + $sub2 = $code eq 'r' + ? 'aat' + : $code eq 's' + ? 'sears' + : $code eq 'z' # pick from 040$f + ? $record->subfield( '040', 'f' ) // q{} + : q{}; + } + return ( $ind, $sub2 ); +} + =head3 clear Clear internal cache. -- 2.1.4