View | Details | Raw Unified | Return to bug 23765
Collapse All | Expand All

(-)a/C4/Letters.pm (-13 / +13 lines)
Lines 37-42 use Koha::SMS::Providers; Link Here
37
37
38
use Koha::Email;
38
use Koha::Email;
39
use Koha::Notice::Messages;
39
use Koha::Notice::Messages;
40
use Koha::Notice::Templates;
40
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
41
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
41
use Koha::Patrons;
42
use Koha::Patrons;
42
use Koha::Subscriptions;
43
use Koha::Subscriptions;
Lines 122-140 sub GetLetterTemplates { Link Here
122
    my $code      = $params->{code};
123
    my $code      = $params->{code};
123
    my $branchcode = $params->{branchcode} // '';
124
    my $branchcode = $params->{branchcode} // '';
124
    my $dbh       = C4::Context->dbh;
125
    my $dbh       = C4::Context->dbh;
125
    my $letters   = $dbh->selectall_arrayref(
126
    return Koha::Notice::Templates->search(
126
        q|
127
        {
127
            SELECT module, code, branchcode, name, is_html, title, content, message_transport_type, lang
128
            module     => $module,
128
            FROM letter
129
            code       => $code,
129
            WHERE module = ?
130
            branchcode => $branchcode,
130
            AND code = ?
131
            (
131
            and branchcode = ?
132
                C4::Context->preference('TranslateNotices')
132
        |
133
                ? ()
133
        , { Slice => {} }
134
                : ( lang => 'default' )
134
        , $module, $code, $branchcode
135
            )
135
    );
136
        }
136
137
    )->unblessed;
137
    return $letters;
138
}
138
}
139
139
140
=head2 GetLettersAvailableForALibrary
140
=head2 GetLettersAvailableForALibrary
(-)a/t/db_dependent/Letters/GetLetterTemplates.t (-14 / +18 lines)
Lines 1-9 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
use Test::More tests => 7;
2
use Test::More tests => 8;
3
3
4
use C4::Context;
4
use C4::Context;
5
use C4::Letters qw( GetLetterTemplates );
5
use C4::Letters qw( GetLetterTemplates );
6
use Koha::Database;
6
use Koha::Database;
7
use t::lib::Mocks;
7
8
8
my $schema = Koha::Database->new->schema;
9
my $schema = Koha::Database->new->schema;
9
$schema->storage->txn_begin;
10
$schema->storage->txn_begin;
Lines 21-26 my $letters = [ Link Here
21
        title                  => 'default title for code1 email',
22
        title                  => 'default title for code1 email',
22
        content                => 'default content for code1 email',
23
        content                => 'default content for code1 email',
23
        message_transport_type => 'email',
24
        message_transport_type => 'email',
25
        lang                   => 'default',
24
    },
26
    },
