@@ -, +, @@ --- C4/HoldsQueue.pm | 80 ++++++++----------- Koha/Hold/HoldsQueueItem.pm | 39 +++++++++ Koha/Schema/Result/TmpHoldsqueue.pm | 48 +++++++++++ circ/view_holdsqueue.pl | 34 ++++---- .../prog/en/modules/circ/view_holdsqueue.tt | 36 ++++----- t/db_dependent/HoldsQueue.t | 22 ++--- 6 files changed, 168 insertions(+), 91 deletions(-) --- a/C4/HoldsQueue.pm +++ a/C4/HoldsQueue.pm @@ -25,7 +25,7 @@ use warnings; use C4::Context; use C4::Circulation qw( GetBranchItemRule ); use Koha::DateUtils qw( dt_from_string ); -use Koha::HoldsQueueItems; +use Koha::Hold::HoldsQueueItems; use Koha::Items; use Koha::Libraries; use Koha::Patrons; @@ -126,52 +126,42 @@ sub GetHoldsQueueItems { my $params = shift; 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, - item_groups.item_group_id, item_groups.description AS item_group_description - FROM tmp_holdsqueue - JOIN biblio USING (biblionumber) - LEFT JOIN biblioitems USING (biblionumber) - LEFT JOIN items USING ( itemnumber) - LEFT JOIN item_group_items ON ( items.itemnumber = item_group_items.item_id ) - LEFT JOIN item_groups ON ( item_group_items.item_group_id = item_groups.item_group_id ) - WHERE 1=1 - /; - if ($params->{branchlimit}) { - $query .="AND tmp_holdsqueue.holdingbranch = ? "; - push @bind_params, $params->{branchlimit}; - } - if( $params->{itemtypeslimit} ) { - $query .=" AND items.itype = ? "; - push @bind_params, $params->{itemtypeslimit}; - } - if( $params->{ccodeslimit} ) { - $query .=" AND items.ccode = ? "; - push @bind_params, $params->{ccodeslimit}; - } - if( $params->{locationslimit} ) { - $query .=" AND items.location = ? "; - push @bind_params, $params->{locationslimit}; - } - $query .= " ORDER BY ccode, location, cn_sort, author, title, pickbranch, reservedate"; - my $sth = $dbh->prepare($query); - $sth->execute(@bind_params); - 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}; + my $search_params; + $search_params->{'me.holdingbranch'} = $params->{branchlimit} if $params->{branchlimit}; + $search_params->{'itype'} = $params->{itemtypeslimit} if $params->{itemtypeslimit}; + $search_params->{'ccode'} = $params->{ccodeslimit} if $params->{ccodeslimit}; + $search_params->{'location'} = $params->{locationslimit} if $params->{locationslimit}; + + my $results = Koha::Hold::HoldsQueueItems->search( + $search_params, + { + join => [ + 'borrower', + 'biblio', + 'biblioitem', + { + 'item' => { + 'item_group_item' => 'item_group' + } + }, + ], + prefetch => [ + 'biblio', + 'biblioitem', + { + 'item' => { + 'item_group_item' => 'item_group' + } + } + ], + order_by => [ + 'ccode', 'location', 'item.cn_sort', 'author', + 'biblio.title', 'pickbranch', 'reservedate' + ], } - delete $row->{itemtype}; + ); - push @$items, $row; - } - return $items; + return $results; } =head2 CreateQueue --- a/Koha/Hold/HoldsQueueItem.pm +++ a/Koha/Hold/HoldsQueueItem.pm @@ -19,6 +19,10 @@ use Modern::Perl; use Koha::Database; +use Koha::Items; +use Koha::Biblios; +use Koha::Patrons; + use base qw(Koha::Object); =head1 NAME @@ -27,6 +31,41 @@ Koha::Hold::HoldsQueueItem - Koha hold cancellation request Object class =head1 API +=head2 Class methods + +=head3 patron + +=cut + +sub patron { + my ( $self ) = @_; + my $rs = $self->_result->borrowernumber; + return unless $rs; + return Koha::Patron->_new_from_dbic( $rs ); +} + +=head3 biblio + +=cut + +sub biblio { + my ( $self ) = @_; + my $rs = $self->_result->biblionumber; + return unless $rs; + return Koha::Biblio->_new_from_dbic( $rs ); +} + +=head3 item + +=cut + +sub item { + my ( $self ) = @_; + my $rs = $self->_result->itemnumber; + return unless $rs; + return Koha::Item->_new_from_dbic( $rs ); +} + =head2 Internal methods =head3 _type --- a/Koha/Schema/Result/TmpHoldsqueue.pm +++ a/Koha/Schema/Result/TmpHoldsqueue.pm @@ -224,6 +224,54 @@ __PACKAGE__->add_columns( '+item_level_request' => { is_boolean => 1 } ); +__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", + }, +); + +__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", + }, +); + sub koha_object_class { 'Koha::HoldsQueueItem'; } --- a/circ/view_holdsqueue.pl +++ a/circ/view_holdsqueue.pl @@ -47,24 +47,24 @@ my $itemtypeslimit = $params->{'itemtypeslimit'}; my $ccodeslimit = $params->{'ccodeslimit'}; my $locationslimit = $params->{'locationslimit'}; -if ( $run_report ) { - my $items = GetHoldsQueueItems({ - branchlimit => $branchlimit, - itemtypeslimit => $itemtypeslimit, - ccodeslimit => $ccodeslimit, - locationslimit => $locationslimit - }); - for my $item ( @$items ) { - $item->{patron} = Koha::Patrons->find( $item->{borrowernumber} ); - } +if ($run_report) { + my $items = GetHoldsQueueItems( + { + branchlimit => $branchlimit, + itemtypeslimit => $itemtypeslimit, + ccodeslimit => $ccodeslimit, + locationslimit => $locationslimit + } + ); + $template->param( - branchlimit => $branchlimit, - itemtypeslimit => $itemtypeslimit, - ccodeslimit => $ccodeslimit, - locationslimit => $locationslimit, - total => scalar @$items, - itemsloop => $items, - run_report => $run_report, + branchlimit => $branchlimit, + itemtypeslimit => $itemtypeslimit, + ccodeslimit => $ccodeslimit, + locationslimit => $locationslimit, + total => $items->count, + itemsloop => $items, + run_report => $run_report, ); } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt @@ -156,40 +156,40 @@
- [% INCLUDE 'biblio-title.inc' biblio=itemsloo link = 1 %] + [% INCLUDE 'biblio-title.inc' biblio=itemsloo.biblio link = 1 %]