Bug 17252 - Koha::AuthorisedValues - Remove GetAuthorisedValueByCode
[koha.git] / Koha / Template / Plugin / AuthorisedValues.pm
1 package Koha::Template::Plugin::AuthorisedValues;
2
3 # Copyright 2012 ByWater Solutions
4 # Copyright 2013-2014 BibLibre
5 #
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19 use Modern::Perl;
20
21 use Template::Plugin;
22 use base qw( Template::Plugin );
23
24 use C4::Koha;
25
26 sub GetByCode {
27     my ( $self, $category, $code, $opac ) = @_;
28     my $av = Koha::AuthorisedValues->search({ category => $category, authorised_value => $code });
29     return $av->count
30             ? $opac
31                 ? $av->next->opac_description
32                 : $av->next->lib
33             : '';
34 }
35
36 sub Get {
37     my ( $self, $category, $opac ) = @_;
38     return GetAuthorisedValues( $category, $opac );
39 }
40
41 sub GetAuthValueDropbox {
42     my ( $self, $category, $default ) = @_;
43     return C4::Koha::GetAuthvalueDropbox($category, $default);
44 }
45
46 1;
47
48 =head1 NAME
49
50 Koha::Template::Plugin::AuthorisedValues - TT Plugin for authorised values
51
52 =head1 SYNOPSIS
53
54 [% USE AuthorisedValues %]
55
56 [% AuthorisedValues.GetByCode( 'CATEGORY', 'AUTHORISED_VALUE_CODE', 'IS_OPAC' ) %]
57
58 [% AuthorisedValues.GetAuthValueDropbox( $category, $default ) %]
59
60 =head1 ROUTINES
61
62 =head2 GetByCode
63
64 In a template, you can get the description for an authorised value with
65 the following TT code: [% AuthorisedValues.GetByCode( 'CATEGORY', 'AUTHORISED_VALUE_CODE', 'IS_OPAC' ) %]
66
67 =head2 GetAuthValueDropbox
68
69 The parameters are identical to those used by the subroutine C4::Koha::GetAuthValueDropbox
70
71 =head1 AUTHOR
72
73 Kyle M Hall <kyle@bywatersolutions.com>
74
75 Jonathan Druart <jonathan.druart@biblibre.com>
76
77 =cut