From 59f3256c9b32824b8fcb625acf06f56b291d136e Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 25 Apr 2023 14:14:19 +0000 Subject: [PATCH] Bug 33607: Add framework display to staff details page This patch adds a Frameworks pluing to allow fetching the framework text and displays this on the intranet details page To test: 1 - Apply patch 2 - View a record details page in staff 3 - Confirm you see the framework name 4 - prove -v t/db_dependent/Template/Plugin/Frameworks.t --- Koha/Template/Plugin/Frameworks.pm | 58 +++++++++++++++++++ .../prog/en/modules/catalogue/detail.tt | 5 ++ t/db_dependent/Template/Plugin/Frameworks.t | 52 +++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 Koha/Template/Plugin/Frameworks.pm create mode 100755 t/db_dependent/Template/Plugin/Frameworks.t diff --git a/Koha/Template/Plugin/Frameworks.pm b/Koha/Template/Plugin/Frameworks.pm new file mode 100644 index 0000000000..e2d9572399 --- /dev/null +++ b/Koha/Template/Plugin/Frameworks.pm @@ -0,0 +1,58 @@ +package Koha::Template::Plugin::Frameworks; + +# Copyright ByWater Solutions 2023 + +# 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 Template::Plugin; +use base qw( Template::Plugin ); + +use Koha::BiblioFrameworks; + +=head1 NAME + +Koha::Template::Plugin::Frameworks - A module for dealing with biblio frameworks in templates + +=head1 DESCRIPTION + +This plugin contains functions for getting frameowrk information in the template + +=head2 Methods + +=head3 GetName + +[% Frameworks.GetName( frameworkcode ) %] + +Return the display name (frameworktext field) for a framework, or the passed code if the framework +is not found + +=cut + + +sub GetName { + my ( $self, $frameworkcode ) = @_; + return q{} unless defined $frameworkcode; + return q{} if $frameworkcode eq q{}; + + my $f = Koha::BiblioFrameworks->find($frameworkcode); + + my $frameworktext = $f ? $f->frameworktext : $frameworkcode; + return $frameworktext; +} + +1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 1fdb6fe7eb..0442d069c7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -6,6 +6,7 @@ [% USE AuthorisedValues %] [% USE Branches %] [% USE Biblio %] +[% USE Frameworks %] [% USE Price %] [% USE TablesSettings %] [% PROCESS 'i18n.inc' %] @@ -135,6 +136,10 @@ [% END %] MARC preview: Show + + MARC framework: + [% Frameworks.GetName(biblio.frameworkcode) | html %] + [% IF !item_level_itypes || Koha.Preference("BiblioItemtypeInfo") %] Itemtype: [% IF ( !noItemTypeImages && imageurl ) %] diff --git a/t/db_dependent/Template/Plugin/Frameworks.t b/t/db_dependent/Template/Plugin/Frameworks.t new file mode 100755 index 0000000000..be3a16935a --- /dev/null +++ b/t/db_dependent/Template/Plugin/Frameworks.t @@ -0,0 +1,52 @@ +#!/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 Test::More tests => 2; +use Test::MockModule; + +use t::lib::TestBuilder; +use t::lib::Mocks; + +BEGIN { + use_ok('Koha::Template::Plugin::Frameworks'); +} + +my $schema = Koha::Database->schema; +my $builder = t::lib::TestBuilder->new; + +$schema->storage->txn_begin; + +subtest 'GetName tests' => sub { + plan tests => 3; + + my $framework = $builder->build_object({ class => 'Koha::BiblioFrameworks' })->store; + + my $plugin = Koha::Template::Plugin::Frameworks->new(); + + my $name = $plugin->GetName( $framework->frameworkcode ); + is( $name, $framework->frameworktext, "Name correctly fetched" ); + + $name = $plugin->GetName(); + is( $name, q{}, "Nothing returned if nothing passed" ); + + $framework->delete; + $name = $plugin->GetName( $framework->frameworkcode ); + is( $name, $framework->frameworkcode, "When framework not found, we get the code back" ); +}; + +$schema->storage->txn_rollback; -- 2.30.2