@@ -, +, @@ --- C4/HoldsQueue.pm | 62 ++++++++++++++++++----------- Koha/Schema/Result/TmpHoldsqueue.pm | 50 ++++++++++++++++++++++- circ/view_holdsqueue.pl | 3 -- 3 files changed, 88 insertions(+), 27 deletions(-) --- a/C4/HoldsQueue.pm +++ a/C4/HoldsQueue.pm @@ -135,35 +135,51 @@ sub GetHoldsQueueItems { my ($branchlimit) = @_; my $dbh = C4::Context->dbh; - my @bind_params = (); - my $query = q/SELECT tmp_holdsqueue.*, biblio.author, items.ccode, items.itype, biblioitems.itemtype, items.location, - items.enumchron, items.cn_sort, biblioitems.publishercode, - biblio.copyrightdate, biblio.subtitle, biblio.medium, - biblio.part_number, biblio.part_name, - biblioitems.publicationyear, biblioitems.pages, biblioitems.size, - biblioitems.isbn, biblioitems.editionstatement, items.copynumber - FROM tmp_holdsqueue - JOIN biblio USING (biblionumber) - LEFT JOIN biblioitems USING (biblionumber) - LEFT JOIN items USING ( itemnumber) - /; + my $search_params; if ($branchlimit) { - $query .=" WHERE tmp_holdsqueue.holdingbranch = ?"; - push @bind_params, $branchlimit; + $search_params->{'me.holdingbranch'} = $branchlimit; } - $query .= " ORDER BY ccode, location, cn_sort, author, title, pickbranch, reservedate"; - my $sth = $dbh->prepare($query); - $sth->execute(@bind_params); + + my $schema = Koha::Database->new->schema; + my $queue_rs = $schema->resultset('TmpHoldsqueue')->search( + $search_params, + { + join => [ qw{ biblio biblioitem borrower item } ], + order_by => [ qw{ ccode location cn_sort author title pickbranch reservedate } ] + } + ); + my $items = []; - while ( my $row = $sth->fetchrow_hashref ){ - # return the bib-level or item-level itype per syspref - if (!C4::Context->preference('item-level_itypes')) { - $row->{itype} = $row->{itemtype}; + while ( my $r = $queue_rs->next ) { + my $result = { $r->get_columns }; + $result->{author} = $r->biblio->author; + $result->{copyrightdate} = $r->biblio->copyrightdate; + $result->{medium} = $r->biblio->medium; + $result->{part_name} = $r->biblio->part_name; + $result->{part_number} = $r->biblio->part_number; + $result->{subittle} = $r->biblio->subtitle; + $result->{editionstatement} = $r->biblioitem->editionstatement; + $result->{isbn} = $r->biblioitem->isbn; + $result->{pages} = $r->biblioitem->pages; + $result->{publicationyear} = $r->biblioitem->publicationyear; + $result->{publishercode} = $r->biblioitem->publishercode; + $result->{size} = $r->biblioitem->size; + $result->{ccode} = $r->item->ccode; + $result->{cn_sort} = $r->item->cn_sort; + $result->{copynumber} = $r->item->copynumber; + $result->{enumchron} = $r->item->enumchron; + $result->{itype} = $r->item->itype; + $result->{location} = $r->item->location; + + if ( !C4::Context->preference('item-level_itypes') ) { + $result->{itype} = $result->{itemtype}; } - delete $row->{itemtype}; - push @$items, $row; + $result->{patron} = Koha::Patron->new_from_dbic( $r->borrower ); + + push( @$items, $result ); } + return $items; } --- a/Koha/Schema/Result/TmpHoldsqueue.pm +++ a/Koha/Schema/Result/TmpHoldsqueue.pm @@ -167,6 +167,54 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-05-14 18:14:09 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tzgAgf+OVO+IncaTr7SZuQ +__PACKAGE__->belongs_to( + "biblio", + "Koha::Schema::Result::Biblio", + { biblionumber => "biblionumber" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + +__PACKAGE__->belongs_to( + "biblioitem", + "Koha::Schema::Result::Biblioitem", + { biblionumber => "biblionumber" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + +__PACKAGE__->belongs_to( + "borrower", + "Koha::Schema::Result::Borrower", + { borrowernumber => "borrowernumber" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + +__PACKAGE__->belongs_to( + "item", + "Koha::Schema::Result::Item", + { itemnumber => "itemnumber" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + + -# You can replace this text with custom content, and it will be preserved on regeneration 1; --- a/circ/view_holdsqueue.pl +++ a/circ/view_holdsqueue.pl @@ -51,9 +51,6 @@ my $itemtypeslimit = $params->{'itemtypeslimit'}; if ( $run_report ) { # XXX GetHoldsQueueItems() does not support $itemtypeslimit! my $items = GetHoldsQueueItems($branchlimit, $itemtypeslimit); - for my $item ( @$items ) { - $item->{patron} = Koha::Patrons->find( $item->{borrowernumber} ); - } $template->param( branchlimit => $branchlimit, total => scalar @$items, --