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 1546-1552
sub _get_tt_params {
Link Here
|
1546 |
my $pk = $config->{$table}->{pk}; |
1550 |
my $pk = $config->{$table}->{pk}; |
1547 |
my $fk = $config->{$table}->{fk}; |
1551 |
my $fk = $config->{$table}->{fk}; |
1548 |
|
1552 |
|
1549 |
if ( $ref eq q{} || $ref eq 'HASH' ) { |
1553 |
if ( $is_a_loop ) { |
|
|
1554 |
unless ( ref( $tables->{$table} ) eq 'ARRAY' ) { |
1555 |
croak "ERROR processing table $table. Wrong API call."; |
1556 |
} |
1557 |
my $objects = $module->search( { $pk => { -in => $tables->{$table} } } ); |
1558 |
$params->{ $config->{$table}->{plural} } = $objects; |
1559 |
} |
1560 |
elsif ( $ref eq q{} || $ref eq 'HASH' ) { |
1550 |
my $id = ref $ref eq 'HASH' ? $tables->{$table}->{$pk} : $tables->{$table}; |
1561 |
my $id = ref $ref eq 'HASH' ? $tables->{$table}->{$pk} : $tables->{$table}; |
1551 |
my $object; |
1562 |
my $object; |
1552 |
if ( $fk ) { # Using a foreign key for lookup |
1563 |
if ( $fk ) { # Using a foreign key for lookup |