From fede858a92ab893f6fc55cfd321b1d869445a44d Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Fri, 20 Nov 2009 10:05:50 +0100 Subject: [PATCH] (MT #2298) Rewrite "only available items" This change the way to show only available items. Now we don't use anymore zebra that delete records with one non-available item, but we check only for non-available items in perl code. --- C4/Search.pm | 42 ++++++++++++------- catalogue/search.pl | 10 ++--- .../intranet-tmpl/prog/en/includes/facets.inc | 2 +- .../prog/en/includes/opac-facets.inc | 2 +- opac/opac-search.pl | 18 ++++---- 5 files changed, 39 insertions(+), 35 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 7171f4239f..313e9fdee5 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1336,7 +1336,9 @@ 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, @marcresults, $hidelostitems ) = @_; + my ( $searchdesc, $hits, $results_per_page, $offset, $scan, + $limit_available, $hidelostitems, @marcresults) = @_; + my $dbh = C4::Context->dbh; my @newresults; @@ -1541,7 +1543,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} ) { + if ( ($item->{onloan} or $item->{reserved} ) and not $limit_available) { $onloan_count++; my $key = $prefix . $item->{onloan} . $item->{barcode}; $onloan_items->{$key}->{due_date} = format_date($item->{onloan}); @@ -1595,7 +1597,7 @@ sub searchResults { # item is withdrawn, lost or damaged if ( $item->{wthdrawn} - || $item->{itemlost} + || ($item->{itemlost} and not $hidelostitems) || $item->{damaged} || $item->{notforloan} || $item->{reserved} @@ -1655,13 +1657,17 @@ sub searchResults { ( C4::Context->preference('maxItemsinSearchResults') ) ? C4::Context->preference('maxItemsinSearchResults') - 1 : 1; - 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}; + + 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 %$notforloan_items ) { (++$notforloanitemscount > $maxitems) and last; @@ -1671,7 +1677,6 @@ 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( @@ -1701,10 +1706,17 @@ sub searchResults { $oldbiblio->{orderedcount} = $ordered_count; $oldbiblio->{isbn} =~ s/-//g; # deleting - in isbn to enable amazon content - push( @newresults, $oldbiblio ) - if(not $hidelostitems - or (($items_count > $itemlost_count ) - && $hidelostitems)); + 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 )) + # ); } diff --git a/catalogue/search.pl b/catalogue/search.pl index 49942dbc3a..6f4ec63fb9 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -378,12 +378,8 @@ if($params->{'multibranchlimit'}) { push @limits, join(" or ", map { "branch: $_ "} @{GetBranchesInCategory($params->{'multibranchlimit'})}) ; } -my $available; -foreach my $limit(@limits) { - if ($limit =~/available/) { - $available = 1; - } -} +my $available = $params->{'available'}; + $template->param(available => $available); # append year limits if they exist @@ -507,7 +503,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,@{$results_hashref->{$server}->{"RECORDS"}}); + my @newresults = searchResults( $query_desc,$hits,$results_per_page,$offset,$scan,$available, 0, @{$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/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc index 6855411c26..377ca87f57 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc @@ -3,7 +3,7 @@

Refine your search