From 57fe9e1a71cae0d4fcc114c56da1573b8e6f4963 Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Sun, 12 Nov 2017 10:50:58 +0000 Subject: [PATCH] Bug 19520: Add more information about rotating collections Test plan: 1) Apply the patch 2) Update database 3) prove t/db_dependent/Koha/RotatingCollections.t --- Koha/RotatingCollection.pm | 65 +++++++++++++++++++++- .../rotating_collections/rotatingCollections.tt | 21 +++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/Koha/RotatingCollection.pm b/Koha/RotatingCollection.pm index 51e7b72..4648b95 100644 --- a/Koha/RotatingCollection.pm +++ b/Koha/RotatingCollection.pm @@ -21,6 +21,8 @@ use Modern::Perl; use Carp; +use C4::Context; + use Koha::Database; use Koha::DateUtils; use Koha::Exceptions; @@ -40,6 +42,23 @@ Koha::RotatingCollection - Koha Rotating collection Object class =cut +=head3 new + + $collection = Koha::RotatingCollection->new(); + + This sub automatically adds date of creation and librarian who created collection if it is not present in params. + +=cut + +sub new { + my ($class, $params) = @_; + $params->{createdOn} //= output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); + $params->{createdBy} = undef; + $params->{createdBy} = C4::Context->userenv->{number} if defined C4::Context->userenv; + + return $class->SUPER::new($params); +} + =head3 items =cut @@ -58,6 +77,30 @@ sub items { return $items; } +=head3 untransferred_items + +my $untransferred_items = $collection->untransferred_items; + +Return all items which are not transferred yet + +=cut + +sub untransferred_items { + my ( $self ) = @_; + + my $items = Koha::Items->search( + { + 'collections_trackings.colId' => $self->colId, + 'branchtransfers.branchtransfer_id' => undef, + }, + { + join => [ 'collections_trackings', 'branchtransfers' ] + } + ); + + return $items; +} + =head3 add_item $collection->add_item( $item_object ); @@ -134,7 +177,9 @@ sub transfer { Koha::Exceptions::ObjectNotFound->throw if ref($library) ne 'Koha::Library'; - $self->colBranchcode( $library->branchcode )->store; + $self->colBranchcode( $library->branchcode ); + $self->lastTransferredOn( output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }) ); + $self->store; my $from; $from = C4::Context->userenv->{'branch'} if C4::Context->userenv; @@ -162,6 +207,24 @@ sub transfer { } } +=head3 creator + + $creator = $collection->creator + + return creator (Koha::Patron object) of this collection + +=cut + +sub creator { + my ( $self ) = @_; + + return unless $self->createdBy; + + my $patron = Koha::Patrons->find( $self->createdBy ); + + return $patron; +} + =head3 type =cut diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/rotatingCollections.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/rotatingCollections.tt index 585f820..7df48d6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/rotatingCollections.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/rotatingCollections.tt @@ -1,4 +1,5 @@ [% USE Branches %] +[% USE KohaDates %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Tools › Rotating collections @@ -28,6 +29,10 @@ Title Description Library + Date created + Created by + Number of items + Number of untransferred items   @@ -38,6 +43,22 @@ [% collectionsLoo.colDesc %] [% Branches.GetName( collectionsLoo.colBranchcode ) %] + [% IF collectionsLoo.createdOn %] + [% collectionsLoo.createdOn | $KohaDates %] + [% ELSE %] + + [% END %] + + + [% IF collectionsLoo.creator %] + + [% collectionsLoo.creator.firstname %] [% collectionsLoo.creator.surname %] + + [% END %] + + [% collectionsLoo.items.count %] + [% collectionsLoo.untransferred_items.count %] +