[Koha-patches] [PATCH] Bug 5786: Correction: Moved holdability check from opac-search.pl to searchResults()
Srdjan
srdjan at catalyst.net.nz
Thu Mar 26 07:36:05 CET 2015
Additional param $borrowernumber for searchResults() when searching in OPAC
---
C4/Search.pm | 24 ++++++++++++++++------
.../opac-tmpl/bootstrap/en/modules/opac-results.tt | 2 +-
opac/opac-detail.pl | 2 +-
opac/opac-search.pl | 21 ++-----------------
4 files changed, 22 insertions(+), 27 deletions(-)
diff --git a/C4/Search.pm b/C4/Search.pm
index f93dd15..2ddc238 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -25,7 +25,7 @@ use Lingua::Stem;
use C4::Search::PazPar2;
use XML::Simple;
use C4::Dates qw(format_date);
-use C4::Members qw(GetHideLostItemsPreference);
+use C4::Members qw(GetHideLostItemsPreference GetMember);
use C4::XSLT;
use C4::Branch;
use C4::Reserves; # GetReserveStatus
@@ -1833,7 +1833,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 ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, $marcresults ) = @_;
+ my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, $marcresults, $borrowernumber ) = @_;
my $dbh = C4::Context->dbh;
my @newresults;
@@ -1863,6 +1863,12 @@ sub searchResults {
# get notforloan authorised value list (see $shelflocations FIXME)
my $notforloan_authorised_value = GetAuthValCode('items.notforloan','');
+ my $userenv = C4::Context->userenv;
+ my $hide_lost_items = GetHideLostItemsPreference($userenv->{'number'});
+
+ # $borrowernumber is passed for opac search
+ my $borrower = $borrowernumber ? GetMember( borrowernumber => $borrowernumber ) : undef;
+
#Build itemtype hash
#find itemtype & itemtype image
my %itemtypes;
@@ -2038,13 +2044,15 @@ sub searchResults {
my $onloan_count = 0;
my $longoverdue_count = 0;
my $other_count = 0;
- my $withdrawn_count = 0;
+ my $withdrawn_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;
+ # If no borrower no point checking issuing_rules
+ my $can_place_item_holds = $borrower ? 0 : 1;
my $item_onhold_count = 0;
my $notforloan_count = 0;
my $items_count = scalar(@fields);
@@ -2091,8 +2099,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
- my $userenv = C4::Context->userenv;
- if ( $item->{onloan} && !(C4::Members::GetHideLostItemsPreference($userenv->{'number'}) && $item->{itemlost}) ) {
+ if ( $item->{onloan} && !($hide_lost_items && $item->{itemlost}) ) {
$onloan_count++;
my $key = $prefix . $item->{onloan} . $item->{barcode};
$onloan_items->{$key}->{due_date} = format_date($item->{onloan});
@@ -2203,6 +2210,11 @@ sub searchResults {
$available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
}
}
+ # ||= because we only need one
+ $can_place_item_holds
+ ||= IsAvailableForItemLevelRequest($item, $borrower) &&
+ OPACItemHoldsAllowed($item, $borrower)
+ if $can_place_holds && $borrower;
} # notforloan, item level and biblioitem level
# if all items are hidden, do not show the record
@@ -2237,7 +2249,7 @@ sub searchResults {
$can_place_holds = 0;
}
}
- $oldbiblio->{norequests} = 1 unless $can_place_holds;
+ $oldbiblio->{norequests} = !($can_place_holds && $can_place_item_holds);
$oldbiblio->{itemsplural} = 1 if $items_count > 1;
$oldbiblio->{items_count} = $items_count;
$oldbiblio->{available_items_loop} = \@available_items_loop;
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt
index fd2cb9f..2622b59 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt
@@ -471,7 +471,7 @@
<div class="actions-menu noprint">
[% IF Koha.Preference( 'RequestOnOpac' ) == 1 %]
[% UNLESS ( SEARCH_RESULT.norequests ) %]
- [% IF ( Koha.Preference( 'opacuserlogin' ) == 1 ) && SEARCH_RESULT.holdable %]
+ [% IF ( Koha.Preference( 'opacuserlogin' ) == 1 ) %]
<span class="actions"><a class="hold" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]">Place hold</a></span><!-- add back when available 0 holds in queue-->
[% END # / IF opacuserlogin && holdable %]
[% END # UNLESS SEARCH_RESULT.norequests %]
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl
index c5f9a6f..0ff60b1 100755
--- a/opac/opac-detail.pl
+++ b/opac/opac-detail.pl
@@ -207,7 +207,7 @@ if ($session->param('busc')) {
for (my $i=0;$i<@servers;$i++) {
my $server = $servers[$i];
$hits = $results_hashref->{$server}->{"hits"};
- @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
+ @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"}, $borrowernumber);
}
return \@newresults;
}#searchAgain
diff --git a/opac/opac-search.pl b/opac/opac-search.pl
index cdf0fbb..0327cd9 100755
--- a/opac/opac-search.pl
+++ b/opac/opac-search.pl
@@ -42,8 +42,6 @@ use C4::Branch; # GetBranches
use C4::SocialData;
use C4::Ratings;
use C4::External::OverDrive;
-use C4::Members;
-use C4::Reserves;
use POSIX qw(ceil floor strftime);
use URI::Escape;
@@ -569,11 +567,8 @@ if ($@ || $error) {
exit;
}
-my $borrower = $borrowernumber ? GetMember( borrowernumber => $borrowernumber ) : undef;
-
# At this point, each server has given us a result set
# now we build that set for template display
-my %allow_onshelf_holds;
my @sup_results_array;
for (my $i=0;$i<@servers;$i++) {
my $server = $servers[$i];
@@ -587,24 +582,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"});
- if ($borrower) {
- $_->{holdable} =
- IsAvailableForItemLevelRequest($_, $borrower) &&
- OPACItemHoldsAllowed($_, $borrower)
- foreach @group_results;
- }
+ $group->{"RECORDS"}, $borrowernumber);
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"});
- if ($borrower) {
- $_->{holdable} =
- IsAvailableForItemLevelRequest($_, $borrower) &&
- OPACItemHoldsAllowed($_, $borrower)
- foreach @newresults;
- }
+ $results_hashref->{$server}->{"RECORDS"}, $borrowernumber);
}
$hits = 0 unless @newresults;
--
1.9.1
More information about the Koha-patches
mailing list