[Koha-patches] [PATCH] [3.0.x] (bug #4055) backport canbook/itembereserved
Nahuel ANGELINETTI
nahuel.angelinetti at biblibre.com
Mon Jan 25 10:17:45 CET 2010
This backport the functions from 3.2/3.4 to the 3.0 API, because we need to factorize the code.
---
C4/Circulation.pm | 2 +-
C4/Reserves.pm | 85 ++++++++++++++++++++
.../opac-tmpl/prog/en/modules/opac-reserve.tmpl | 6 +-
opac/opac-reserve.pl | 37 +++++++--
reserve/request.pl | 11 ++-
5 files changed, 126 insertions(+), 15 deletions(-)
diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 93f1981..cfa1519 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -682,7 +682,7 @@ sub CanBookBeIssued {
if ( $borrower->{'dateexpiry'} eq '0000-00-00') {
$issuingimpossible{EXPIRED} = 1;
} else {
- my @expirydate= split /-/,$borrower->{'dateexpiry'};
+ my @expirydate= split (/-/,$borrower->{'dateexpiry'});
if($expirydate[0]==0 || $expirydate[1]==0|| $expirydate[2]==0 ||
Date_to_Days(Today) > Date_to_Days( @expirydate )) {
$issuingimpossible{EXPIRED} = 1;
diff --git a/C4/Reserves.pm b/C4/Reserves.pm
index c1d7b49..e9e5ce4 100644
--- a/C4/Reserves.pm
+++ b/C4/Reserves.pm
@@ -112,6 +112,8 @@ BEGIN {
&ModReserveMinusPriority
&CheckReserves
+ &CanBookBeReserved
+ &CanItemBeReserved
&CancelReserve
&IsAvailableForItemLevelRequest
@@ -431,6 +433,89 @@ sub GetReservesFromBorrowernumber {
return @$data;
}
#-------------------------------------------------------------------------------------
+=item CanBookBeReserved
+
+$error = &CanBookBeReserved($borrowernumber, $biblionumber)
+
+=cut
+
+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= C4::Context->preference('maxreserves');
+ my $reservescount = 0;
+
+ # we retrieve the user rights
+ my @args;
+ my $branchcode;
+
+
+ if($controlbranch eq "ItemHomeLibrary"){
+ $branchcode = '*';
+ }elsif($controlbranch eq "PatronLibrary"){
+ $branchcode = $borrower->{branchcode};
+ }
+
+ $reservescount = GetReserveCount($borrowernumber);
+
+ if($reservescount < $reservesrights){
+ return 1;
+ }else{
+ return 0;
+ }
+
+}
+
+=item CanItemBeReserved
+
+$error = &CanItemBeReserved($borrowernumber, $itemnumber)
+
+this function return 1 if an item can be issued by this borrower.
+
+=cut
+
+sub CanItemBeReserved{
+ my ($borrowernumber, $itemnumber) = @_;
+
+ my $dbh = C4::Context->dbh;
+
+ my $controlbranch = C4::Context->preference('ReservesControlBranch') eq "ItemHomeLibrary";
+ my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype";
+ my $allowedreserves = C4::Context->preference('maxreserves');
+
+ # we retrieve borrowers and items informations #
+ my $item = C4::Items::GetItem($itemnumber);
+ my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber);
+
+ my $branchcode = "*";
+ my $branchfield = "reserves.branchcode";
+
+ if( $controlbranch eq "ItemHomeLibrary" ){
+ $branchcode = $item->{homebranch};
+ }elsif( $controlbranch eq "PatronLibrary" ){
+ $branchcode = $borrower->{branchcode};
+ }
+
+ # we retrieve user rights on this itemtype and branchcode
+ my $issuingrule = C4::Circulation::GetIssuingRule($borrower->{categorycode}, $item->{$itype}, $branchcode);
+
+ # we retrieve count
+
+ my $reservecount = GetReserveCount($borrowernumber);
+
+ # we check if it's ok or not
+ if(( $reservecount < $allowedreserves ) and $issuingrule->{maxissueqty} ){
+ return 1;
+ }else{
+ return 0;
+ }
+}
+#-------------------------------------------------------------------------------------
=item GetReserveCount
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tmpl
index 51ed128..0eb4ea2 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tmpl
@@ -196,7 +196,11 @@
<!-- /TMPL_IF -->
<!-- TMPL_IF Name="message" -->
- <span class="lost">Unavailable (lost or missing)</span>
+ <span class="lost">Unavailable
+ <!-- TMPL_UNLESS NAME="notholdable" -->
+ (lost or missing)
+ <!-- /TMPL_IF -->
+ </span>
<!-- /TMPL_IF -->
<!-- TMPL_IF Name="notforloan" -->
diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl
index 846a59e..2ec7c31 100755
--- a/opac/opac-reserve.pl
+++ b/opac/opac-reserve.pl
@@ -145,6 +145,7 @@ if ( $query->param('place_reserve') ) {
my $notes=$query->param('notes');
my $checkitem=$query->param('checkitem');
my $found;
+ my $canreserve=0;
#if we have an item selectionned, and the pickup branch is the same as the holdingbranch of the document, we force the value $rank and $found.
if ($checkitem ne ''){
@@ -168,13 +169,24 @@ if ( $query->param('place_reserve') ) {
$i2++;
}
}
- # here we actually do the reserveration. Stage 3.
- if ($query->param('request') eq 'any'){
- # place a request on 1st available
- AddReserve($branch,$borrowernumber,$biblionumber,'a',\@realbi,$rank,$notes,$bibdata->{'title'},$checkitem,$found);
- } else {
- AddReserve($branch,$borrowernumber,$biblionumber,'a',\@realbi,$rank,$notes,$bibdata->{'title'},$checkitem, $found);
+
+ if ($checkitem ne ''){
+ $canreserve = 1 if CanItemBeReserved($borrowernumber,$checkitem);
+ $rank = '0' unless C4::Context->preference('ReservesNeedReturns');
+ my $item = GetItem($checkitem);
+ if ( $item->{'holdingbranch'} eq $branch ){
+ $found = 'W' unless C4::Context->preference('ReservesNeedReturns');
+ }
+ }
+ else {
+ $canreserve = 1 if CanBookBeReserved($borrowernumber,$biblionumber);
+ # Inserts a null into the 'itemnumber' field of 'reserves' table.
+ $checkitem = undef;
}
+
+ # here we actually do the reserveration. Stage 3.
+ AddReserve($branch,$borrowernumber,$biblionumber,'a',\@realbi,$rank,$notes,
+ $bibdata->{'title'},$checkitem, $found) if ($canreserve);
print $query->redirect("/cgi-bin/koha/opac-user.pl#opac-user-holds");
}
else {
@@ -342,7 +354,7 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
$policy_holdallowed = 0;
}
- if (IsAvailableForItemLevelRequest($itemnumber) and $policy_holdallowed) {
+ if (IsAvailableForItemLevelRequest($itemnumber) and $policy_holdallowed and CanItemBeReserved($borrowernumber,$itemnumber)) {
$item->{available} = 1;
$num_available++;
}
@@ -354,10 +366,17 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
while (my $wait_hashref = $sth2->fetchrow_hashref) {
$item->{waitingdate} = format_date($wait_hashref->{waitingdate});
}
- $item->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $item->{itype} }{imageurl} );
+
+ $item->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $item->{itype} }{imageurl} );
+
push @{ $biblioitem->{itemloop} }, $item;
}
-
+
+ if(not CanBookBeReserved($borrowernumber,$biblionumber)){
+ $biblioitem->{available} = undef;
+ $biblioitem->{notholdable} = 1;
+ }
+
push @bibitemloop, $biblioitem;
}
diff --git a/reserve/request.pl b/reserve/request.pl
index 8c55e54..acb813c 100755
--- a/reserve/request.pl
+++ b/reserve/request.pl
@@ -106,7 +106,7 @@ if ($cardnumber) {
my $number_reserves =
GetReserveCount( $borrowerinfo->{'borrowernumber'} );
- if ( $number_reserves > C4::Context->preference('maxreserves') ) {
+ if ( not CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber)) {
$warnings = 1;
$maxreserves = 1;
}
@@ -250,15 +250,18 @@ my @bibitemloop;
foreach my $biblioitemnumber (@biblioitemnumbers) {
my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
-
+
my $num_available;
my $num_override;
-
+ $biblioitem->{itemloop} = [];
+
$biblioitem->{description} =
$itemtypes->{ $biblioitem->{itemtype} }{description};
foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } ){
my $item = $iteminfos_of->{$itemnumber};
+
+
unless (C4::Context->preference('item-level_itypes')) {
$item->{itype} = $biblioitem->{itemtype};
}
@@ -356,7 +359,7 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
$policy_holdallowed = 0;
}
- if (IsAvailableForItemLevelRequest($itemnumber) and not $item->{cantreserve}) {
+ if (IsAvailableForItemLevelRequest($itemnumber) and not $item->{cantreserve} and CanItemBeReserved($borrowerinfo->{borrowernumber}, $itemnumber)) {
if ( not $policy_holdallowed and C4::Context->preference( 'AllowHoldPolicyOverride' ) ) {
$item->{override} = 1;
$num_override++;
--
1.6.3.3
More information about the Koha-patches
mailing list