Bug 20400: Add routing list tab in OPAC
authorKatrin Fischer <katrin.fischer.83@web.de>
Thu, 15 Mar 2018 08:40:12 +0000 (08:40 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 20 Apr 2018 16:34:41 +0000 (13:34 -0300)
This patch adds the base for the new feature:
Show a list of the serial titles a patron is on routing
lists for in the OPAC.

Test plan applies to the complete patch set:

To test:
- Apply all patches
- Make sure RoutingSerials is not activated
- Check patron account in OPAC - no tab should appear
- Activate RoutingSerials
- Create subscriptions and different routing lists, test with:
  - Patron with no routing list entries = no tab
  - Patron with one or more routing list entries = tab appears

Signed-off-by: Dilan Johnpullé <dilan@calyx.net.au>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Bug 20400: Rewrite using Koha::Objects

Adds
- Koha::Subscription::Routinglist
- Koha::Subscription::Routinglists

Adds 2 methods
- Koha::Patron::get_routinglists
- Koha::Routinglist::subscription

Signed-off-by: Dilan Johnpullé <dilan@calyx.net.au>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Bug 20400: Add unit tests

prove t/db_dependent/Koha/Subscription/Routinglists.t
prove t/db_dependent/Koha/Patrons.t

Signed-off-by: Dilan Johnpullé <dilan@calyx.net.au>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Bug 20400: Display new tab in OPAC only for patrons with routing lists

The visibility of the routing list tab in the OPAC depends
on the system preference RoutingSerials and the existence
of routing list entries for the patron.

Some libraries only offer routing lists to certain user groups and
would not want it generally visible. As there are currently no
actions you can perform from the list, this appears to be a
reasonable behaviour.

See test plan in first patch.

Signed-off-by: Dilan Johnpullé <dilan@calyx.net.au>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Bug 20400: (follow-up) Use Asset TT plugin on opac-routing-lists.tt

Patch applies and functions as described.
Signed-off-by: Dilan Johnpullé <dilan@calyx.net.au>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Bug 20400: (QA follow-up) Redirect to 404 if routing is disabled

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Auth.pm
Koha/Patron.pm
Koha/Subscription/Routinglist.pm [new file with mode: 0644]
Koha/Subscription/Routinglists.pm [new file with mode: 0644]
koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-routing-lists.tt [new file with mode: 0644]
opac/opac-routing-lists.pl [new file with mode: 0644]
t/db_dependent/Koha/Patrons.t
t/db_dependent/Koha/Subscription/Routinglists.t [new file with mode: 0644]

index 00dedcb..9ee5c2b 100644 (file)
@@ -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") );
index c5dcc12..fb278aa 100644 (file)
@@ -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 (file)
index 0000000..4c081e5
--- /dev/null
@@ -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 <katrin.fischer@bsz-bw.de>
+
+=cut
+
+1;
diff --git a/Koha/Subscription/Routinglists.pm b/Koha/Subscription/Routinglists.pm
new file mode 100644 (file)
index 0000000..198118e
--- /dev/null
@@ -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 <katrin.fischer@bsz-bw.de>
+
+=cut
+
+1;
index 7d27f22..5914f04 100644 (file)
                 <a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=1">your lists</a></li>
             [% END %]
 
+            [% IF Koha.Preference( 'RoutingSerials' ) && routing_lists_exist %]
+                [% IF ( routinglistsview ) %]
+                    <li class="active">
+                [% ELSE %]
+                    <li>
+                [% END %]
+                <a href="/cgi-bin/koha/opac-routing-lists.pl">your routing lists</a></li>
+            [% END %]
+
             [% IF Koha.Preference( 'useDischarge' ) == 1 %]
                 [% IF ( dischargeview ) %]
                     <li class="active">
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 (file)
index 0000000..ba1e34a
--- /dev/null
@@ -0,0 +1,71 @@
+[% USE Asset %]
+[% USE Koha %]
+[% USE KohaDates %]
+[% INCLUDE 'doc-head-open.inc' %]
+<title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; Your routing lists</title>
+[% INCLUDE 'doc-head-close.inc' %]
+[% BLOCK cssinclude %]
+    [% Asset.css("css/datatables.css") %]
+[% END %]
+</head>
+
+[% INCLUDE 'bodytag.inc' bodyid='opac-account' bodyclass='scrollto' %]
+[% INCLUDE 'masthead.inc' %]
+
+<div class="main">
+    <ul class="breadcrumb">
+        <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
+        <li><a href="/cgi-bin/koha/opac-routing-lists.pl">[% INCLUDE 'patron-title.inc' category_type = BORROWER_INFO.category_type firstname = BORROWER_INFO.firstname surname = BORROWER_INFO.surname othernames = BORROWER_INFO.othernames cardnumber = BORROWER_INFO.cardnumber %]</a> <span class="divider">&rsaquo;</span></li>
+        <li><a href="#">Your routing lists</a></li>
+    </ul>
+
+    <div class="container-fluid">
+        <div class="row-fluid">
+            <div class="span2">
+                <div id="navigation">
+                    [% INCLUDE 'navigation.inc' IsPatronPage=1 %]
+                </div>
+            </div>
+            <div class="span10">
+                <div id="user-routing-lists" class="maincontent">
+
+
+                    <h3>Routing lists</h3>
+
+                    [% IF ( routinglists ) %]
+                        <p id="routing-list-intro">You are subscribed to the routing lists for following serial titles. If you wish to make changes, please contact the library.</p>
+
+                        <table class="table table-bordered table-striped" id="routingtable">
+                            <thead>
+                                <tr>
+                                    <th>Subscription title</th>
+                                </tr>
+                            </thead>
+
+                            <tbody>
+                            [% FOREACH routinglist IN routinglists %]
+                                [% IF ( titles_loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
+                                    <td>
+                                        <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% routinglist.subscription.biblio.biblionumber %]">
+                                            [% routinglist.subscription.biblio.title %]
+                                        </a>
+                                    </td>
+                                </tr>
+                            [% END %]
+                            </tbody>
+                        </table>
+                    [% ELSE %]
+                        <p>You are currently not listed on any routing lists.</p>
+                    [% END %]
+                </div>
+            </div> <!-- / .span10 -->
+        </div> <!-- / .row-fluid -->
+    </div> <!-- / .container-fluid -->
+</div> <!-- / .main -->
+
+[% INCLUDE 'opac-bottom.inc' %]
+[% BLOCK jsinclude %]
+[% INCLUDE 'datatables.inc' %]
+<script type="text/javascript">
+</script>
+[% END %]
diff --git a/opac/opac-routing-lists.pl b/opac/opac-routing-lists.pl
new file mode 100644 (file)
index 0000000..331cc4d
--- /dev/null
@@ -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 <http://www.gnu.org/licenses>.
+
+
+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 };
index 04352c9..a36a1ed 100644 (file)
@@ -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 (file)
index 0000000..1eff86c
--- /dev/null
@@ -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 <http://www.gnu.org/licenses>.
+
+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;