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>.
23 use Koha::Notice::Template;
25 use base qw(Koha::Objects);
29 Koha::Notice::Templates - Koha notice template Object set class, related to the letter table
39 my $template = Koha::Notice::Templates->find_effective_template(
43 branchcode => $branchcode,
48 Return the notice template that must be used for a given primary key (module, code, branchcode, lang).
50 For instance if lang="es-ES" but there is no "es-ES" template defined for this language,
51 the default template will be returned.
53 lang will default to "default" if not passed.
57 sub find_effective_template {
58 my ( $self, $params ) = @_;
60 $params = { %$params }; # don't modify original
62 $params->{lang} = 'default'
63 unless C4::Context->preference('TranslateNotices') && $params->{lang};
65 my $only_my_library = C4::Context->only_my_library;
66 if ( $only_my_library and $params->{branchcode} ) {
67 $params->{branchcode} = C4::Context::mybranch();
69 $params->{branchcode} //= '';
70 $params->{branchcode} = [$params->{branchcode}, ''];
72 my $template = $self->SUPER::search( $params, { order_by => { -desc => 'branchcode' } } );
74 if ( !$template->count
75 && C4::Context->preference('TranslateNotices')
76 && $params->{lang} ne 'default' )
78 $params->{lang} = 'default';
79 $template = $self->SUPER::search( $params, { order_by => { -desc => 'branchcode' } } );
82 return $template->next if $template->count;
94 return 'Koha::Notice::Template';