Bugzilla – Attachment 59427 Details for
Bug 17971
TT syntax for notices - Add support for plurals
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17971: Add support for objects represented by fk
Bug-17971-Add-support-for-objects-represented-by-f.patch (text/plain), 3.02 KB, created by
Jonathan Druart
on 2017-01-23 15:05:21 UTC
(
hide
)
Description:
Bug 17971: Add support for objects represented by fk
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-01-23 15:05:21 UTC
Size:
3.02 KB
patch
obsolete
>From b8b718d6f1160b76225b7af67677f6068ea7f51a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 17 Jan 2017 16:18:54 +0100 >Subject: [PATCH] Bug 17971: Add support for objects represented by fk > >For instance an issue is not fetch from its fk but using the fk >itemnumber. >We need to support them. >--- > C4/Letters.pm | 6 ++++-- > t/db_dependent/Letters/TemplateToolkit.t | 16 +++++++++++++++- > 2 files changed, 19 insertions(+), 3 deletions(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index cbcdbb1..30b81b9 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -1551,10 +1551,12 @@ sub _get_tt_params { > my $fk = $config->{$table}->{fk}; > > if ( $is_a_loop ) { >- unless ( ref( $tables->{$table} ) eq 'ARRAY' ) { >+ my $values = $tables->{$table} || []; >+ unless ( ref( $values ) eq 'ARRAY' ) { > croak "ERROR processing table $table. Wrong API call."; > } >- my $objects = $module->search( { $pk => { -in => $tables->{$table} } } ); >+ my $key = $pk ? $pk : $fk; >+ my $objects = $module->search( { $key => { -in => $values } } ); > $params->{ $config->{$table}->{plural} } = $objects; > } > elsif ( $ref eq q{} || $ref eq 'HASH' ) { >diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t >index 5c24b49..4329933 100644 >--- a/t/db_dependent/Letters/TemplateToolkit.t >+++ b/t/db_dependent/Letters/TemplateToolkit.t >@@ -283,7 +283,7 @@ $prepared_letter = GetPreparedLetter( > is( $prepared_letter->{content}, $modification->id(), 'Patron modification object used correctly' ); > > subtest 'loops' => sub { >- plan tests => 1; >+ plan tests => 2; > my $code = "TEST"; > my $module = "TEST"; > >@@ -298,6 +298,20 @@ subtest 'loops' => sub { > my $expected_letter = join '', ( $patron_1->{surname}, $patron_2->{surname} ); > is( $letter->{content}, $expected_letter, ); > }; >+ >+ subtest 'foreign key is used' => sub { >+ plan tests => 1; >+ my $patron_1 = $builder->build({ source => 'Borrower' }); >+ my $patron_2 = $builder->build({ source => 'Borrower' }); >+ my $checkout_1 = $builder->build({ source => 'Issue', value => { borrowernumber => $patron_1->{borrowernumber} } } ); >+ my $checkout_2 = $builder->build({ source => 'Issue', value => { borrowernumber => $patron_1->{borrowernumber} } } ); >+ >+ my $template = q|[% FOREACH checkout IN checkouts %][% checkout.issue_id %][% END %]|; >+ reset_template( { template => $template, code => $code, module => $module } ); >+ my $letter = GetPreparedLetter( module => $module, letter_code => $code, loops => { issues => [ $checkout_1->{itemnumber}, $checkout_2->{itemnumber} ] } ); >+ my $expected_letter = join '', ( $checkout_1->{issue_id}, $checkout_2->{issue_id} ); >+ is( $letter->{content}, $expected_letter, ); >+ }; > }; > > sub reset_template { >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17971
:
59426
|
59427
|
59529
|
59530
|
60987
|
60988
|
61710
|
61711
|
61712