25
    {
27
    {
26
        module                 => 'circulation',
28
        module                 => 'circulation',
Lines 31-36 my $letters = [ Link Here
31
        title                  => 'default title for code1 sms',
33
        title                  => 'default title for code1 sms',
32
        content                => 'default content for code1 sms',
34
        content                => 'default content for code1 sms',
33
        message_transport_type => 'sms',
35
        message_transport_type => 'sms',
36
        lang                   => 'es-ES',
34
    },
37
    },
35
    {
38
    {
36
        module                 => 'circulation',
39
        module                 => 'circulation',
Lines 41-46 my $letters = [ Link Here
41
        title                  => 'default title for code2 email',
44
        title                  => 'default title for code2 email',
42
        content                => 'default content for code2 email',
45
        content                => 'default content for code2 email',
43
        message_transport_type => 'email',
46
        message_transport_type => 'email',
47
        lang                   => 'default',
44
    },
48
    },
45
    {
49
    {
46
        module                 => 'circulation',
50
        module                 => 'circulation',
Lines 51-56 my $letters = [ Link Here
51
        title                  => 'default title for code3 email',
55
        title                  => 'default title for code3 email',
52
        content                => 'default content for code3 email',
56
        content                => 'default content for code3 email',
53
        message_transport_type => 'email',
57
        message_transport_type => 'email',
58
        lang                   => 'default',
54
    },
59
    },
55
60
56
    {
61
    {
Lines 62-67 my $letters = [ Link Here
62
        title                  => 'default title for code1 cat email',
67
        title                  => 'default title for code1 cat email',
63
        content                => 'default content for code1 cat email',
68
        content                => 'default content for code1 cat email',
64
        message_transport_type => 'email',
69
        message_transport_type => 'email',
70
        lang                   => 'default',
65
    },
71
    },
66
72
67
    {
73
    {
Lines 73-78 my $letters = [ Link Here
73
        title                  => 'CPL title for code1 email',
79
        title                  => 'CPL title for code1 email',
74
        content                => 'CPL content for code1 email',
80
        content                => 'CPL content for code1 email',
75
        message_transport_type => 'email',
81
        message_transport_type => 'email',
82
        lang                   => 'default',
76
    },
83
    },
77
    {
84
    {
78
        module                 => 'circulation',
85
        module                 => 'circulation',
Lines 83-109 my $letters = [ Link Here
83
        title                  => 'CPL title for code1 sms',
90
        title                  => 'CPL title for code1 sms',
84
        content                => 'CPL content for code1 sms',
91
        content                => 'CPL content for code1 sms',
85
        message_transport_type => 'sms',
92
        message_transport_type => 'sms',
86
    },
93
        lang                   => 'default',
87
    {
88
        module                 => 'circulation',
89
        code                   => 'code1',
90
        branchcode             => 'MPL',
91
        name                   => 'B MPL name for code1 circ',
92
        is_html                => 0,
93
        title                  => 'MPL title for code1 email',
94
        content                => 'MPL content for code1 email',
95
        message_transport_type => 'email',
96
    },
94
    },
97
];
95
];
98
96
99
my $sth = $dbh->prepare(
97
my $sth = $dbh->prepare(
100
q|INSERT INTO letter(module, code, branchcode, name, title, content, message_transport_type) VALUES (?, ?, ?, ?, ?, ?, ?)|
98
q|INSERT INTO letter(module, code, branchcode, name, title, content, message_transport_type, lang) VALUES (?, ?, ?, ?, ?, ?, ?, ?)|
101
);
99
);
102
for my $l (@$letters) {
100
for my $l (@$letters) {
103
    $sth->execute( $l->{module}, $l->{code}, $l->{branchcode}, $l->{name},
101
    $sth->execute( $l->{module}, $l->{code}, $l->{branchcode}, $l->{name},
104
        $l->{title}, $l->{content}, $l->{message_transport_type} );
102
        $l->{title}, $l->{content}, $l->{message_transport_type}, $l->{lang} );
105
}
103
}
106
104
105
t::lib::Mocks::mock_preference('TranslateNotices', 1);
107
my $letter_templates;
106
my $letter_templates;
108
$letter_templates = C4::Letters::GetLetterTemplates;
107
$letter_templates = C4::Letters::GetLetterTemplates;
109
is_deeply( $letter_templates, [],
108
is_deeply( $letter_templates, [],
Lines 129-131 $letter_templates = C4::Letters::GetLetterTemplates( Link Here
129
    { module => 'circulation', code => 'code1' } );
128
    { module => 'circulation', code => 'code1' } );
130
is( scalar( @$letter_templates ),
129
is( scalar( @$letter_templates ),
131
    2, '2 default templates should exist for circulation code1 (even if branchcode is not given)' );
130
    2, '2 default templates should exist for circulation code1 (even if branchcode is not given)' );
132
- 
131
132
t::lib::Mocks::mock_preference('TranslateNotices', 0);
133
$letter_templates = C4::Letters::GetLetterTemplates(
134
    { module => 'circulation', code => 'code1' } );
135
is( scalar( @$letter_templates ),
136
    1, 'There should exist only 1 template circulation code1 for default language' );

Return to bug 23765