Bug 13758: Move the Koha version from kohaversion.pl
[koha.git] / Koha / Template / Plugin / Koha.pm
1 package Koha::Template::Plugin::Koha;
2
3 # Copyright ByWater Solutions 2013
4
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21 use Encode qw( encode );
22
23 use base qw( Template::Plugin );
24
25 use C4::Context;
26 use Koha;
27
28 =pod
29
30 This plugin contains various Koha replated Template Toolkit functions
31 to help streamline Koha and to move logic from the Perl code into the
32 Templates when it makes sense to do so.
33
34 To use, first, include the line '[% USE Koha %]' at the top
35 of the template to enable the plugin.
36
37 For example: [% IF Koha.Preference( 'MyPreference ) == 'SettingA' %]
38 removes the necessity of setting a template variable in Perl code for
39 each and every system preference, even if no evaluation of the setting
40 is necessary.
41
42 =cut
43
44 sub Preference {
45     my ( $self, $pref ) = @_;
46     return encode('UTF-8', C4::Context->preference( $pref ) );
47 }
48
49 sub Version {
50     my $version_string = Koha::version();
51     my ($major,$minor,$maintenance,$development) = split('\.',$version_string);
52
53     return {
54         major       => $major,
55         release     => $major . "." . $minor,
56         maintenance => $major . "." . $minor . "." . $maintenance,
57         development => ( $development ne '000' )
58                             ? $development
59                             : undef
60     };
61 }
62
63 1;