1 package Koha::Notice::Templates;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use Koha::Notice::Template;
26 use base qw(Koha::Objects);
30 Koha::Notice::Templates - Koha notice template Object set class, related to the letter table
40 my $template = Koha::Notice::Templates->find_effective_template(
44 branchcode => $branchcode,
49 Return the notice template that must be used for a given primary key (module, code, branchcode, lang).
51 For instance if lang="es-ES" but there is no "es-ES" template defined for this language,
52 the default template will be returned.
54 lang will default to "default" if not passed.
58 sub find_effective_template {
59 my ( $self, $params ) = @_;
61 $params = { %$params }; # don't modify original
63 $params->{lang} = 'default'
64 unless C4::Context->preference('TranslateNotices') && $params->{lang};
66 my $only_my_library = C4::Context->only_my_library;
67 if ( $only_my_library and $params->{branchcode} ) {
68 $params->{branchcode} = C4::Context::mybranch();
70 $params->{branchcode} //= '';
71 $params->{branchcode} = [$params->{branchcode}, ''];
73 my $template = $self->SUPER::search( $params, { order_by => { -desc => 'branchcode' } } );
75 if ( !$template->count
76 && C4::Context->preference('TranslateNotices')
77 && $params->{lang} ne 'default' )
79 $params->{lang} = 'default';
80 $template = $self->SUPER::search( $params, { order_by => { -desc => 'branchcode' } } );
83 return $template->next if $template->count;
95 return 'Koha::Notice::Template';