Bug 24350: (follow-up) Clear Koha::Libraries->pickup_locations() and move logic to Koha::Template::Plugin::Branches->pickup_locations().
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
3e6963e183
commit
6cd1ffab4e
|
|
@ -67,17 +67,12 @@ 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::Patrons->find($patron);
|
||||
}
|
||||
|
||||
# Select libraries that are configured as pickup locations
|
||||
my $libraries = $self->search({
|
||||
|
|
@ -86,20 +81,33 @@ sub pickup_locations {
|
|||
order_by => ['branchname']
|
||||
});
|
||||
|
||||
return $libraries unless $item or $biblio;
|
||||
if($item) {
|
||||
return $libraries->unblessed unless $item or $biblio;
|
||||
return $libraries->unblessed
|
||||
unless C4::Context->preference('UseBranchTransferLimits');
|
||||
my $limittype = C4::Context->preference('BranchTransferLimitsType');
|
||||
|
||||
if ($item) {
|
||||
unless (ref($item) eq 'Koha::Item') {
|
||||
$item = Koha::Items->find($item);
|
||||
return $libraries unless $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 unless $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
|
||||
|
|
|
|||
|
|
@ -87,13 +87,32 @@ sub InIndependentBranchesMode {
|
|||
|
||||
sub pickup_locations {
|
||||
my ( $self, $params ) = @_;
|
||||
|
||||
my $search_params = $params->{search_params} || {};
|
||||
my $selected = $params->{selected};
|
||||
my $libraries = Koha::Libraries->pickup_locations($search_params);
|
||||
my @libraries;
|
||||
|
||||
for my $l (@$libraries) {
|
||||
$l = $l->unblessed;
|
||||
if(defined $search_params->{item} || defined $search_params->{biblio}) {
|
||||
my $item = $search_params->{'item'};
|
||||
my $biblio = $search_params->{'biblio'};
|
||||
my $patron = $search_params->{'patron'};
|
||||
|
||||
unless (! defined $patron || ref($patron) eq 'Koha::Patron') {
|
||||
$patron = Koha::Patrons->find($patron);
|
||||
}
|
||||
|
||||
if($item) {
|
||||
$item = Koha::Items->find($item) unless ref($item) eq 'Koha::Item';
|
||||
@libraries = map { $_->unblessed } $item->pickup_locations( {patron => $patron} ) if defined $item;
|
||||
} elsif($biblio) {
|
||||
$biblio = Koha::Biblios->find($biblio) unless ref($biblio) eq 'Koha::Biblio';
|
||||
@libraries = map { $_->unblessed } $biblio->pickup_locations( {patron => $patron} ) if defined $biblio;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@libraries = Koha::Libraries->pickup_locations() unless @libraries;
|
||||
|
||||
for my $l (@libraries) {
|
||||
if ( defined $selected and $l->{branchcode} eq $selected
|
||||
or not defined $selected
|
||||
and C4::Context->userenv
|
||||
|
|
@ -103,7 +122,7 @@ sub pickup_locations {
|
|||
}
|
||||
}
|
||||
|
||||
return $libraries;
|
||||
return \@libraries;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@
|
|||
[% Branches.GetName(hold.branchcode) | html %] <input type="hidden" name="pickup" value="[% hold.branchcode | html %]" />
|
||||
[% ELSE %]
|
||||
<select name="pickup">
|
||||
[% PROCESS options_for_libraries libraries => Branches.pickup_locations( { search_params => { item => hold.itemnumber, patron => hold.patron }, selected => hold.branchcode }) %]
|
||||
[% PROCESS options_for_libraries libraries => Branches.pickup_locations( { search_params => { item => hold.itemnumber, biblio => hold.biblionumber, patron => hold.patron }, selected => hold.branchcode }) %]
|
||||
</select>
|
||||
[% END %]
|
||||
[% END %]
|
||||
|
|
|
|||
Loading…
Reference in New Issue