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

(-)a/C4/Letters.pm (-13 / +18 lines)
Lines 638-649 sub GetPreparedLetter { Link Here
638
        $letter->{'content-type'} = 'text/html; charset="UTF-8"' if $letter->{is_html};
638
        $letter->{'content-type'} = 'text/html; charset="UTF-8"' if $letter->{is_html};
639
    }
639
    }
640
640
641
    my $objects = $params{objects} || {};
641
    my $tables = $params{tables} || {};
642
    my $tables = $params{tables} || {};
642
    my $substitute = $params{substitute} || {};
643
    my $substitute = $params{substitute} || {};
643
    my $loops  = $params{loops} || {}; # loops is not supported for historical notices syntax
644
    my $loops  = $params{loops} || {}; # loops is not supported for historical notices syntax
644
    my $repeat = $params{repeat};
645
    my $repeat = $params{repeat};
645
    %$tables || %$substitute || $repeat || %$loops
646
    %$tables || %$substitute || $repeat || %$loops || %$objects
646
      or carp( "ERROR: nothing to substitute - both 'tables', 'loops' and 'substitute' are empty" ),
647
      or carp( "ERROR: nothing to substitute - all of 'objects', 'tables', 'loops' and 'substitute' are empty" ),
647
         return;
648
         return;
648
    my $want_librarian = $params{want_librarian};
649
    my $want_librarian = $params{want_librarian};
649
650
Lines 718-737 sub GetPreparedLetter { Link Here
718
719
719
    $letter->{content} = _process_tt(
720
    $letter->{content} = _process_tt(
720
        {
721
        {
721
            content => $letter->{content},
722
            content    => $letter->{content},
722
            tables  => $tables,
723
            lang       => $lang,
723
            loops  => $loops,
724
            loops      => $loops,
725
            objects    => $objects,
724
            substitute => $substitute,
726
            substitute => $substitute,
725
            lang => $lang
727
            tables     => $tables,
726
        }
728
        }
727
    );
729
    );
728
730
729
    $letter->{title} = _process_tt(
731
    $letter->{title} = _process_tt(
730
        {
732
        {
731
            content => $letter->{title},
733
            content    => $letter->{title},
732
            tables  => $tables,
734
            lang       => $lang,
733
            loops  => $loops,
735
            loops      => $loops,
736
            objects    => $objects,
734
            substitute => $substitute,
737
            substitute => $substitute,
738
            tables     => $tables,
735
        }
739
        }
736
    );
740
    );
737
741
Lines 1616-1624 sub _set_message_status { Link Here
1616
sub _process_tt {
1620
sub _process_tt {
1617
    my ( $params ) = @_;
1621
    my ( $params ) = @_;
1618
1622
1619
    my $content = $params->{content};
1623
    my $content    = $params->{content};
1620
    my $tables = $params->{tables};
1624
    my $tables     = $params->{tables};
1621
    my $loops = $params->{loops};
1625
    my $loops      = $params->{loops};
1626
    my $objects    = $params->{objects};
1622
    my $substitute = $params->{substitute} || {};
1627
    my $substitute = $params->{substitute} || {};
1623
    my $lang = defined($params->{lang}) && $params->{lang} ne 'default' ? $params->{lang} : 'en';
1628
    my $lang = defined($params->{lang}) && $params->{lang} ne 'default' ? $params->{lang} : 'en';
1624
    my ($theme, $availablethemes);
1629
    my ($theme, $availablethemes);
Lines 1645-1651 sub _process_tt { Link Here
1645
        }
1650
        }
1646
    ) or die Template->error();
1651
    ) or die Template->error();
1647
1652
1648
    my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute };
1653
    my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute, %$objects };
1649
1654
1650
    $content = add_tt_filters( $content );
1655
    $content = add_tt_filters( $content );
1651
    $content = qq|[% USE KohaDates %][% USE Remove_MARC_punctuation %]$content|;
1656
    $content = qq|[% USE KohaDates %][% USE Remove_MARC_punctuation %]$content|;
(-)a/t/db_dependent/Letters/TemplateToolkit.t (-2 / +13 lines)
Lines 19-25 Link Here
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
20
21
use Modern::Perl;
21
use Modern::Perl;
22
use Test::More tests => 28;
22
use Test::More tests => 29;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 44-49 use Koha::Serial; Link Here
44
use Koha::Subscription;
44
use Koha::Subscription;
45
use Koha::Suggestion;
45
use Koha::Suggestion;
46
use Koha::Checkout;
46
use Koha::Checkout;
47
use Koha::Patrons;
47
use Koha::Notice::Messages;
48
use Koha::Notice::Messages;
48
use Koha::Notice::Templates;
49
use Koha::Notice::Templates;
49
use Koha::Patron::Modification;
50
use Koha::Patron::Modification;
Lines 139-144 $prepared_letter = GetPreparedLetter( Link Here
139
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with arrayref for content' );
140
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with arrayref for content' );
140
is( $prepared_letter->{title}, $patron->{firstname}, 'Patron object used correctly with arrayref for title' );
141
is( $prepared_letter->{title}, $patron->{firstname}, 'Patron object used correctly with arrayref for title' );
141
142
143
$prepared_letter = GetPreparedLetter(
144
    (
145
        module      => 'test',
146
        letter_code => 'TEST_PATRON',
147
        objects      => {
148
            borrower => scalar Koha::Patrons->find( $patron->{borrowernumber} ),
149
        },
150
    )
151
);
152
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly as object' );
153
142
$sth->execute( "TEST_BIBLIO", "[% biblio.title %]", "[% biblio.id %]" );
154
$sth->execute( "TEST_BIBLIO", "[% biblio.title %]", "[% biblio.id %]" );
143
$prepared_letter = GetPreparedLetter(
155
$prepared_letter = GetPreparedLetter(
144
    (
156
    (
145
- 

Return to bug 19966