diff --git a/C4/Auth.pm b/C4/Auth.pm index 00dedcb22a..9ee5c2bb2d 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -238,12 +238,12 @@ sub get_template_and_user { } my $borrowernumber; + my $patron; if ($user) { # It's possible for $user to be the borrowernumber if they don't have a # userid defined (and are logging in through some other method, such # as SSL certs against an email address) - my $patron; $borrowernumber = getborrowernumber($user) if defined($user); if ( !defined($borrowernumber) && defined($user) ) { $patron = Koha::Patrons->find( $user ); @@ -610,6 +610,7 @@ sub get_template_and_user { PatronSelfRegistration => C4::Context->preference("PatronSelfRegistration"), PatronSelfRegistrationDefaultCategory => C4::Context->preference("PatronSelfRegistrationDefaultCategory"), useDischarge => C4::Context->preference('useDischarge'), + routing_lists_exist => ( $patron and $patron->get_routinglists ), ); $template->param( OpacPublic => '1' ) if ( $user || C4::Context->preference("OpacPublic") ); diff --git a/Koha/Patron.pm b/Koha/Patron.pm index c5dcc12e30..fb278aac80 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -39,6 +39,7 @@ use Koha::Patrons; use Koha::Virtualshelves; use Koha::Club::Enrollments; use Koha::Account; +use Koha::Subscription::Routinglists; use base qw(Koha::Object); @@ -649,7 +650,7 @@ sub old_checkouts { my $overdue_items = $patron->get_overdues -Return the overdued items +Return the overdue items =cut @@ -666,6 +667,20 @@ sub get_overdues { ); } +=head3 get_routinglists + +my @routinglists = $patron->get_routinglists + +Returns the routing lists a patron is subscribed to. + +=cut + +sub get_routinglists { + my ($self) = @_; + 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 0000000000..4c081e5774 --- /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 ); +} + +=head2 Internal methods + +=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 0000000000..198118e6e4 --- /dev/null +++ b/Koha/Subscription/Routinglists.pm @@ -0,0 +1,62 @@ +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 + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'Subscriptionroutinglist'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Subscription::Routinglist'; +} + +=head1 AUTHOR + +Katrin Fischer + +=cut + +1; diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc index 7d27f22d75..5914f04a2b 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc @@ -96,6 +96,15 @@ your lists [% END %] + [% IF Koha.Preference( 'RoutingSerials' ) && routing_lists_exist %] + [% IF ( routinglistsview ) %] +
  • + [% ELSE %] +
  • + [% END %] + your routing lists
  • + [% END %] + [% IF Koha.Preference( 'useDischarge' ) == 1 %] [% IF ( dischargeview ) %]
  • 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 new file mode 100644 index 0000000000..ba1e34a108 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-routing-lists.tt @@ -0,0 +1,71 @@ +[% USE Asset %] +[% USE Koha %] +[% USE KohaDates %] +[% INCLUDE 'doc-head-open.inc' %] +[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › Your routing lists +[% INCLUDE 'doc-head-close.inc' %] +[% BLOCK cssinclude %] + [% Asset.css("css/datatables.css") %] +[% END %] + + +[% INCLUDE 'bodytag.inc' bodyid='opac-account' bodyclass='scrollto' %] +[% INCLUDE 'masthead.inc' %] + +
    + + +
    +
    +
    + +
    +
    +
    + + +

    Routing lists

    + + [% IF ( routinglists ) %] +

    You are subscribed to the routing lists for following serial titles. If you wish to make changes, please contact the library.

    + + + + + + + + + + [% FOREACH routinglist IN routinglists %] + [% IF ( titles_loop.odd ) %][% ELSE %][% END %] + + + [% END %] + +
    Subscription title
    + + [% routinglist.subscription.biblio.title %] + +
    + [% ELSE %] +

    You are currently not listed on any routing lists.

    + [% END %] +
    +
    +
    +
    +
    + +[% INCLUDE 'opac-bottom.inc' %] +[% BLOCK jsinclude %] +[% INCLUDE 'datatables.inc' %] + +[% END %] diff --git a/opac/opac-routing-lists.pl b/opac/opac-routing-lists.pl new file mode 100644 index 0000000000..331cc4d0d5 --- /dev/null +++ b/opac/opac-routing-lists.pl @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +# 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, see . + + +use Modern::Perl; +use CGI qw ( -utf8 ); +use C4::Members; +use C4::Auth; +use C4::Output; +use Koha::Patrons; + +my $query = new CGI; + +unless ( C4::Context->preference('RoutingSerials') ) { + print $query->redirect("/cgi-bin/koha/errors/404.pl"); + exit; +} + + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "opac-routing-lists.tt", + query => $query, + type => "opac", + authnotrequired => 0, + debug => 1, + } +); + +my $patron = Koha::Patrons->find( $borrowernumber ); +my $category = $patron->category; +my $borrower= $patron->unblessed; +$borrower->{description} = $category->description; +$borrower->{category_type} = $category->category_type; +$template->param( BORROWER_INFO => $borrower ); + +my @routinglists = $patron->get_routinglists(); + +$template->param( + routinglists => \@routinglists, + routinglistview => 1, +); + +output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 04352c9de3..a36a1ed95f 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -529,6 +529,49 @@ subtest 'checkouts + pending_checkouts + get_overdues + old_checkouts' => sub { $module->unmock('userenv'); }; +subtest 'get_routinglists' => sub { + plan tests => 5; + + my $biblio = Koha::Biblio->new()->store(); + my $subscription = Koha::Subscription->new({ + biblionumber => $biblio->biblionumber, + } + )->store; + + my $patron = $builder->build( { source => 'Borrower' } ); + $patron = Koha::Patrons->find( $patron->{borrowernumber} ); + + is( $patron->get_routinglists, 0, 'Retrieves correct number of routing lists: 0' ); + + my $routinglist_count = Koha::Subscription::Routinglists->count; + my $routinglist = Koha::Subscription::Routinglist->new({ + borrowernumber => $patron->borrowernumber, + ranking => 5, + subscriptionid => $subscription->subscriptionid + })->store; + + is ($patron->get_routinglists, 1, "Retrieves correct number of routing lists: 1"); + + my @routinglists = $patron->get_routinglists; + is ($routinglists[0]->ranking, 5, "Retrieves ranking: 5"); + is( ref($routinglists[0]), 'Koha::Subscription::Routinglist', 'get_routinglists returns Koha::Subscription::Routinglist objects' ); + + my $subscription2 = Koha::Subscription->new({ + biblionumber => $biblio->biblionumber, + } + )->store; + my $routinglist2 = Koha::Subscription::Routinglist->new({ + borrowernumber => $patron->borrowernumber, + ranking => 1, + subscriptionid => $subscription2->subscriptionid + })->store; + + is ($patron->get_routinglists, 2, "Retrieves correct number of routing lists: 2"); + + $patron->delete; # Clean up for later tests + +}; + subtest 'get_age' => sub { plan tests => 7; diff --git a/t/db_dependent/Koha/Subscription/Routinglists.t b/t/db_dependent/Koha/Subscription/Routinglists.t new file mode 100644 index 0000000000..1eff86ca54 --- /dev/null +++ b/t/db_dependent/Koha/Subscription/Routinglists.t @@ -0,0 +1,67 @@ +#!/usr/bin/perl + +# 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 +# WIT HOUT 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, see . + +use Modern::Perl; + +use Test::More tests => 1; +use t::lib::TestBuilder; + +use C4::Biblio; + +use Koha::Database; +use Koha::Patrons; +use Koha::Subscriptions; +use Koha::Subscription::Routinglists; + +my $schema = Koha::Database->new->schema; +my $builder = t::lib::TestBuilder->new; + +subtest 'new() tests' => sub { + plan tests => 4; + + $schema->storage->txn_begin; + + my $biblio = Koha::Biblio->new()->store(); + my $subscription = Koha::Subscription->new({ + biblionumber => $biblio->biblionumber, + } + )->store; + + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->id } }); + + my $routinglist_count = Koha::Subscription::Routinglists->count; + my $routinglist = Koha::Subscription::Routinglist->new({ + borrowernumber => $patron->borrowernumber, + ranking => 1, + subscriptionid => $subscription->subscriptionid + })->store; + + is( Koha::Subscription::Routinglists->search->count, $routinglist_count +1, 'One routing list added' ); + + my $retrieved_routinglist = Koha::Subscription::Routinglists->find( $routinglist->routingid ); + is ( $retrieved_routinglist->routingid, $routinglist->routingid, "Find a routing list by id returns the correct routing list"); + + $routinglist->ranking(4)->update; + is ( $routinglist->ranking, 4, "Routing list ranking has been updated"); + + $routinglist->delete; + is ( Koha::Subscription::Routinglists->search->count, $routinglist_count, 'One subscription list deleted' ); + +}; + +$schema->storage->txn_rollback;