From d812bf9d276b47d048b81bbe8fab3f4c913e8330 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Tue, 10 Nov 2020 19:23:49 -0300 Subject: [PATCH] Bug 20936: (follow-up) add biblio and item relation to old holds and set a limit on search holds Signed-off-by: Jonathan Druart --- Koha/Schema/Result/OldReserve.pm | 24 ++++++++++++++++++++++++ opac/opac-holdshistory.pl | 32 ++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/Koha/Schema/Result/OldReserve.pm b/Koha/Schema/Result/OldReserve.pm index eae6d24d3b..a65cef0814 100644 --- a/Koha/Schema/Result/OldReserve.pm +++ b/Koha/Schema/Result/OldReserve.pm @@ -324,6 +324,30 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07049 @ 2020-11-06 11:00:40 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7weIpuc0RpZ/MxFn94E8dg +__PACKAGE__->belongs_to( + "item", + "Koha::Schema::Result::Item", + { itemnumber => "itemnumber" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + +__PACKAGE__->belongs_to( + "biblio", + "Koha::Schema::Result::Biblio", + { biblionumber => "biblionumber" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + __PACKAGE__->add_columns( '+item_level_hold' => { is_boolean => 1 }, '+lowestPriority' => { is_boolean => 1 }, diff --git a/opac/opac-holdshistory.pl b/opac/opac-holdshistory.pl index e55ae1ad04..67ecae864e 100755 --- a/opac/opac-holdshistory.pl +++ b/opac/opac-holdshistory.pl @@ -24,6 +24,8 @@ use C4::Auth; use C4::Output; use Koha::Patrons; +use Koha::Holds; +use Koha::Old::Holds; my $query = CGI->new; my @all_holds; @@ -42,10 +44,26 @@ my ( $template, $patron_id, $cookie ) = get_template_and_user( } ); -my $patron = Koha::Patrons->find( $patron_id ); +my $patron = Koha::Patrons->find($patron_id); -my $holds = $patron->holds; -my $old_holds = $patron->old_holds; +my $sort = $query->param('sort'); +$sort = 'reservedate' unless $sort; + +my $unlimit = $query->param('unlimit'); +my $ops = { + prefetch => ['biblio', 'item'], + order_by => $sort +}; + +$ops->{rows} = 50 unless $unlimit; + +my $holds = Koha::Holds->search({ + borrowernumber => $patron_id +}, $ops); + +my $old_holds = Koha::Old::Holds->search({ + borrowernumber => $patron_id +}, $ops); while (my $hold = $holds->next) { push @all_holds, $hold; @@ -55,19 +73,13 @@ while (my $hold = $old_holds->next) { push @all_holds, $hold; } -my $sort = $query->param('sort'); - -$sort = 'reservedate' unless $sort; - if($sort eq 'reservedate') { @all_holds = sort {$b->$sort cmp $a->$sort} @all_holds; } else { my ($obj, $col) = split /\./, $sort; - @all_holds = sort {$a->$obj->$col cmp $b->$obj->$col} @all_holds; + @all_holds = sort { ( $a->$obj && $a->$obj->$col || '' ) cmp ( $b->$obj && $b->$obj->$col || '' ) } @all_holds; } -my $unlimit = $query->param('unlimit'); - unless($unlimit) { @all_holds = splice(@all_holds, 0, 50); } -- 2.39.5