Bug 20415: Add POD
[koha-equinox.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
22 use base qw( Template::Plugin );
23
24 use C4::Context;
25 use Koha;
26
27 =head1 NAME
28
29 Koha::Template::Plugin::Koha - General Koha Template Toolkit plugin
30
31 =head1 SYNOPSIS
32
33 This plugin contains various Koha replated Template Toolkit functions
34 to help streamline Koha and to move logic from the Perl code into the
35 Templates when it makes sense to do so.
36
37 To use, first, include the line '[% USE Koha %]' at the top
38 of the template to enable the plugin.
39
40 For example: [% IF Koha.Preference( 'MyPreference ) == 'SettingA' %]
41 removes the necessity of setting a template variable in Perl code for
42 each and every system preference, even if no evaluation of the setting
43 is necessary.
44
45 =cut
46
47 =head1 API
48
49 =head2 Class Methods
50
51 =cut
52
53 sub Preference {
54     my ( $self, $pref ) = @_;
55     return C4::Context->preference( $pref );
56 }
57
58 sub Version {
59     my $version_string = Koha::version();
60     my ( $major, $minor, $maintenance, $development ) = split( '\.', $version_string );
61
62     return {
63         major       => $major,
64         minor       => $minor,
65         release     => $major . "." . $minor,
66         maintenance => $major . "." . $minor . "." . $maintenance,
67         development => ( $development ne '000' ) ? $development : undef,
68     };
69 }
70
71 =head3 ArePluginsEnabled
72
73 Returns true if plugins are enabled, false otherwise.
74
75 =cut
76
77 sub ArePluginsEnabled {
78     return C4::Context->config('enable_plugins');
79 }
80
81 1;