1 package Koha::Template::Plugin::AuthorisedValues;
3 # Copyright 2012 ByWater Solutions
4 # Copyright 2013-2014 BibLibre
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.
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.
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>.
22 use base qw( Template::Plugin );
25 use Koha::AuthorisedValues;
28 my ( $self, $category, $code, $opac ) = @_;
29 my $av = Koha::AuthorisedValues->search({ category => $category, authorised_value => $code });
32 ? $av->next->opac_description
38 my ( $self, $category, $selected, $opac ) = @_;
39 return GetAuthorisedValues( $category, $selected, $opac );
42 sub GetAuthValueDropbox {
43 my ( $self, $category ) = @_;
44 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
45 return Koha::AuthorisedValues->search(
47 branchcode => $branch_limit,
48 category => $category,
51 order_by => [ 'category', 'lib', 'lib_opac' ],
57 my ( $self, $params ) = @_;
58 my $selected = $params->{selected};
59 my @categories = Koha::AuthorisedValues->new->categories;
64 ( ( $selected and $selected eq $_ ) ? ( selected => 1 ) : () ),
70 sub GetDescriptionsByKohaField {
71 my ( $self, $params ) = @_;
72 return Koha::AuthorisedValues->get_descriptions_by_koha_field(
73 { kohafield => $params->{kohafield} } );
76 sub GetDescriptionByKohaField {
77 my ( $self, $params ) = @_;
78 my $av = Koha::AuthorisedValues->get_description_by_koha_field(
80 kohafield => $params->{kohafield},
81 authorised_value => $params->{authorised_value},
86 ? $av->{opac_description}
88 : ''; # Maybe we should return $params->{authorised_value}?
96 Koha::Template::Plugin::AuthorisedValues - TT Plugin for authorised values
100 [% USE AuthorisedValues %]
102 [% AuthorisedValues.GetByCode( 'CATEGORY', 'AUTHORISED_VALUE_CODE', 'IS_OPAC' ) %]
104 [% AuthorisedValues.GetAuthValueDropbox( $category, $default ) %]
110 In a template, you can get the description for an authorised value with
111 the following TT code: [% AuthorisedValues.GetByCode( 'CATEGORY', 'AUTHORISED_VALUE_CODE', 'IS_OPAC' ) %]
113 =head2 GetAuthValueDropbox
115 The parameters are identical to those used by the subroutine C4::Koha::GetAuthValueDropbox
117 =head2 GetDescriptionsByKohaField
119 The parameters are identical to those used by the subroutine Koha::AuthorisedValues->get_descriptions_by_koha_field
121 =head2 GetDescriptionByKohaField
123 The parameters are identical to those used by the subroutine Koha::AuthorisedValues->get_description_by_koha_field
127 Kyle M Hall <kyle@bywatersolutions.com>
129 Jonathan Druart <jonathan.druart@biblibre.com>