(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.
This commit is contained in:
parent
36720b589c
commit
fede858a92
42
C4/Search.pm
42
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 ))
|
||||
# );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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" -->&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 -->&limit=available">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 -->&available=1">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>
|
||||
|
||||
|
|
|
|||
|
|
@ -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" -->&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" -->&sort_by=<!-- TMPL_VAR NAME="sort_by" --><!-- /TMPL_IF -->&limit=available">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" -->&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" -->&sort_by=<!-- TMPL_VAR NAME="sort_by" --><!-- /TMPL_IF -->&available=1">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>
|
||||
|
||||
|
|
|
|||
|
|
@ -290,12 +290,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
|
||||
|
|
@ -412,11 +408,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"} }, C4::Context->preference('hidelostitems'));
|
||||
@{ $group->{"RECORDS"} }, $available, 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,@{$results_hashref->{$server}->{"RECORDS"}},, C4::Context->preference('hidelostitems'));
|
||||
} else {
|
||||
@newresults = searchResults( $query_desc,$hits,$results_per_page,$offset,$scan, $available,C4::Context->preference('hidelostitems'), @{$results_hashref->{$server}->{"RECORDS"}});
|
||||
}
|
||||
my $tag_quantity;
|
||||
if (C4::Context->preference('TagsEnabled') and
|
||||
|
|
@ -459,7 +455,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/&limit=available//g if defined $limit_cgi_not_availablity;
|
||||
$limit_cgi_not_availablity =~ s/&available=1//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);
|
||||
|
|
@ -583,6 +579,6 @@ if (defined $barshelves) {
|
|||
$template->param( addbarshelvesloop => $barshelves);
|
||||
}
|
||||
|
||||
my $content_type = ($format eq 'rss' or $format eq 'atom') ? $format : 'html';
|
||||
$content_type = ($format eq 'rss' or $format eq 'atom') ? $format : 'html';
|
||||
|
||||
output_html_with_http_headers $cgi, $cookie, $template->output, $content_type;
|
||||
|
|
|
|||
Loading…
Reference in New Issue