[Koha-cvs] koha/C4 Reserves2.pm

Mason James szrj1m at yahoo.com
Wed Jun 7 02:36:22 CEST 2006


CVSROOT:	/sources/koha
Module name:	koha
Changes by:	Mason James <sushi>	06/06/07 00:36:22

Modified files:
	C4             : Reserves2.pm 

Log message:
	Merging Katipo changes.
	Updating new fixpriority() sub. now used by reorder_reserve.pl.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Reserves2.pm?cvsroot=koha&r1=1.44&r2=1.45

Patches:
Index: Reserves2.pm
===================================================================
RCS file: /sources/koha/koha/C4/Reserves2.pm,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- Reserves2.pm	6 Jun 2006 23:49:26 -0000	1.44
+++ Reserves2.pm	7 Jun 2006 00:36:22 -0000	1.45
@@ -3,7 +3,7 @@
 
 package C4::Reserves2;
 
-# $Id: Reserves2.pm,v 1.44 2006/06/06 23:49:26 sushi Exp $
+# $Id: Reserves2.pm,v 1.45 2006/06/07 00:36:22 sushi Exp $
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -73,8 +73,7 @@
     &OtherReserves
     GetFirstReserveDateFromItem
     GetNumberReservesFromBorrower
-
-    # fixpriority is used only used internally, and by reorder_reserve.pl
+    &fixpriority 
 );
 
 # make all your functions, whether exported or not;
@@ -570,22 +569,68 @@
     }
 }
 
-# Only used internally
-# Decrements (makes more important) the reserves for all of the
-# entries waiting on the given book, if their priority is > $priority.
+# Only used internally + reorder_reserve.pl
+# Changed how this functions works #
+# Now just gets an array of reserves in the rank order and updates them with
+# the array index (+1 as array starts from 0)
+# and if $rank is supplied will splice item from the array and splice it back in again
+# in new priority rank
 sub fixpriority {
-    my ($priority, $biblio) =  @_;
+    my ($biblio,$borrowernumber,$rank) =  @_;
     my $dbh = C4::Context->dbh;
-    my ($count, $reserves) = FindReserves($biblio);
-    foreach my $rec (@$reserves) {
-	if ($rec->{'priority'} > $priority) {
-	    my $sth = $dbh->prepare("UPDATE reserves SET priority = ?
+
+    warn "BIB: $biblio, BORR: $borrowernumber, RANK: $rank";
+    if($rank eq "del"){
+        warn "Cancel";
+        CancelReserve($biblio,undef,$borrowernumber);
+    }
+    if($rank eq "W" || $rank eq "0"){
+        # make sure priority for waiting items is 0
+        my $sth=$dbh->prepare("UPDATE reserves SET priority = 0
                                WHERE biblionumber     = ?
                                  AND borrowernumber   = ?
-                                 AND reservedate      = ?");
-	    $sth->execute($rec->{'priority'},$rec->{'biblionumber'},$rec->{'borrowernumber'},$rec->{'reservedate'});
-	    $sth->finish;
+                         AND cancellationdate is NULL
+                         AND found ='W'");
+    $sth->execute($biblio,$borrowernumber);
+    }
+    my @priority;
+    my @reservedates;
+    # get whats left
+    my $sth=$dbh->prepare("SELECT borrowernumber, reservedate, constrainttype FROM reserves
+                         WHERE biblionumber   = ?
+                         AND cancellationdate is NULL
+                         AND ((found <> 'F' and found <> 'W') or found is NULL) ORDER BY priority ASC");
+    $sth->execute($biblio);
+    while(my $line = $sth->fetchrow_hashref){
+         push(@reservedates,$line);
+         push(@priority,$line);
+    }
+    # To find the matching index
+    my $i;
+    my $key = -1; # to allow for 0 to be a valid result
+    for ($i = 0; $i < @priority; $i++) {
+           if ($borrowernumber == $priority[$i]->{'borrowernumber'}) {
+               $key = $i; # save the index
+               last;
+            }
 	}
+    warn "key: $key";
+    # if index exists in array then move it to new position
+    if($key>-1 && $rank ne 'del' && $rank > 0){
+          my $new_rank = $rank-1; # $new_rank is what you want the new index to be in the array
+          my $moving_item = splice(@priority, $key, 1);
+          splice(@priority, $new_rank, 0, $moving_item);
+    }
+    # now fix the priority on those that are left....
+    for(my $j=0;$j<@priority;$j++){
+ # warn "update reserves set priority = ".($j+1)." where biblionumber = $biblio and borrowernumber = $priority[$j]->{'borrowernumber'} ";
+ # warn "and reservedate =$priority[$j]->{'reservedate'}";
+         my $sth = $dbh->prepare("UPDATE reserves SET priority = " . ($j+1 ) . "
+                           WHERE biblionumber     = ?
+                           AND borrowernumber   = ?
+                           AND reservedate = ? and found is null");
+        $sth->execute($biblio,$priority[$j]->{'borrowernumber'},$priority[$j]->{'reservedate'});
+        $sth->finish;
     }
 }
 





More information about the Koha-cvs mailing list