|
Lines 17-23
package Koha::Notice::Template;
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
|
|
20 |
use YAML::XS qw(LoadFile); |
| 20 |
|
21 |
|
|
|
22 |
use C4::Context; |
| 21 |
use Koha::Database; |
23 |
use Koha::Database; |
| 22 |
|
24 |
|
| 23 |
use base qw(Koha::Object); |
25 |
use base qw(Koha::Object); |
|
Lines 30-37
Koha::Notice::Template - Koha notice template Object class, related to the lette
Link Here
|
| 30 |
|
32 |
|
| 31 |
=head2 Class Methods |
33 |
=head2 Class Methods |
| 32 |
|
34 |
|
|
|
35 |
=head3 get_default |
| 36 |
|
| 37 |
my $default = $template->get_default; |
| 38 |
|
| 39 |
Returns the default notice template content. |
| 40 |
|
| 33 |
=cut |
41 |
=cut |
| 34 |
|
42 |
|
|
|
43 |
sub get_default { |
| 44 |
my $self = shift; |
| 45 |
my $lang = $self->lang; |
| 46 |
my $defaulted_to_en = 0; |
| 47 |
|
| 48 |
my $file = C4::Context->config('intranetdir') . "/installer/data/mysql/$lang/mandatory/sample_notices.yml"; |
| 49 |
if ( !-e $file ) { |
| 50 |
if ( $lang eq 'en' ) { |
| 51 |
warn "cannot open sample data $file"; |
| 52 |
} else { |
| 53 |
|
| 54 |
# if no localised sample data is available, |
| 55 |
# default to English |
| 56 |
$file = C4::Context->config('intranetdir') . "/installer/data/mysql/en/mandatory/sample_notices.yml"; |
| 57 |
die "cannot open English sample data directory $file" unless ( -e $file ); |
| 58 |
$defaulted_to_en = 1; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
my $data = YAML::XS::LoadFile("$file"); |
| 63 |
|
| 64 |
my $module = $self->module; |
| 65 |
my $code = $self->code; |
| 66 |
my $mtt = $self->message_transport_type; |
| 67 |
|
| 68 |
my $content; |
| 69 |
for my $table ( @{ $data->{tables} } ) { |
| 70 |
if ( $table->{letter}->{rows} ) { |
| 71 |
for my $template ( @{ $table->{letter}->{rows} } ) { |
| 72 |
if ( $template->{module} eq $module |
| 73 |
&& $template->{code} eq $code |
| 74 |
&& $template->{message_transport_type} eq $mtt ) |
| 75 |
{ |
| 76 |
$content = join "\r\n", @{ $template->{content} }; |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
return $content; |
| 83 |
} |
| 84 |
|
| 35 |
=head3 type |
85 |
=head3 type |
| 36 |
|
86 |
|
| 37 |
=cut |
87 |
=cut |
| 38 |
- |
|
|