Bug 14769: Biblio indicators based on authority's thesaurus code
authorJanusz Kaczmarek <januszop@gmail.com>
Fri, 24 Nov 2017 21:21:48 +0000 (22:21 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 12 Apr 2018 13:50:35 +0000 (10:50 -0300)
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 <m.de.rooy@rijksmuseum.nl>
The construction $thes_mapping{ $code } // $code // '4' will still get
some attention on a follow-up.
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Authority/ControlledIndicators.pm

index bdadaad..87ae796 100644 (file)
@@ -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.