From 56fc5070101c17195853fdd364266a5498978310 Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Fri, 18 Jan 2013 16:07:59 +0100 Subject: [PATCH] Bug 9426: Add itemtype description template plugin Like branch name template plugin KohaBranchName, add a plugin that converts itemtype code into its description. This patch adds this template plugin and a method tho instanciate a C4::ItemType object using its code. Test plan : - Choose an existing itemtype code (ie DVD) - Edit any template (ie intranet-main.tt) - Add as first line : [% USE KohaItemType %] - Add in body : itemtype=[% 'DVD' | $KohaItemType %] - Go to this page => Itemtype description is displayed next to 'itemtype=' Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- C4/ItemType.pm | 21 ++++++++++++++++++++ Koha/Template/Plugin/KohaItemType.pm | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Koha/Template/Plugin/KohaItemType.pm diff --git a/C4/ItemType.pm b/C4/ItemType.pm index 648cff9..daeba5e 100644 --- a/C4/ItemType.pm +++ b/C4/ItemType.pm @@ -87,6 +87,27 @@ sub all { return @itypes; } +=head3 C4::ItemType->new_from_code($code) + +This returns the itemtype as object from code. + +=cut + +sub new_from_code { + my ($class, $code) = @_; + my $dbh = C4::Context->dbh; + my $itype; + my $sth = $dbh->prepare(q{ + SELECT * FROM itemtypes WHERE itemtype = ? + }); + $sth->execute($code); + my $data = $sth->fetchrow_hashref; + if ($data) { + $itype = $class->new($data); + utf8::encode($itype->{description}); + } + return $itype; +} diff --git a/Koha/Template/Plugin/KohaItemType.pm b/Koha/Template/Plugin/KohaItemType.pm new file mode 100644 index 0000000..d5b276b --- /dev/null +++ b/Koha/Template/Plugin/KohaItemType.pm @@ -0,0 +1,36 @@ +package Koha::Template::Plugin::KohaItemType; + +# Copyright 2013 BibLibre SARL + +# 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 2 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 strict; +use warnings; + +use Template::Plugin::Filter; +use base qw( Template::Plugin::Filter ); +use warnings; +use strict; + +use C4::ItemType; + +sub filter { + my ($self,$code) = @_; + my $itemtype = C4::ItemType->new_from_code($code); + return $itemtype ? $itemtype->description : ''; +} + +1; -- 1.7.10.4