Bug 36815: Add 'get_default' method to Koha::Notice::Template

This patch adds a new 'get_default' method to the Koha::Notice::Template
object.  The idea is that it returns the template content as defined by
the sample_notices.yml file for the language of your choosing.

Signed-off-by: Emily Lamancusa <emily.lamancusa@montgomerycountymd.gov>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Martin Renvoize 2024-05-08 16:19:26 +01:00 committed by Katrin Fischer
parent 2013ea70ec
commit 217898cbb7
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834

View file

@ -17,7 +17,9 @@ package Koha::Notice::Template;
use Modern::Perl; use Modern::Perl;
use YAML::XS qw(LoadFile);
use C4::Context;
use Koha::Database; use Koha::Database;
use base qw(Koha::Object); use base qw(Koha::Object);
@ -30,8 +32,57 @@ Koha::Notice::Template - Koha notice template Object class, related to the lette
=head2 Class Methods =head2 Class Methods
=head3 get_default
my $default = $template->get_default;
Returns the default notice template content.
=cut =cut
sub get_default {
my $self = shift;
my $lang = $self->lang;
my $defaulted_to_en = 0;
my $file = C4::Context->config('intranetdir') . "/installer/data/mysql/$lang/mandatory/sample_notices.yml";
if ( !-e $file ) {
if ( $lang eq 'en' ) {
warn "cannot open sample data $file";
} else {
# if no localised sample data is available,
# default to English
$file = C4::Context->config('intranetdir') . "/installer/data/mysql/en/mandatory/sample_notices.yml";
die "cannot open English sample data directory $file" unless ( -e $file );
$defaulted_to_en = 1;
}
}
my $data = YAML::XS::LoadFile("$file");
my $module = $self->module;
my $code = $self->code;
my $mtt = $self->message_transport_type;
my $content;
for my $table ( @{ $data->{tables} } ) {
if ( $table->{letter}->{rows} ) {
for my $template ( @{ $table->{letter}->{rows} } ) {
if ( $template->{module} eq $module
&& $template->{code} eq $code
&& $template->{message_transport_type} eq $mtt )
{
$content = join "\r\n", @{ $template->{content} };
last;
}
}
}
}
return $content;
}
=head3 type =head3 type
=cut =cut