From 1b705598aa92d48a2709758b3f08837234df5a1c 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 --- 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 cfcc609..be8862c 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 @@
New collection
- - [% IF ( colId ) %] + [% IF ( collection.colId ) %]
- Transfer + Transfer
- Edit + Edit
- Delete + Delete
[% 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 a5dc9ac..c3de6e8 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 @@ -1,6 +1,6 @@ [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] -Koha › Tools › Rotating collections › Collection [% colTitle %] ’ Add or remove items +Koha › Tools › Rotating collections › Collection [% collection.colTitle %] ’ Add or remove items [% INCLUDE 'doc-head-close.inc' %] @@ -8,21 +8,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 %]

+

Collection [% collection.colTitle %]

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

- +

@@ -90,8 +90,8 @@
-

Items in [% colTitle %]

- [% IF ( collectionItemsLoop ) %] +

Items in [% collection.colTitle %]

+ [% IF ( collection.items ) %] @@ -99,12 +99,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 %][% collectionItemsLoo.barcode %]Remove[% INCLUDE 'biblio-default-view.inc' biblionumber = item.biblionumber %][% item.biblio.title |html %][% item.itemcallnumber %][% item.barcode %]Remove
diff --git a/rotating_collections/addItems.pl b/rotating_collections/addItems.pl index 1a3f358..8ef4645 100755 --- a/rotating_collections/addItems.pl +++ b/rotating_collections/addItems.pl @@ -92,16 +92,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