Revert "(MT #2298) Rewrite "only available items""
authorHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Mon, 7 Dec 2009 10:17:32 +0000 (11:17 +0100)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Mon, 7 Dec 2009 10:20:56 +0000 (11:20 +0100)
This reverts commit dfa44a90d4005a034bc2186e0d48ce4d5cb1992e.

C4/Search.pm
catalogue/search.pl
koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc
koha-tmpl/opac-tmpl/prog/en/includes/opac-facets.inc
opac/opac-search.pl

index a709c64..202f6d5 100644 (file)
@@ -1336,9 +1336,7 @@ 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 ( $searchdesc, $hits, $results_per_page, $offset, $scan,
-        $limit_available, $hidelostitems, @marcresults) = @_;
-
+    my ( $searchdesc, $hits, $results_per_page, $offset, $scan, @marcresults, $hidelostitems ) = @_;
     my $dbh = C4::Context->dbh;
     my @newresults;
 
@@ -1543,7 +1541,7 @@ sub searchResults {
             
                        my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber};
 # For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
-            if ( ($item->{onloan} or $item->{reserved} ) and not $limit_available) {
+            if ( $item->{onloan} or $item->{reserved} ) {
                 $onloan_count++;
                                my $key = $prefix . $item->{onloan} . $item->{barcode};
                                $onloan_items->{$key}->{due_date} = format_date($item->{onloan});
@@ -1598,7 +1596,7 @@ sub searchResults {
 
                 # item is withdrawn, lost or damaged
                 if (   $item->{wthdrawn}
-                    || ($item->{itemlost} and not $hidelostitems)
+                    || $item->{itemlost}
                     || $item->{damaged}
                     || $item->{notforloan} 
                     || $item->{reserved}
@@ -1658,17 +1656,13 @@ sub searchResults {
           ( C4::Context->preference('maxItemsinSearchResults') )
           ? C4::Context->preference('maxItemsinSearchResults') - 1
           : 1;
-           
-        if(! $limit_available){
-            for my $key ( sort keys %$onloan_items) {
-                (++$onloanitemscount > $maxitems) and last;
-                push @onloan_items_loop, $onloan_items->{$key};
-            }
-        
-            for my $key ( sort keys %$other_items ) {
-                (++$otheritemscount > $maxitems) and last;
-                push @other_items_loop, $other_items->{$key};
-            }
+        for my $key ( sort keys %$onloan_items ) {
+            (++$onloanitemscount > $maxitems) and last;
+            push @onloan_items_loop, $onloan_items->{$key};
+        }
+        for my $key ( sort keys %$other_items ) {
+            (++$otheritemscount > $maxitems) and last;
+            push @other_items_loop, $other_items->{$key};
         }
         for my $key ( sort keys %$notforloan_items ) {
             (++$notforloanitemscount > $maxitems) and last;
@@ -1678,6 +1672,7 @@ sub searchResults {
             (++$availableitemscount > $maxitems) and last;
             push @available_items_loop, $available_items->{$key}
         }
+
         # XSLT processing of some stuff
         if (C4::Context->preference("XSLTResultsDisplay") && !$scan) {
             $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display(
@@ -1707,17 +1702,10 @@ sub searchResults {
         $oldbiblio->{orderedcount}         = $ordered_count;
         $oldbiblio->{isbn} =~
           s/-//g;    # deleting - in isbn to enable amazon content
-        push( @newresults, $oldbiblio ) if ((not $limit_available and ($items_count))
-                                        or ($limit_available and $available_count));
-         
-            #if((not $hidelostitems and not $limit_available ) 
-            #or ($items_count > $itemlost_count and $available_count  ));
-            #($items_count > $itemlost_count) )
-            #or (or ($available_count and $limit_available))
-            #);
-            #+ $onloan_count ) )  
-            #        && ( $hidelostitems or $limit_available ))
-            #   );
+        push( @newresults, $oldbiblio ) 
+            if(not $hidelostitems
+               or (($items_count > $itemlost_count ) 
+                    && $hidelostitems));
         
     }
     
index 6f4ec63..49942db 100755 (executable)
@@ -378,8 +378,12 @@ if($params->{'multibranchlimit'}) {
 push @limits, join(" or ", map { "branch: $_ "}  @{GetBranchesInCategory($params->{'multibranchlimit'})}) ;
 }
 
-my $available = $params->{'available'};
-
+my $available;
+foreach my $limit(@limits) {
+    if ($limit =~/available/) {
+        $available = 1;
+    }
+}
 $template->param(available => $available);
 
 # append year limits if they exist
@@ -503,7 +507,7 @@ for (my $i=0;$i<@servers;$i++) {
     if ($server =~/biblioserver/) { # this is the local bibliographic server
         $hits = $results_hashref->{$server}->{"hits"};
         my $page = $cgi->param('page') || 0;
-        my @newresults = searchResults( $query_desc,$hits,$results_per_page,$offset,$scan,$available, 0, @{$results_hashref->{$server}->{"RECORDS"}});
+        my @newresults = searchResults( $query_desc,$hits,$results_per_page,$offset,$scan,@{$results_hashref->{$server}->{"RECORDS"}});
         $total = $total + $results_hashref->{$server}->{"hits"};
         ## If there's just one result, redirect to the detail page
         if ($total == 1) {         
index 377ca87..6855411 100644 (file)
@@ -3,7 +3,7 @@
 <div id="search-facets">
 <h4>Refine your search</h4>
 <ul>
-       <li>Availability<ul><li><!-- TMPL_IF NAME="available" -->Showing only <strong>available</strong> items. <a href="/cgi-bin/koha/catalogue/search.pl?<!-- TMPL_VAR NAME="query_cgi" --><!-- TMPL_VAR NAME="limit_cgi_not_availablity" --><!-- TMPL_IF NAME="sort_by" -->&amp;sort_by=<!-- TMPL_VAR NAME="sort_by" --><!-- /TMPL_IF -->">Show all items</a><!-- TMPL_ELSE -->Limit to <a href="/cgi-bin/koha/catalogue/search.pl?<!-- TMPL_VAR NAME="query_cgi" --><!-- TMPL_VAR NAME="limit_cgi" --><!-- TMPL_IF NAME="sort_by" -->&amp;sort_by=<!-- TMPL_VAR NAME="sort_by" --><!-- /TMPL_IF -->&amp;available=1">currently available items.</a><!-- /TMPL_IF --></li></ul>
+       <li>Availability<ul><li><!-- TMPL_IF NAME="available" -->Showing only <strong>available</strong> items. <a href="/cgi-bin/koha/catalogue/search.pl?<!-- TMPL_VAR NAME="query_cgi" --><!-- TMPL_VAR NAME="limit_cgi_not_availablity" --><!-- TMPL_IF NAME="sort_by" -->&sort_by=<!-- TMPL_VAR NAME="sort_by" --><!-- /TMPL_IF -->">Show all items</a><!-- TMPL_ELSE -->Limit to <a href="/cgi-bin/koha/catalogue/search.pl?<!-- TMPL_VAR NAME="query_cgi" --><!-- TMPL_VAR NAME="limit_cgi" --><!-- TMPL_IF NAME="sort_by" -->&sort_by=<!-- TMPL_VAR NAME="sort_by" --><!-- /TMPL_IF -->&amp;limit=available">currently available items.</a><!-- /TMPL_IF --></li></ul>
        <!-- TMPL_IF NAME="related" --> <li>(related searches: <!-- TMPL_LOOP NAME="related" --><!-- TMPL_VAR NAME="related_search" --><!-- /TMPL_LOOP -->)</li><!-- /TMPL_IF -->
        </li>
 
index f2cabbe..aba1e3b 100644 (file)
@@ -3,7 +3,7 @@
 <div id="search-facets">
 <h4>Refine your search</h4>
 <ul>
-       <li>Availability<ul><li><!-- TMPL_IF NAME="available" -->Showing only <strong>available</strong> items. <a href="/cgi-bin/koha/opac-search.pl?<!-- TMPL_VAR NAME="query_cgi" --><!-- TMPL_VAR NAME="limit_cgi_not_availablity" --><!-- TMPL_IF NAME="sort_by" -->&amp;sort_by=<!-- TMPL_VAR NAME="sort_by" --><!-- /TMPL_IF -->">Show all items</a><!-- TMPL_ELSE -->Limit to <a href="/cgi-bin/koha/opac-search.pl?<!-- TMPL_VAR NAME="query_cgi" --><!-- TMPL_VAR NAME="limit_cgi" --><!-- TMPL_IF NAME="sort_by" -->&amp;sort_by=<!-- TMPL_VAR NAME="sort_by" --><!-- /TMPL_IF -->&amp;available=1">currently available items.</a><!-- /TMPL_IF --></li></ul>
+       <li>Availability<ul><li><!-- TMPL_IF NAME="available" -->Showing only <strong>available</strong> items. <a href="/cgi-bin/koha/opac-search.pl?<!-- TMPL_VAR NAME="query_cgi" --><!-- TMPL_VAR NAME="limit_cgi_not_availablity" --><!-- TMPL_IF NAME="sort_by" -->&amp;sort_by=<!-- TMPL_VAR NAME="sort_by" --><!-- /TMPL_IF -->">Show all items</a><!-- TMPL_ELSE -->Limit to <a href="/cgi-bin/koha/opac-search.pl?<!-- TMPL_VAR NAME="query_cgi" --><!-- TMPL_VAR NAME="limit_cgi" --><!-- TMPL_IF NAME="sort_by" -->&amp;sort_by=<!-- TMPL_VAR NAME="sort_by" --><!-- /TMPL_IF -->&amp;limit=available">currently available items.</a><!-- /TMPL_IF --></li></ul>
        <!-- TMPL_IF NAME="related" --> <li>(related searches: <!-- TMPL_LOOP NAME="related" --><!-- TMPL_VAR NAME="related_search" --><!-- /TMPL_LOOP -->)</li><!-- /TMPL_IF -->
        </li>
        
index 2ed8303..e460f16 100755 (executable)
@@ -290,8 +290,12 @@ if($params->{'multibranchlimit'}) {
 push @limits, join(" or ", map { "branch: $_ "}  @{GetBranchesInCategory($params->{'multibranchlimit'})}) ;
 }
 
-my $available = $params->{'available'};
-
+my $available;
+foreach my $limit(@limits) {
+    if ($limit =~/available/) {
+        $available = 1;
+    }
+}
 $template->param(available => $available);
 
 # append year limits if they exist
@@ -408,11 +412,11 @@ 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( $query_desc, $group->{'group_count'},$results_per_page, 0, $scan,
-                                                   @{ $group->{"RECORDS"} }, $available, C4::Context->preference('hidelostitems'));
+                                                   @{ $group->{"RECORDS"} }, C4::Context->preference('hidelostitems'));
                 push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results };
             }
-        } else { 
-            @newresults = searchResults( $query_desc,$hits,$results_per_page,$offset,$scan, $available,C4::Context->preference('hidelostitems'), @{$results_hashref->{$server}->{"RECORDS"}});
+        } else {
+            @newresults = searchResults( $query_desc,$hits,$results_per_page,$offset,$scan,@{$results_hashref->{$server}->{"RECORDS"}},, C4::Context->preference('hidelostitems'));
         }
                my $tag_quantity;
                if (C4::Context->preference('TagsEnabled') and
@@ -455,7 +459,7 @@ for (my $i=0;$i<=@servers;$i++) {
         if ($hits) {
             $template->param(total => $hits);
             my $limit_cgi_not_availablity = $limit_cgi;
-            $limit_cgi_not_availablity =~ s/&available=1//g if defined $limit_cgi_not_availablity;
+            $limit_cgi_not_availablity =~ s/&limit=available//g if defined $limit_cgi_not_availablity;
             $template->param(limit_cgi_not_availablity => $limit_cgi_not_availablity);
             $template->param(limit_cgi => $limit_cgi);
             $template->param(query_cgi => $query_cgi);
@@ -579,6 +583,6 @@ if (defined $barshelves) {
        $template->param( addbarshelvesloop => $barshelves);
 }
 
-$content_type = ($format eq 'rss' or $format eq 'atom') ? $format : 'html';
+my $content_type = ($format eq 'rss' or $format eq 'atom') ? $format : 'html';
 
 output_html_with_http_headers $cgi, $cookie, $template->output, $content_type;