[Koha-patches] [PATCH] [SIGNED-OFF] (MT 2985) simplify CanBookBeReserved
Galen Charlton
gmcharlt at gmail.com
Fri Nov 5 14:13:21 CET 2010
From: Nahuel ANGELINETTI <nahuel.angelinetti at biblibre.com>
The function was too complex for so simple stuff, not we check if one of all items of the record can be issued.
[Note by Galen Charlton: not only does this patch simplify the routine,
it also makes it behave correctly.]
Signed-off-by: Galen Charlton <gmcharlt at gmail.com>
---
C4/Reserves.pm | 73 +++----------------------------------------------------
1 files changed, 4 insertions(+), 69 deletions(-)
diff --git a/C4/Reserves.pm b/C4/Reserves.pm
index 9b7014e..fcf9209 100644
--- a/C4/Reserves.pm
+++ b/C4/Reserves.pm
@@ -380,76 +380,11 @@ sub GetReservesFromBorrowernumber {
sub CanBookBeReserved{
my ($borrowernumber, $biblionumber) = @_;
- my $dbh = C4::Context->dbh;
- my $biblio = GetBiblioData($biblionumber);
- my $borrower = C4::Members::GetMember(borrowernumber=>$borrowernumber);
- my $controlbranch = C4::Context->preference('ReservesControlBranch');
- my $itype = C4::Context->preference('item-level_itypes');
- my $reservesrights= 0;
- my $reservescount = 0;
-
- # we retrieve the user rights
- my @args;
- my $rightsquery = "SELECT categorycode, itemtype, branchcode, reservesallowed
- FROM issuingrules
- WHERE categorycode IN (?, '*')";
- push @args,$borrower->{categorycode};
-
- if($controlbranch eq "ItemHomeLibrary"){
- $rightsquery .= " AND branchcode = '*'";
- }elsif($controlbranch eq "PatronLibrary"){
- $rightsquery .= " AND branchcode IN (?,'*')";
- push @args, $borrower->{branchcode};
- }
-
- if(not $itype){
- $rightsquery .= " AND itemtype IN (?,'*')";
- push @args, $biblio->{itemtype};
- }else{
- $rightsquery .= " AND itemtype = '*'";
- }
-
- $rightsquery .= " ORDER BY categorycode DESC, itemtype DESC, branchcode DESC";
- my $sthrights = $dbh->prepare($rightsquery);
- $sthrights->execute(@args);
-
- if(my $row = $sthrights->fetchrow_hashref()){
- $reservesrights = $row->{reservesallowed};
- }
-
- @args = ();
- # we count how many reserves the borrower have
- my $countquery = "SELECT count(*) as count
- FROM reserves
- LEFT JOIN items USING (itemnumber)
- LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber)
- LEFT JOIN borrowers USING (borrowernumber)
- WHERE borrowernumber = ?
- ";
- push @args, $borrowernumber;
-
- if(not $itype){
- $countquery .= "AND itemtype = ?";
- push @args, $biblio->{itemtype};
+ my @items = GetItemsInfo($biblionumber);
+ foreach my $item (@items){
+ return 1 if CanItemBeReserved($borrowernumber, $item->{itemnumber});
}
-
- if($controlbranch eq "PatronLibrary"){
- $countquery .= " AND borrowers.branchcode = ? ";
- push @args, $borrower->{branchcode};
- }
-
- my $sthcount = $dbh->prepare($countquery);
- $sthcount->execute(@args);
-
- if(my $row = $sthcount->fetchrow_hashref()){
- $reservescount = $row->{count};
- }
- if($reservescount < $reservesrights){
- return 1;
- }else{
- return 0;
- }
-
+ return 0;
}
=head2 CanItemBeReserved
--
1.7.0
More information about the Koha-patches
mailing list