Adding trinaries to handle unpopulated itemcallnumber and/or barcode fields
[koha_fer] / labels / label-item-search.pl
index 3da74f5..386c97d 100755 (executable)
@@ -58,6 +58,7 @@ my $dbh = C4::Context->dbh;
 
 my $startfrom = $query->param('startfrom') || 0;
 my ( $template, $loggedinuser, $cookie );
+my $total_hits;
 my (@marclist,@and_or,@excluding,@operator,@value,$orderby,@tags,$results,$total,$error,$marcresults);
 # XXX should this be maxItemsInSearchResults or numSearchResults preference instead of 19?
 my $resultsperpage = $query->param('resultsperpage') || 19;
@@ -74,7 +75,7 @@ if ( $op eq "do_search" ) {
       #catalogsearch( $dbh, \@tags, \@and_or, \@excluding, \@operator, \@value,
       #  $startfrom * $resultsperpage,
       #  $resultsperpage, $orderby );
-               ( $error, $marcresults ) = SimpleSearch( $marclist[0], $startfrom, $resultsperpage );
+               ( $error, $marcresults, $total_hits ) = SimpleSearch( $marclist[0], $startfrom, $resultsperpage );
                if ($marcresults) {
                        $show_results = scalar @$marcresults;
                } else {
@@ -112,10 +113,11 @@ if ( $show_results ) {
                     if ($item_results->{$item}->{'biblionumber'} eq $results[$i]->{'biblionumber'}) {
                         # NOTE: The order of the elements in this array must be preserved or the table dependent on it will be incorrectly rendered.
                         # This is a real hack, but I can't think of a better way right now. -fbcit
+                        # It is conceivable that itemcallnumber and/or barcode fields might be empty so the trinaries cover this possibility.
                         push @{$results[$i]->{'item'}}, { i_itemnumber1         => $item_results->{$item}->{'itemnumber'} };
-                        push @{$results[$i]->{'item'}}, { i_itemcallnumber      => $item_results->{$item}->{'itemcallnumber'} };
+                        push @{$results[$i]->{'item'}}, { i_itemcallnumber      => ($item_results->{$item}->{'itemcallnumber'} ? $item_results->{$item}->{'itemcallnumber'} : 'NA') };
                         push @{$results[$i]->{'item'}}, { i_dateaccessioned     => $item_results->{$item}->{'dateaccessioned'} };
-                        push @{$results[$i]->{'item'}}, { i_barcode             => $item_results->{$item}->{'barcode'} };
+                        push @{$results[$i]->{'item'}}, { i_barcode             => ($item_results->{$item}->{'barcode'} ? $item_results->{$item}->{'barcode'} : 'NA')};
                         push @{$results[$i]->{'item'}}, { i_itemnumber2         => $item_results->{$item}->{'itemnumber'} };
                     }
                 }
@@ -149,6 +151,7 @@ if ( $show_results ) {
     }
 
     my @numbers = ();
+    $total = $total_hits;
     if ( $total > $resultsperpage ) {
         for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
             if ( $i < 16 ) {
@@ -182,7 +185,7 @@ if ( $show_results ) {
         startfromnext  => $startfrom + min( $resultsperpage, scalar @results ),
         startfromprev  => max( $startfrom - $resultsperpage, 0 ),
         searchdata     => \@field_data,
-        total          => $total,
+        total          => $total_hits,
         from           => $startfrom + 1,
         to             => $startfrom + min( $resultsperpage, scalar @results ),
         numbers        => \@numbers,