[Patches] [PATCH] bug_6488: Changed searchResults() interface

koha-patchbot at kohaaloha.com koha-patchbot at kohaaloha.com
Tue Nov 15 20:10:04 NZDT 2011


From: Srdjan Jankovic <srdjan at catalyst.net.nz>
Date: Thu, 8 Sep 2011 18:21:11 +1200
Subject: [PATCH] bug_6488: Changed searchResults() interface
 Take in account opachiddenitems when searching in opac
 Added trailing \n when parsing OpacHiddenItems to make YAML happy

---
 C4/Items.pm             |    7 +++----
 C4/Search.pm            |   31 ++++++++++++++++++++-----------
 catalogue/search.pl     |    2 +-
 cataloguing/addbooks.pl |    2 +-
 opac/opac-search.pl     |    4 ++--
 5 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/C4/Items.pm b/C4/Items.pm
index bc36dd1..0f098af 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -1531,6 +1531,7 @@ sub GetHiddenItemnumbers {
     my @resultitems;
 
     my $yaml = C4::Context->preference('OpacHiddenItems');
+    $yaml = "$yaml\n"; # YAML is anal on ending \n. Surplus does not hurt
     my $hidingrules;
     eval {
     	$hidingrules = YAML::Load($yaml);
@@ -1538,7 +1539,7 @@ sub GetHiddenItemnumbers {
     if ($@) {
     	warn "Unable to parse OpacHiddenItems syspref : $@";
     	return ();
-    } else {
+    }
     my $dbh = C4::Context->dbh;
 
 	# For each item
@@ -1563,9 +1564,7 @@ sub GetHiddenItemnumbers {
 	    }
 	}
 	return @resultitems;
-    }
-
- }
+}
 
 =head3 get_item_authorised_values
 
diff --git a/C4/Search.pm b/C4/Search.pm
index c3cff65..0ebef81 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -1413,11 +1413,16 @@ Format results in a form suitable for passing to the template
 # IMO this subroutine is pretty messy still -- it's responsible for
 # building the HTML output for the template
 sub searchResults {
-    my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, @marcresults, $hidelostitems ) = @_;
+    my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, $marcresults ) = @_;
     my $dbh = C4::Context->dbh;
     my @newresults;
 
-    $search_context = 'opac' unless $search_context eq 'opac' or $search_context eq 'intranet';
+    $search_context = 'opac' if !$search_context || $search_context ne 'intranet';
+    my ($is_opac, $hidelostitems);
+    if ($search_context eq 'opac') {
+        $hidelostitems = C4::Context->preference('hidelostitems');
+        $is_opac       = 1;
+    }
 
     #Build branchnames hash
     #find branchname
