Bug 11431: Add additional sound options
[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 use JSON;
23
24 use base qw( Template::Plugin );
25
26 use C4::Context;
27 use Koha;
28
29 =pod
30
31 This plugin contains various Koha replated Template Toolkit functions
32 to help streamline Koha and to move logic from the Perl code into the
33 Templates when it makes sense to do so.
34
35 To use, first, include the line '[% USE Koha %]' at the top
36 of the template to enable the plugin.
37
38 For example: [% IF Koha.Preference( 'MyPreference ) == 'SettingA' %]
39 removes the necessity of setting a template variable in Perl code for
40 each and every system preference, even if no evaluation of the setting
41 is necessary.
42
43 =cut
44
45 sub Preference {
46     my ( $self, $pref ) = @_;
47     return C4::Context->preference( $pref );
48 }
49
50 sub Version {
51     my $version_string = Koha::version();
52     my ( $major, $minor, $maintenance, $development ) = split( '\.', $version_string );
53
54     return {
55         major       => $major,
56         release     => $major . "." . $minor,
57         maintenance => $major . "." . $minor . "." . $maintenance,
58         development => ( $development ne '000' ) ? $development : undef,
59     };
60 }
61
62 sub AudioAlerts {
63     my $dbh = C4::Context->dbh;
64     my $audio_alerts = $dbh->selectall_arrayref( 'SELECT * FROM audio_alerts ORDER BY precedence', { Slice => {} } );
65     return encode_json($audio_alerts);
66 }
67
68 1;