From 4e12667511add272c109317ec251ba2e09d14ae5 Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Mon, 15 May 2017 11:42:43 +0000 Subject: [PATCH] Bug 18606: Get rid of GetItemsInCollection Signed-off-by: Kyle M Hall --- C4/RotatingCollections.pm | 51 ---------------------- Koha/RotatingCollection.pm | 19 ++++++++ .../en/includes/rotating-collections-toolbar.inc | 9 ++-- .../en/modules/rotating_collections/addItems.tt | 24 +++++----- rotating_collections/addItems.pl | 10 +---- 5 files changed, 36 insertions(+), 77 deletions(-) diff --git a/C4/RotatingCollections.pm b/C4/RotatingCollections.pm index 66a64c4..dafc1dc 100644 --- a/C4/RotatingCollections.pm +++ b/C4/RotatingCollections.pm @@ -48,8 +48,6 @@ BEGIN { require Exporter; @ISA = qw( Exporter ); @EXPORT = qw( - GetItemsInCollection - AddItemToCollection RemoveItemFromCollection TransferCollection @@ -58,55 +56,6 @@ BEGIN { ); } -=head2 GetItemsInCollection - - ( $results, $success, $errorcode, $errormessage ) = GetItemsInCollection( $colId ); - - Returns information about the items in the given collection - - Input: - $colId: The id of the collection - - Output: - $results: Reference to an array of associated arrays - $success: 1 if all database operations were successful, 0 otherwise - $errorCode: Code for reason of failure, good for translating errors in templates - $errorMessage: English description of error - -=cut - -sub GetItemsInCollection { - my ($colId) = @_; - - ## Parameter check - if ( !$colId ) { - return ( 0, 0, 1, "NO_ID" ); - } - - my $dbh = C4::Context->dbh; - - my $sth = $dbh->prepare( - "SELECT - biblio.title, - biblio.biblionumber, - items.itemcallnumber, - items.barcode - FROM collections, collections_tracking, items, biblio - WHERE collections.colId = collections_tracking.colId - AND collections_tracking.itemnumber = items.itemnumber - AND items.biblionumber = biblio.biblionumber - AND collections.colId = ? ORDER BY biblio.title" - ); - $sth->execute($colId) or return ( 0, 0, 2, $sth->errstr() ); - - my @results; - while ( my $row = $sth->fetchrow_hashref ) { - push( @results, $row ); - } - - return \@results; -} - =head2 AddItemToCollection ( $success, $errorcode, $errormessage ) = AddItemToCollection( $colId, $itemnumber ); diff --git a/Koha/RotatingCollection.pm b/Koha/RotatingCollection.pm index c8857b2..ba90192 100644 --- a/Koha/RotatingCollection.pm +++ b/Koha/RotatingCollection.pm @@ -22,6 +22,7 @@ use Modern::Perl; use Carp; use Koha::Database; +use Koha::Items; use base qw(Koha::Object); @@ -35,6 +36,24 @@ Koha::RotatingCollection - Koha Rotating collection Object class =cut +=head3 items + +=cut + +sub items { + my ( $self ) = @_; + my $items = Koha::Items->search( + { + 'collections_trackings.colId' => $self->colId + }, + { + join => [ 'collections_trackings' ] + } + ); + + return $items; +} + =head3 type =cut diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/rotating-collections-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/rotating-collections-toolbar.inc index 804fcfa..5ec0e36 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/rotating-collections-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/rotating-collections-toolbar.inc @@ -3,16 +3,15 @@ - - [% IF ( colId ) %] + [% IF ( collection.colId ) %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tt index 7c0f04c..954cd6a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tt @@ -2,7 +2,7 @@ [% USE Asset %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] -Koha › Tools › Rotating collections › Collection [% colTitle | html %] ’ Add or remove items +Koha › Tools › Rotating collections › Collection [% collection.colTitle | html %] ’ Add or remove items [% INCLUDE 'doc-head-close.inc' %] @@ -10,21 +10,21 @@ [% INCLUDE 'header.inc' %] [% INCLUDE 'cat-search.inc' %] - +
- [% IF ( ! colId ) %] + [% IF ( ! collection ) %]

Invalid collection id

Return to rotating collections home

[% ELSE %] [% INCLUDE 'rotating-collections-toolbar.inc' %] -

Collection [% colTitle | html %]

+

Collection [% collection.colTitle | html %]

[% IF ( previousActionAdd ) %] [% IF ( addSuccess ) %] @@ -82,7 +82,7 @@

- +

@@ -92,8 +92,8 @@
-

Items in [% colTitle | html %]

- [% IF ( collectionItemsLoop ) %] +

Items in [% collection.colTitle | html %]

+ [% IF ( collection.items ) %] @@ -101,12 +101,12 @@ - [% FOREACH collectionItemsLoo IN collectionItemsLoop %] + [% FOREACH item IN collection.items %] - - - - + + + + [% END %]
TitleBarcode  
[% INCLUDE 'biblio-default-view.inc' biblionumber = collectionItemsLoo.biblionumber %][% collectionItemsLoo.title | html %][% collectionItemsLoo.itemcallnumber | html %][% collectionItemsLoo.barcode | html %]Remove[% INCLUDE 'biblio-default-view.inc' biblionumber = item.biblionumber %][% item.biblio.title |html %][% item.itemcallnumber | html%][% item.barcode | html %]Remove
diff --git a/rotating_collections/addItems.pl b/rotating_collections/addItems.pl index 3aee138..11c6612 100755 --- a/rotating_collections/addItems.pl +++ b/rotating_collections/addItems.pl @@ -94,16 +94,8 @@ if ( $query->param('action') eq 'addItem' ) { my $colId = $query->param('colId'); my $collection = Koha::RotatingCollections->find($colId); -my $collectionItems = GetItemsInCollection($colId); -if ($collectionItems) { - $template->param( collectionItemsLoop => $collectionItems ); -} - $template->param( - colId => $collection->colId, - colTitle => $collection->colTitle, - colDescription => $collection->colDesc, - colBranchcode => $collection->colBranchcode, + collection => $collection, ); output_html_with_http_headers $query, $cookie, $template->output; -- 2.1.4