From 17d5015661263b58069daaa7c8444056f37bc59d Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 14 Jul 2016 13:48:56 -0400 Subject: [PATCH] [SIGNED-OFF] Bug 14876 - Show number of holds on the staff side next to 'holds' link This patch adds a a Holds plugin for the templates to count existing holds on a record. We then use this in koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt to display the current number of holds on a record. To test: 1 - Search in staff 2 - Note holds link has no extra information 3 - Apply patch 4 - prove -v t/db_dependent/Template/Plugin/Holds.t 5 - Do search in staff that returns records with some holds (i.e. place some holds) 6 - Note the number of holds now displays next to the text of the link: Holds (#) Signed-off-by: Liz Rea --- Koha/Template/Plugin/Holds.pm | 48 ++++++++++++++++++++++ .../prog/en/modules/catalogue/results.tt | 3 +- t/db_dependent/Template/Plugin/Holds.t | 43 +++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 Koha/Template/Plugin/Holds.pm create mode 100644 t/db_dependent/Template/Plugin/Holds.t diff --git a/Koha/Template/Plugin/Holds.pm b/Koha/Template/Plugin/Holds.pm new file mode 100644 index 0000000..91a978c --- /dev/null +++ b/Koha/Template/Plugin/Holds.pm @@ -0,0 +1,48 @@ +package Koha::Template::Plugin::Holds; + +# 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 base qw( Template::Plugin ); + +use Koha::Holds qw(); + +=pod + +This plugin is a home for various patron related Template Toolkit functions +to help streamline Koha and to move logic from the Perl code into the +Templates when it makes sense to do so. + +To use, first, include the line '[% USE Borrowers %]' at the top +of the template to enable the plugin. + +For example: [% IF Borrowers.IsDebarred( borrower ) %] +removes the necessity of setting a template variable in Perl code to +find out if a patron is restricted even if that variable is not evaluated +in any way in the script. + +=cut + +sub count { + my ( $self, $biblionumber ) = @_; + + return unless $biblionumber; + + return Koha::Holds->count( { biblionumber => $biblionumber } ); +} + +1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index 9902578..8bd347c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -1,4 +1,5 @@ [% USE Koha %] +[% USE Holds %] [% INCLUDE 'doc-head-open.inc' %] Koha › Catalog › [% IF ( searchdesc ) %]Results of search [% IF ( query_desc ) %]for '[% query_desc | html %]'[% END %][% IF ( limit_desc ) %] with limit(s): '[% limit_desc | html %]'[% END %][% ELSE %]You did not specify any search criteria[% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -583,7 +584,7 @@ var holdForPatron = function () { [% IF ( SEARCH_RESULT.norequests ) %] No holds allowed [% ELSE %] - Holds + Holds ([% Holds.count(SEARCH_RESULT.biblionumber) %]) [% IF ( holdfor ) %] | Place hold for [% holdfor_firstname %] [% holdfor_surname %] ([% holdfor_cardnumber %])[% END %] [% END %] diff --git a/t/db_dependent/Template/Plugin/Holds.t b/t/db_dependent/Template/Plugin/Holds.t new file mode 100644 index 0000000..33fd2a7 --- /dev/null +++ b/t/db_dependent/Template/Plugin/Holds.t @@ -0,0 +1,43 @@ +use Modern::Perl; + +use Test::More tests => 3; +use t::lib::TestBuilder; + +use C4::Context; +use Koha::Database; +use Koha::Library; +use Koha::Libraries; +use Koha::Template::Plugin::Holds; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; + +my $dbh = C4::Context->dbh; + +#$dbh->{AutoCommit} = 0; +#$dbh->{RaiseError} = 1; + +my $biblio = $builder->build({ + source => 'Biblio', + value => {} +}); + +my $plugin = Koha::Template::Plugin::Holds->new(); +ok($plugin, "initialized Holds plugin"); + +my $count = $plugin->count($biblio->{biblionumber}); +is($count, 0, 'No holds expected yet'); + +my $hold = $builder->build({ + source => 'Reserve', + value => { + biblionumber => $biblio->{biblionumber} + } +}); + +$count = $plugin->count($biblio->{biblionumber}); +is($count, 1, 'Now there is a hold'); + +$schema->storage->txn_rollback; -- 1.9.1