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

(-)a/C4/Letters.pm (-13 / +18 lines)
Lines 637-648 sub GetPreparedLetter { Link Here
637
        $letter->{'content-type'} = 'text/html; charset="UTF-8"' if $letter->{is_html};
637
        $letter->{'content-type'} = 'text/html; charset="UTF-8"' if $letter->{is_html};
638
    }
638
    }
639
639
640
    my $objects = $params{objects} || {};
640
    my $tables = $params{tables} || {};
641
    my $tables = $params{tables} || {};
641
    my $substitute = $params{substitute} || {};
642
    my $substitute = $params{substitute} || {};
642
    my $loops  = $params{loops} || {}; # loops is not supported for historical notices syntax
643
    my $loops  = $params{loops} || {}; # loops is not supported for historical notices syntax
643
    my $repeat = $params{repeat};
644
    my $repeat = $params{repeat};
644
    %$tables || %$substitute || $repeat || %$loops
645
    %$tables || %$substitute || $repeat || %$loops || %$objects
645
      or carp( "ERROR: nothing to substitute - both 'tables', 'loops' and 'substitute' are empty" ),
646
      or carp( "ERROR: nothing to substitute - all of 'objects', 'tables', 'loops' and 'substitute' are empty" ),
646
         return;
647
         return;
647
    my $want_librarian = $params{want_librarian};
648
    my $want_librarian = $params{want_librarian};
648
649
Lines 717-736 sub GetPreparedLetter { Link Here
717
718
718
    $letter->{content} = _process_tt(
719
    $letter->{content} = _process_tt(
719
        {
720
        {
720
            content => $letter->{content},
721
            content    => $letter->{content},
721
            tables  => $tables,
722
            lang       => $lang,
722
            loops  => $loops,
723
            loops      => $loops,
724
            objects    => $objects,
723
            substitute => $substitute,
725
            substitute => $substitute,
724
            lang => $lang
726
            tables     => $tables,
725
        }
727
        }
726
    );
728
    );
727
729
728
    $letter->{title} = _process_tt(
730
    $letter->{title} = _process_tt(
729
        {
731
        {
730
            content => $letter->{title},
732
            content    => $letter->{title},
731
            tables  => $tables,
733
            lang       => $lang,
732
            loops  => $loops,
734
            loops      => $loops,
735
            objects    => $objects,
733
            substitute => $substitute,
736
            substitute => $substitute,
737
            tables     => $tables,
734
        }
738
        }
735
    );
739
    );
736
740
Lines 1552-1560 sub _set_message_status { Link Here
1552
sub _process_tt {
1556
sub _process_tt {
1553
    my ( $params ) = @_;
1557
    my ( $params ) = @_;
1554
1558
1555
    my $content = $params->{content};
1559
    my $content    = $params->{content};
1556
    my $tables = $params->{tables};
1560
    my $tables     = $params->{tables};
1557
    my $loops = $params->{loops};
1561
    my $loops      = $params->{loops};
1562
    my $objects    = $params->{objects};
1558
    my $substitute = $params->{substitute} || {};
1563
    my $substitute = $params->{substitute} || {};
1559
    my $lang = defined($params->{lang}) && $params->{lang} ne 'default' ? $params->{lang} : 'en';
1564
    my $lang = defined($params->{lang}) && $params->{lang} ne 'default' ? $params->{lang} : 'en';
1560
    my ($theme, $availablethemes);
1565
    my ($theme, $availablethemes);
Lines 1581-1587 sub _process_tt { Link Here
1581
        }
1586
        }
1582
    ) or die Template->error();
1587
    ) or die Template->error();
1583
1588
1584
    my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute };
1589
    my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute, %$objects };
1585
1590
1586
    $content = add_tt_filters( $content );
1591
    $content = add_tt_filters( $content );
1587
    $content = qq|[% USE KohaDates %][% USE Remove_MARC_punctuation %]$content|;
1592
    $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