[Koha-patches] [PATCH] Minor tuning of opac-reserve

Joe Atzberger joe.atzberger at liblime.com
Tue Mar 24 23:38:31 CET 2009


The non-trivial changes are:
 ~ Allow failover to default value if maxreserves not defined.  The
default is taken from the English sysprefs (50), not the French (2).
Note that this means users cannot "disable" reserves by setting
maxreserves = 0, but that is BY DESIGN, since there is a separate
syspref for that purpose.
 ~ Removed unused template param "biblionumbers"
 ~ Pulled the reserves sth creation outside the inner loop.  Recreating
it on each pass was a waste.  FIXME still applies, however.
---
 opac/opac-reserve.pl |   44 ++++++++++++++++++++------------------------
 1 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl
index 4395f38..b6c7796 100755
--- a/opac/opac-reserve.pl
+++ b/opac/opac-reserve.pl
@@ -32,7 +32,7 @@ use C4::Branch; # GetBranches
 use C4::Debug;
 # use Data::Dumper;
 
-my $MAXIMUM_NUMBER_OF_RESERVES = C4::Context->preference("maxreserves");
+my $MAXIMUM_NUMBER_OF_RESERVES = C4::Context->preference("maxreserves") || 50;
 
 my $query = new CGI;
 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
@@ -61,7 +61,7 @@ my $itemTypes = GetItemTypes();
 # There are two ways of calling this script, with a single biblio num
 # or multiple biblio nums.
 my $biblionumbers = $query->param('biblionumbers');
-my $reserveMode = $query->param('reserve_mode');
+my $reserveMode   = $query->param('reserve_mode');
 if ($reserveMode && ($reserveMode eq 'single')) {
     my $bib = $query->param('single_bib');
     $biblionumbers = "$bib/";
@@ -75,10 +75,6 @@ if ((! $biblionumbers) && (! $query->param('place_reserve'))) {
     &get_out($query, $cookie, $template->output);
 }
 
-# Pass the numbers to the page so they can be fed back
-# when the hold is confirmed. TODO: Not necessary?
-$template->param( biblionumbers => $biblionumbers );
-
 # Each biblio number is suffixed with '/', e.g. "1/2/3/"
 my @biblionumbers = split /\//, $biblionumbers;
 if (($#biblionumbers < 0) && (! $query->param('place_reserve'))) {
@@ -287,6 +283,10 @@ my $numBibsAvailable = 0;
 my $itemLevelTypes = C4::Context->preference('item-level_itypes');
 $template->param('item-level_itypes' => $itemLevelTypes);
 
+# FIXME: move this to a pm
+my $dbh = C4::Context->dbh;
+my $reserves_sth = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
+
 foreach my $biblioNum (@biblionumbers) {
 
     my $record = GetMarcBiblio($biblioNum);
@@ -301,12 +301,12 @@ foreach my $biblioNum (@biblionumbers) {
         &get_out($query, $cookie, $template->output);
     }
 
-    $biblioLoopIter{biblionumber} = $biblioData->{biblionumber};
-    $biblioLoopIter{title} = $biblioData->{title};
-    $biblioLoopIter{subtitle} = $subtitle;
-    $biblioLoopIter{author} = $biblioData->{author};
-    $biblioLoopIter{rank} = $biblioData->{rank};
-    $biblioLoopIter{reservecount} = $biblioData->{reservecount};
+    $biblioLoopIter{biblionumber}     = $biblioData->{biblionumber};
+    $biblioLoopIter{title}            = $biblioData->{title};
+    $biblioLoopIter{subtitle}         = $subtitle;
+    $biblioLoopIter{author}           = $biblioData->{author};
+    $biblioLoopIter{rank}             = $biblioData->{rank};
+    $biblioLoopIter{reservecount}     = $biblioData->{reservecount};
     $biblioLoopIter{already_reserved} = $biblioData->{already_reserved};
 
     if (!$itemLevelTypes && $biblioData->{itemtype}) {
@@ -315,7 +315,7 @@ foreach my $biblioNum (@biblionumbers) {
     }
 
     foreach my $itemInfo (@{$biblioData->{itemInfos}}) {
-        $debug and warn $itemInfo->{'notforloan'};
+        $debug and warn "itemInfo->{notforloan}: " . $itemInfo->{notforloan};
 
         # Get reserve fee.
         my $fee = GetReserveFee(undef, $borrowernumber, $itemInfo->{'biblionumber'}, 'a',
@@ -341,13 +341,13 @@ foreach my $biblioNum (@biblionumbers) {
         my $itemLoopIter = {};
 
         $itemLoopIter->{itemnumber} = $itemNum;
-        $itemLoopIter->{barcode} = $itemInfo->{barcode};
+        $itemLoopIter->{barcode}    = $itemInfo->{barcode};
         $itemLoopIter->{homeBranchName} = $branches->{$itemInfo->{homebranch}}{branchname};
         $itemLoopIter->{callNumber} = $itemInfo->{itemcallnumber};
         $itemLoopIter->{copynumber} = $itemInfo->{copynumber};
         if ($itemLevelTypes) {
             $itemLoopIter->{description} = $itemInfo->{description};
-            $itemLoopIter->{imageurl} = $itemInfo->{imageurl};
+            $itemLoopIter->{imageurl}    = $itemInfo->{imageurl};
         }
 
         # If the holdingbranch is different than the homebranch, we show the
@@ -378,7 +378,7 @@ foreach my $biblioNum (@biblionumbers) {
             $itemLoopIter->{ExpectedAtLibrary}         = $expectedAt;
         }
 
-        $itemLoopIter->{notforloan} = $itemInfo->{notforloan};
+        $itemLoopIter->{notforloan}     = $itemInfo->{notforloan};
         $itemLoopIter->{itemnotforloan} = $itemInfo->{itemnotforloan};
 
         # Management of the notforloan document
@@ -404,9 +404,8 @@ foreach my $biblioNum (@biblionumbers) {
           GetTransfers($itemNum);
         if ( $transfertwhen && ($transfertwhen ne '') ) {
             $itemLoopIter->{transfertwhen} = format_date($transfertwhen);
-            $itemLoopIter->{transfertfrom} =
-              $branches->{$transfertfrom}{branchname};
-            $itemLoopIter->{transfertto} = $branches->{$transfertto}{branchname};
+            $itemLoopIter->{transfertfrom} = $branches->{$transfertfrom}{branchname};
+            $itemLoopIter->{transfertto}   = $branches->{$transfertto}{branchname};
             $itemLoopIter->{nocancel} = 1;
         }
 
@@ -426,11 +425,8 @@ foreach my $biblioNum (@biblionumbers) {
             $numCopiesAvailable++;
         }
 
-	# FIXME: move this to a pm
-        my $dbh = C4::Context->dbh;
-        my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
-        $sth2->execute($itemLoopIter->{ReservedForBorrowernumber}, $itemNum);
-        while (my $wait_hashref = $sth2->fetchrow_hashref) {
+        $reserves_sth->execute($itemLoopIter->{ReservedForBorrowernumber}, $itemNum);
+        while (my $wait_hashref = $reserves_sth->fetchrow_hashref) {
             $itemLoopIter->{waitingdate} = format_date($wait_hashref->{waitingdate});
         }
 	$itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemTypes->{ $itemInfo->{itype} }{imageurl} );
-- 
1.5.6.5




More information about the Koha-patches mailing list