Bug 20936: (follow-up) add biblio and item relation to old holds and set a limit...
authorAgustin Moyano <agustinmoyano@theke.io>
Tue, 10 Nov 2020 22:23:49 +0000 (19:23 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 11 Nov 2020 14:55:48 +0000 (15:55 +0100)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Schema/Result/OldReserve.pm
opac/opac-holdshistory.pl

index eae6d24..a65cef0 100644 (file)
@@ -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 },
index e55ae1a..67ecae8 100755 (executable)
@@ -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);
 }