From f076c67746c6f15115902f55ececfb0092b6ea3c Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Mon, 25 Jan 2010 10:16:41 +0100 Subject: [PATCH] [3.0.x] (bug #4055) backport canbook/itembereserved 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 +++++++++++++++++++ .../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 93f19813d4..cfa1519bb2 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 c1d7b49eee..a867a86910 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') || "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 51ed128231..0eb4ea2426 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 @@ - Unavailable (lost or missing) + Unavailable + + (lost or missing) + + diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 846a59e1fe..2ec7c317a9 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 8c55e5470a..acb813c7f1 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++; -- 2.39.5