From 91394ba7abcb375b3b6c36d1feef8058fd2f8c6e Mon Sep 17 00:00:00 2001 From: Katrin Fischer Date: Thu, 15 Mar 2018 15:26:35 +0000 Subject: [PATCH] Bug 20400: Rewrite using Koha::Objects Adds - Koha::Subscription::Routinglist - Koha::Subscription::Routinglists Adds 2 methods - Koha::Patron::get_routinglists - Koha::Routinglist::subscription --- Koha/Patron.pm | 20 ++++++- Koha/Subscription/Routinglist.pm | 67 ++++++++++++++++++++++ Koha/Subscription/Routinglists.pm | 57 ++++++++++++++++++ .../bootstrap/en/modules/opac-routing-lists.tt | 10 ++-- opac/opac-routing-lists.pl | 21 +------ 5 files changed, 150 insertions(+), 25 deletions(-) create mode 100644 Koha/Subscription/Routinglist.pm create mode 100644 Koha/Subscription/Routinglists.pm diff --git a/Koha/Patron.pm b/Koha/Patron.pm index d0be998..ae37e3f 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -38,6 +38,7 @@ use Koha::Patrons; use Koha::Virtualshelves; use Koha::Club::Enrollments; use Koha::Account; +use Koha::Subscription::Routinglists; use base qw(Koha::Object); @@ -539,7 +540,7 @@ sub old_checkouts { my $overdue_items = $patron->get_overdues -Return the overdued items +Return the overdue items =cut @@ -556,6 +557,23 @@ sub get_overdues { ); } +=cut + +=head3 get_routinglists + +my @routinglists = $patron->get_routinglists + +Returns the routing lists a patron is subscribed to. + +=cut + +sub get_routinglists { + my ($self) = @_; + my @titles; + my @subscribed_routings = Koha::Subscription::Routinglists->search({ borrowernumber => $self->borrowernumber }); + return @subscribed_routings; +} + =head3 get_age my $age = $patron->get_age diff --git a/Koha/Subscription/Routinglist.pm b/Koha/Subscription/Routinglist.pm new file mode 100644 index 0000000..3691fd9 --- /dev/null +++ b/Koha/Subscription/Routinglist.pm @@ -0,0 +1,67 @@ +package Koha::Subscription::Routinglist; + +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; +use Koha::Subscriptions; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Subscription::Routinglist - Koha subscription routing list object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 subscription + +my $subscription = $routinglist->subscription + +Returns the subscription for a routing list. + +=cut + +sub subscription { + my ( $self ) = @_; + return scalar Koha::Subscriptions->find( $self->subscriptionid ); +} + +=cut + +=head3 type + +=cut + +sub _type { + return 'Subscriptionroutinglist'; +} + +=head1 AUTHOR + +Katrin Fischer + +=cut + +1; diff --git a/Koha/Subscription/Routinglists.pm b/Koha/Subscription/Routinglists.pm new file mode 100644 index 0000000..f2bbfac --- /dev/null +++ b/Koha/Subscription/Routinglists.pm @@ -0,0 +1,57 @@ +package Koha::Subscription::Routinglists; + +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Subscription::Routinglist; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Subscription::Routinglists - Koha subscription routing lists object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'Subscriptionroutinglist'; +} + +sub object_class { + return 'Koha::Subscription::Routinglist'; +} + +=head1 AUTHOR + +Katrin Fischer + +=cut + +1; diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-routing-lists.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-routing-lists.tt index fa791a6..697f874 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-routing-lists.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-routing-lists.tt @@ -31,7 +31,7 @@

Routing lists

- [% IF ( subscriptionLoop ) %] + [% IF ( routinglists ) %] @@ -40,11 +40,11 @@ - [% FOREACH subscription IN subscriptionLoop %] - [% IF ( subscripLoop.odd ) %][% ELSE %][% END %] + [% FOREACH routinglist IN routinglists %] + [% IF ( titles_loop.odd ) %][% ELSE %][% END %] diff --git a/opac/opac-routing-lists.pl b/opac/opac-routing-lists.pl index 55e3878..6567579 100644 --- a/opac/opac-routing-lists.pl +++ b/opac/opac-routing-lists.pl @@ -23,7 +23,6 @@ use C4::Auth; use C4::Output; use C4::Serials; use Koha::Patrons; -use Koha::Subscriptions; my $query = new CGI; my ( $template, $borrowernumber, $cookie ) = get_template_and_user( @@ -43,26 +42,10 @@ $borrower->{description} = $category->description; $borrower->{category_type} = $category->category_type; $template->param( BORROWER_INFO => $borrower ); - -my $count; -my @borrowerSubscriptions; -($count, @borrowerSubscriptions) = GetSubscriptionsFromBorrower($borrowernumber ); -my @subscripLoop; - -foreach my $num_res (@borrowerSubscriptions) { - my %getSubscrip; - $getSubscrip{subscriptionid} = $num_res->{'subscriptionid'}; - $getSubscrip{title} = $num_res->{'title'}; - $getSubscrip{borrowernumber} = $num_res->{'borrowernumber'}; - my $subscription = Koha::Subscriptions->find( $num_res->{'subscriptionid'} ); - $getSubscrip{biblionumber} = $subscription->biblionumber(); - push( @subscripLoop, \%getSubscrip ); -} +my @routinglists = $patron->get_routinglists(); $template->param( - countSubscrip => scalar @subscripLoop, - subscriptionLoop => \@subscripLoop, - routinglistview => 1 + routinglists => \@routinglists, ); output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; -- 2.1.4
- - [% subscription.title %] + + [% routinglist.subscription.biblio.title %]