1 package Koha::Notice::Template;
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>.
20 use YAML::XS qw(LoadFile);
25 use base qw(Koha::Object);
29 Koha::Notice::Template - Koha notice template Object class, related to the letter table
37 my $default = $template->get_default;
39 Returns the default notice template content.
45 my $lang = $self->lang;
46 if ( $lang eq 'default' ) {
47 my $translated_languages = C4::Languages::getTranslatedLanguages(
49 C4::Context->preference('template')
51 $lang = @{ @{$translated_languages}[0]->{sublanguages_loop} }[0]->{rfc4646_subtag};
54 my $defaulted_to_en = 0;
56 my $file = C4::Context->config('intranetdir') . "/installer/data/mysql/$lang/mandatory/sample_notices.yml";
58 if ( $lang eq 'en' ) {
59 warn "cannot open sample data $file";
62 # if no localised sample data is available,
64 $file = C4::Context->config('intranetdir') . "/installer/data/mysql/en/mandatory/sample_notices.yml";
65 die "cannot open English sample data directory $file" unless ( -e $file );
70 my $data = YAML::XS::LoadFile("$file");
72 my $module = $self->module;
73 my $code = $self->code;
74 my $mtt = $self->message_transport_type;
77 for my $table ( @{ $data->{tables} } ) {
78 if ( $table->{letter}->{rows} ) {
79 for my $template ( @{ $table->{letter}->{rows} } ) {
80 if ( $template->{module} eq $module
81 && $template->{code} eq $code
82 && $template->{message_transport_type} eq $mtt )
84 $content = join "\r\n", @{ $template->{content} };