@@ -, +, @@ --- Koha/Biblio.pm | 27 ++ Koha/Item.pm | 56 +++ Koha/Libraries.pm | 24 +- .../bootstrap/en/modules/opac-reserve.tt | 4 +- t/db_dependent/Koha/Biblios.t | 344 +++++++++++++++++- t/db_dependent/Koha/Items.t | 315 +++++++++++++++- 6 files changed, 750 insertions(+), 20 deletions(-) --- a/Koha/Biblio.pm +++ a/Koha/Biblio.pm @@ -188,6 +188,33 @@ sub can_be_transferred { return 0; } + +=head3 pickup_locations + +@pickup_locations = $biblio->pickup_locations( {patron => $patron } ) + +Returns possible pickup locations for this biblio items, according to patron's home library (if patron is defined and holds are allowed only from hold groups) +and if item can be transfered to each pickup location. + +=cut + +sub pickup_locations { + my ($self, $params) = @_; + + my $patron = $params->{patron}; + + my @pickup_locations; + foreach my $item_of_bib ($self->items) { + push @pickup_locations, $item_of_bib->pickup_locations( {patron => $patron} ); + } + + my %seen; + @pickup_locations = + grep { !$seen{ $_->{branchcode} }++ } @pickup_locations; + + return wantarray ? @pickup_locations : \@pickup_locations; +} + =head3 hidden_in_opac my $bool = $biblio->hidden_in_opac({ [ rules => $rules ] }) --- a/Koha/Item.pm +++ a/Koha/Item.pm @@ -26,6 +26,7 @@ use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use C4::Context; +use C4::Circulation; use Koha::Checkouts; use Koha::IssuingRules; use Koha::Item::Transfer::Limits; @@ -37,6 +38,8 @@ use Koha::StockRotationRotas; use base qw(Koha::Object); +use Data::Dumper; + =head1 NAME Koha::Item - Koha Item object class @@ -277,6 +280,59 @@ sub can_be_transferred { })->count ? 0 : 1; } +=head3 pickup_locations + +@pickup_locations = $item->pickup_locations( {patron => $patron } ) + +Returns possible pickup locations for this item, according to patron's home library (if patron is defined and holds are allowed only from hold groups) +and if item can be transfered to each pickup location. + +=cut + +sub pickup_locations { + my ($self, $params) = @_; + + my $patron = $params->{patron}; + + my $circ_control_branch = + C4::Circulation::_GetCircControlBranch( $self->unblessed(), $patron ); + my $branchitemrule = + C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype ); + + my $branch_control = C4::Context->preference('HomeOrHoldingBranch'); + my $library = $branch_control eq 'holdingbranch' ? $self->holding_branch : $self->home_branch; + + #warn $branch_control.' '.$branchitemrule->{holdallowed}.' '.$library->branchcode.' '.$patron->branchcode; + + my @libs; + if(defined $patron) { + return @libs if $branchitemrule->{holdallowed} == 3 && !$library->validate_hold_sibling( {branchcode => $patron->branchcode} ); + return @libs if $branchitemrule->{holdallowed} == 1 && $library->branchcode ne $patron->branchcode; + } + + if ($branchitemrule->{hold_fulfillment_policy} eq 'holdgroup') { + @libs = $library->get_hold_libraries; + } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'homebranch') { + push @libs, $self->home_branch; + } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'holdingbranch') { + push @libs, $self->holding_branch; + } else { + @libs = Koha::Libraries->search({ + pickup_location => 1 + }, { + order_by => ['branchname'] + })->as_list; + } + + my @pickup_locations; + foreach my $library (@libs) { + if ($library->pickup_location && $self->can_be_transferred({ to => $library })) { + push @pickup_locations, $library->unblessed; + } + } + return wantarray ? @pickup_locations : \@pickup_locations; +} + =head3 article_request_type my $type = $item->article_request_type( $borrower ) --- a/Koha/Libraries.pm +++ a/Koha/Libraries.pm @@ -66,12 +66,17 @@ sub pickup_locations { my $item = $params->{'item'}; my $biblio = $params->{'biblio'}; + my $patron = $params->{'patron'}; + if ($biblio && $item) { Koha::Exceptions::BadParameter->throw( error => "Koha::Libraries->pickup_locations takes either 'biblio' or " ." 'item' as parameter, but not both." ); } + unless (! defined $patron || ref($patron) eq 'Koha::Patron') { + $patron = Koha::Items->find($patron); + } # Select libraries that are configured as pickup locations my $libraries = $self->search({ @@ -81,32 +86,19 @@ sub pickup_locations { }); return $libraries->unblessed unless $item or $biblio; - return $libraries->unblessed - unless C4::Context->preference('UseBranchTransferLimits'); - my $limittype = C4::Context->preference('BranchTransferLimitsType'); - - if ($item) { + if($item) { unless (ref($item) eq 'Koha::Item') { $item = Koha::Items->find($item); return $libraries->unblessed unless $item; } + return $item->pickup_locations( {patron => $patron} ); } else { unless (ref($biblio) eq 'Koha::Biblio') { $biblio = Koha::Biblios->find($biblio); return $libraries->unblessed unless $biblio; } + return $biblio->pickup_locations( {patron => $patron} ); } - - my @pickup_locations; - foreach my $library ($libraries->as_list) { - if ($item && $item->can_be_transferred({ to => $library })) { - push @pickup_locations, $library->unblessed; - } elsif ($biblio && $biblio->can_be_transferred({ to => $library })) { - push @pickup_locations, $library->unblessed; - } - } - - return wantarray ? @pickup_locations : \@pickup_locations; } =head3 search_filtered --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt @@ -233,12 +233,12 @@ [% UNLESS ( bibitemloo.holdable ) %] [% ELSE %] [% SET at_least_one_library_not_available_for_pickup = 0 %]