Lines 691-699
sub GetPreparedLetter {
Link Here
|
691 |
|
691 |
|
692 |
my $tables = $params{tables} || {}; |
692 |
my $tables = $params{tables} || {}; |
693 |
my $substitute = $params{substitute} || {}; |
693 |
my $substitute = $params{substitute} || {}; |
|
|
694 |
my $loops = $params{loops} || {}; # loops is not supported for history syntax |
694 |
my $repeat = $params{repeat}; |
695 |
my $repeat = $params{repeat}; |
695 |
%$tables || %$substitute || $repeat |
696 |
%$tables || %$substitute || $repeat || %$loops |
696 |
or carp( "ERROR: nothing to substitute - both 'tables' and 'substitute' are empty" ), |
697 |
or carp( "ERROR: nothing to substitute - both 'tables', 'loops' and 'substitute' are empty" ), |
697 |
return; |
698 |
return; |
698 |
my $want_librarian = $params{want_librarian}; |
699 |
my $want_librarian = $params{want_librarian}; |
699 |
|
700 |
|
Lines 770-775
sub GetPreparedLetter {
Link Here
|
770 |
{ |
771 |
{ |
771 |
content => $letter->{content}, |
772 |
content => $letter->{content}, |
772 |
tables => $tables, |
773 |
tables => $tables, |
|
|
774 |
loops => $loops, |
773 |
} |
775 |
} |
774 |
); |
776 |
); |
775 |
|
777 |
|
Lines 1440-1445
sub _process_tt {
Link Here
|
1440 |
|
1442 |
|
1441 |
my $content = $params->{content}; |
1443 |
my $content = $params->{content}; |
1442 |
my $tables = $params->{tables}; |
1444 |
my $tables = $params->{tables}; |
|
|
1445 |
my $loops = $params->{loops}; |
1443 |
|
1446 |
|
1444 |
my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; |
1447 |
my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; |
1445 |
my $template = Template->new( |
1448 |
my $template = Template->new( |
Lines 1454-1460
sub _process_tt {
Link Here
|
1454 |
} |
1457 |
} |
1455 |
) or die Template->error(); |
1458 |
) or die Template->error(); |
1456 |
|
1459 |
|
1457 |
my $tt_params = _get_tt_params( $tables ); |
1460 |
my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) } }; |
1458 |
|
1461 |
|
1459 |
my $output; |
1462 |
my $output; |
1460 |
$template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error(); |
1463 |
$template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error(); |
Lines 1463-1471
sub _process_tt {
Link Here
|
1463 |
} |
1466 |
} |
1464 |
|
1467 |
|
1465 |
sub _get_tt_params { |
1468 |
sub _get_tt_params { |
1466 |
my ($tables) = @_; |
1469 |
my ($tables, $is_a_loop) = @_; |
1467 |
|
1470 |
|
1468 |
my $params; |
1471 |
my $params; |
|
|
1472 |
$is_a_loop ||= 0; |
1469 |
|
1473 |
|
1470 |
my $config = { |
1474 |
my $config = { |
1471 |
biblio => { |
1475 |
biblio => { |
Lines 1552-1558
sub _get_tt_params {
Link Here
|
1552 |
my $pk = $config->{$table}->{pk}; |
1556 |
my $pk = $config->{$table}->{pk}; |
1553 |
my $fk = $config->{$table}->{fk}; |
1557 |
my $fk = $config->{$table}->{fk}; |
1554 |
|
1558 |
|
1555 |
if ( $ref eq q{} || $ref eq 'HASH' ) { |
1559 |
if ( $is_a_loop ) { |
|
|
1560 |
unless ( ref( $tables->{$table} ) eq 'ARRAY' ) { |
1561 |
croak "ERROR processing table $table. Wrong API call."; |
1562 |
} |
1563 |
my $objects = $module->search( { $pk => { -in => $tables->{$table} } } ); |
1564 |
$params->{ $config->{$table}->{plural} } = $objects; |
1565 |
} |
1566 |
elsif ( $ref eq q{} || $ref eq 'HASH' ) { |
1556 |
my $id = ref $ref eq 'HASH' ? $tables->{$table}->{$pk} : $tables->{$table}; |
1567 |
my $id = ref $ref eq 'HASH' ? $tables->{$table}->{$pk} : $tables->{$table}; |
1557 |
my $object; |
1568 |
my $object; |
1558 |
if ( $fk ) { # Using a foreign key for lookup |
1569 |
if ( $fk ) { # Using a foreign key for lookup |