@@ -1484,7 +1489,7 @@ sub searchResults {
 
     # loop through all of the records we've retrieved
     for ( my $i = $offset ; $i <= $times - 1 ; $i++ ) {
-        my $marcrecord = MARC::File::USMARC::decode( $marcresults[$i] );
+        my $marcrecord = MARC::File::USMARC::decode( $marcresults->[$i] );
         $fw = $scan
              ? undef
              : $bibliotag < 10
@@ -1576,11 +1581,12 @@ sub searchResults {
         my $other_count           = 0;
         my $wthdrawn_count        = 0;
         my $itemlost_count        = 0;
+        my $hideatopac_count      = 0;
         my $itembinding_count     = 0;
         my $itemdamaged_count     = 0;
         my $item_in_transit_count = 0;
         my $can_place_holds       = 0;
-	my $item_onhold_count     = 0;
+        my $item_onhold_count     = 0;
         my $items_count           = scalar(@fields);
         my $maxitems =
           ( C4::Context->preference('maxItemsinSearchResults') )
@@ -1597,9 +1603,10 @@ sub searchResults {
             }
 
 	        # Hidden items
-	        my @items = ($item);
-	        my (@hiddenitems) = GetHiddenItemnumbers(@items);
-    	    $item->{'hideatopac'} = 1 if (@hiddenitems); 
+            if ($is_opac) {
+	            my @hiddenitems = GetHiddenItemnumbers($item);
+    	        $item->{'hideatopac'} = @hiddenitems; 
+            }
 
             my $hbranch     = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch'    : 'holdingbranch';
             my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch';
@@ -1683,6 +1690,7 @@ sub searchResults {
                     $wthdrawn_count++        if $item->{wthdrawn};
                     $itemlost_count++        if $item->{itemlost};
                     $itemdamaged_count++     if $item->{damaged};
+                    $hideatopac_count++      if $item->{hideatopac};
                     $item_in_transit_count++ if $transfertwhen ne '';
 		    $item_onhold_count++     if $reservestatus eq 'Waiting';
                     $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan};
@@ -1721,6 +1729,10 @@ sub searchResults {
                 }
             }
         }    # notforloan, item level and biblioitem level
+
+        next if $is_opac       && $hideatopac_count >= $items_count;
+        next if $hidelostitems && $itemlost_count   >= $items_count;
+
         my ( $availableitemscount, $onloanitemscount, $otheritemscount );
         $maxitems =
           ( C4::Context->preference('maxItemsinSearchResults') )
@@ -1807,10 +1819,7 @@ sub searchResults {
             $oldbiblio->{'alternateholdings_count'} = $alternateholdingscount;
         }
 
-        push( @newresults, $oldbiblio )
-            if(not $hidelostitems
-               or (($items_count > $itemlost_count )
-                    && $hidelostitems));
+        push( @newresults, $oldbiblio );
     }
 
     return @newresults;
diff --git a/catalogue/search.pl b/catalogue/search.pl
index b9f9ed3..604b895 100755
--- a/catalogue/search.pl
+++ b/catalogue/search.pl
@@ -547,7 +547,7 @@ for (my $i=0;$i<@servers;$i++) {
         $hits = $results_hashref->{$server}->{"hits"};
         my $page = $cgi->param('page') || 0;
         my @newresults = searchResults('intranet', $query_desc, $hits, $results_per_page, $offset, $scan,
-                                       @{$results_hashref->{$server}->{"RECORDS"}});
+                                       $results_hashref->{$server}->{"RECORDS"});
         $total = $total + $results_hashref->{$server}->{"hits"};
         ## If there's just one result, redirect to the detail page
         if ($total == 1) {         
diff --git a/cataloguing/addbooks.pl b/cataloguing/addbooks.pl
index 5e89ef8..38e8024 100755
--- a/cataloguing/addbooks.pl
+++ b/cataloguing/addbooks.pl
@@ -86,7 +86,7 @@ if ($query) {
     # format output
     # SimpleSearch() give the results per page we want, so 0 offet here
     my $total = @{$marcresults};
-    my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, @{$marcresults} );
+    my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, $marcresults );
     $template->param(
         total          => $total_hits,
         query          => $query,
diff --git a/opac/opac-search.pl b/opac/opac-search.pl
index 8f6b67a..6902633 100755
--- a/opac/opac-search.pl
+++ b/opac/opac-search.pl
@@ -467,12 +467,12 @@ for (my $i=0;$i<@servers;$i++) {
                 # we want as specified by $offset and $results_per_page,
                 # we need to set the offset parameter of searchResults to 0
                 my @group_results = searchResults( 'opac', $query_desc, $group->{'group_count'},$results_per_page, 0, $scan,
-                                                   @{ $group->{"RECORDS"} }, C4::Context->preference('hidelostitems'));
+                                                   $group->{"RECORDS"});
                 push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results };
             }
         } else {
             @newresults = searchResults('opac', $query_desc, $hits, $results_per_page, $offset, $scan,
-                                        @{$results_hashref->{$server}->{"RECORDS"}},, C4::Context->preference('hidelostitems'));
+                                        $results_hashref->{$server}->{"RECORDS"});
         }
 		my $tag_quantity;
 		if (C4::Context->preference('TagsEnabled') and
-- 
1.6.5




More information about the Patches mailing list