Bug 9156: itemcallnumber not pulling more than 2 subfields
authorOwen Leonard <oleonard@myacpl.org>
Tue, 19 Nov 2019 14:56:05 +0000 (14:56 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 10 Jan 2020 16:14:02 +0000 (16:14 +0000)
When the itemcallnumber system preference is defined, the item add form
pulls data from the specified tag and subfield(s) to pre-populate the
call number field. This update makes it possible to build the
prepopulated callnumber from more than just the first two subfields.

To test, apply the patch and update the itemcallnumber system preference
so that it includes more than two subfields. For instance, "092abef"

 - Edit a bibliographic record and populate the specified subfields.
   e.g. subfield a -> "One", b-> "Two", e-> "Three", f-> "Four".
 - Save the record and go to the add/edit items screen.
 - The call number field should contain a string which contains each of
   the subfields you populated, concatenated with spaces: "One Two Three
   Four."
 - Test with other numbers of subfields.
 - Test with an empty itemcallnumber preference.

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
cataloguing/additem.pl

index 2c371de..38fb34b 100755 (executable)
@@ -154,17 +154,23 @@ sub generate_subfield_form {
 
         my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
         if (!$value && $subfieldlib->{kohafield} eq 'items.itemcallnumber' && $pref_itemcallnumber) {
-            my $CNtag       = substr($pref_itemcallnumber, 0, 3);
-            my $CNsubfield  = substr($pref_itemcallnumber, 3, 1);
-            my $CNsubfield2 = substr($pref_itemcallnumber, 4, 1);
+            my $CNtag       = substr( $pref_itemcallnumber, 0, 3 ); # 3-digit tag number
+            my $CNsubfields = substr( $pref_itemcallnumber, 3 ); # Any and all subfields
+            my @subfields = ( $CNsubfields =~ m/./g ); # Split into single-character elements
             my $temp2 = $temp->field($CNtag);
+
             if ($temp2) {
-                $value = join ' ', $temp2->subfield($CNsubfield) || q{}, $temp2->subfield($CNsubfield2) || q{};
+                my @selectedsubfields;
+                foreach my $subfieldcode( @subfields ){
+                    push @selectedsubfields, $temp2->subfield( $subfieldcode );
+                }
+                $value = join( ' ', @selectedsubfields );
+
                 #remove any trailing space incase one subfield is used
                 $value =~ s/^\s+|\s+$//g;
             }
         }
-        
+
         if ($frameworkcode eq 'FA' && $subfieldlib->{kohafield} eq 'items.barcode' && !$value){
            my $input = new CGI;
            $value = $input->param('barcode');