[Koha-patches] [PATCH] bug 2522 [2/3]: C4::Reserves support for request targeting

Galen Charlton galen.charlton at liblime.com
Fri Aug 15 03:59:50 CEST 2008


_Findgroupreserve, which identifies which hold request an
item should fill, is modified to check to see if
that item is targeted to fill a specific hold request.

It first checks for a targeted match with an item-level hold request,
then a targeted match with a title-level request.  If no
such targeted match exists, it then checks for the top entries
in the holds queue.

The hold targeting map (i.e., the hold_fill_targets table) is
populated by the build_holds_queue.pl batch job.  If that
job is not used, the behavior of _Findgroupreserve
is not changed.

This patch also

* adjusts ModReserveMinusPriority so that it calls
  _FixPriority().
* adjusts circ/returns.pl so that it
  correctly detects transfers.
---
 C4/Reserves.pm  |   74 ++++++++++++++++++++++++++++++++++++++++++++++---------
 circ/returns.pl |    2 +-
 2 files changed, 63 insertions(+), 13 deletions(-)

diff --git a/C4/Reserves.pm b/C4/Reserves.pm
index 8de6d37..ec81bf4 100644
--- a/C4/Reserves.pm
+++ b/C4/Reserves.pm
@@ -1058,16 +1058,7 @@ sub ModReserveMinusPriority {
     $sth_upd->execute( $itemnumber, $borrowernumber, $biblionumber );
     $sth_upd->finish;
     # second step update all others reservs
-    $query = "
-            UPDATE reserves
-            SET    priority = priority-1
-            WHERE  biblionumber = ?
-            AND priority > 0
-    ";
-    $sth_upd = $dbh->prepare($query);
-    $sth_upd->execute( $biblionumber );
-    $sth_upd->finish;
-    $sth_upd->finish;
+    _FixPriority($biblionumber, $borrowernumber, '0');
 }
 
 =item GetReserveInfo
@@ -1294,6 +1285,65 @@ C<biblioitemnumber>.
 sub _Findgroupreserve {
     my ( $bibitem, $biblio, $itemnumber ) = @_;
     my $dbh   = C4::Context->dbh;
+
+    # check for exact targetted match
+    my $item_level_target_query = qq/
+        SELECT reserves.biblionumber AS biblionumber,
+               reserves.borrowernumber AS borrowernumber,
+               reserves.reservedate AS reservedate,
+               reserves.branchcode AS branchcode,
+               reserves.cancellationdate AS cancellationdate,
+               reserves.found AS found,
+               reserves.reservenotes AS reservenotes,
+               reserves.priority AS priority,
+               reserves.timestamp AS timestamp,
+               biblioitems.biblioitemnumber AS biblioitemnumber,
+               reserves.itemnumber AS itemnumber
+        FROM reserves
+        JOIN biblioitems USING (biblionumber)
+        JOIN hold_fill_targets USING (biblionumber, borrowernumber, itemnumber)
+        WHERE found IS NULL
+        AND priority > 0
+        AND item_level_request = 1
+        AND itemnumber = ?
+    /;
+    my $sth = $dbh->prepare($item_level_target_query);
+    $sth->execute($itemnumber);
+    my @results;
+    if ( my $data = $sth->fetchrow_hashref ) {
+        push( @results, $data );
+    }
+    return @results if @results;
+    
+    # check for title-level targetted match
+    my $title_level_target_query = qq/
+        SELECT reserves.biblionumber AS biblionumber,
+               reserves.borrowernumber AS borrowernumber,
+               reserves.reservedate AS reservedate,
+               reserves.branchcode AS branchcode,
+               reserves.cancellationdate AS cancellationdate,
+               reserves.found AS found,
+               reserves.reservenotes AS reservenotes,
+               reserves.priority AS priority,
+               reserves.timestamp AS timestamp,
+               biblioitems.biblioitemnumber AS biblioitemnumber,
+               reserves.itemnumber AS itemnumber
+        FROM reserves
+        JOIN biblioitems USING (biblionumber)
+        JOIN hold_fill_targets USING (biblionumber, borrowernumber)
+        WHERE found IS NULL
+        AND priority > 0
+        AND item_level_request = 0
+        AND hold_fill_targets.itemnumber = ?
+    /;
+    $sth = $dbh->prepare($title_level_target_query);
+    $sth->execute($itemnumber);
+    @results = ();
+    if ( my $data = $sth->fetchrow_hashref ) {
+        push( @results, $data );
+    }
+    return @results if @results;
+
     my $query = qq/
         SELECT reserves.biblionumber AS biblionumber,
                reserves.borrowernumber AS borrowernumber,
@@ -1315,9 +1365,9 @@ sub _Findgroupreserve {
           OR  reserves.constrainttype='a' )
           AND (reserves.itemnumber IS NULL OR reserves.itemnumber = ?)
     /;
-    my $sth = $dbh->prepare($query);
+    $sth = $dbh->prepare($query);
     $sth->execute( $biblio, $bibitem, $itemnumber );
-    my @results;
+    @results = ();
     while ( my $data = $sth->fetchrow_hashref ) {
         push( @results, $data );
     }
diff --git a/circ/returns.pl b/circ/returns.pl
index 726e886..9c08c31 100755
--- a/circ/returns.pl
+++ b/circ/returns.pl
@@ -129,7 +129,7 @@ if ( $query->param('resbarcode') ) {
     
 #     addin in ModReserveAffect the possibility to check if the document is expected in this library or not,
 # if not we send a value in reserve waiting for not implementting waiting status
-    if ($diffBranchReturned) {
+    if (C4::Context->userenv->{'branch'} ne $diffBranchReturned) {
         $diffBranchSend = $diffBranchReturned;
     }
     else {
-- 
1.5.5.GIT




More information about the Koha-patches mailing list