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

(-)a/C4/SIP/ILS/Item.pm (-1 / +61 lines)
Lines 14-20 use Carp; Link Here
14
use Template;
14
use Template;
15
15
16
use C4::SIP::ILS::Transaction;
16
use C4::SIP::ILS::Transaction;
17
use C4::SIP::Sip qw(add_field);
17
use C4::SIP::Sip qw(add_field maybe_add);
18
18
19
use C4::Biblio;
19
use C4::Biblio;
20
use C4::Circulation qw( barcodedecode );
20
use C4::Circulation qw( barcodedecode );
Lines 429-437 sub build_additional_item_fields_string { Link Here
429
        }
429
        }
430
    }
430
    }
431
431
432
    if ( $server->{account}->{custom_item_field} ) {
433
        my @custom_fields =
434
            ref $server->{account}->{custom_item_field} eq "ARRAY"
435
            ? @{ $server->{account}->{custom_item_field} }
436
            : $server->{account}->{custom_item_field};
437
438
        foreach my $custom_field ( @custom_fields ) {
439
            my $field = $custom_field->{field};
440
            return q{} unless defined $field;
441
            my $template = $custom_field->{template};
442
            my $formatted = $self->format( $template );
443
            my $substring = maybe_add( $field, $formatted, $server );
444
            $string .= $substring;
445
        }
446
    }
447
448
    return $string;
449
}
450
451
=head2 build_custom_field_string
452
453
This method builds the part of the sip message for custom item fields as defined in the sip config
454
455
=cut
456
457
sub build_custom_field_string {
458
    my ( $self, $server ) = @_;
459
460
    my $string = q{};
461
462
432
    return $string;
463
    return $string;
433
}
464
}
434
465
466
=head2 format
467
468
This method uses a template to build a string from a Koha::Item object
469
If errors are encountered in processing template we log them and return nothing
470
471
=cut
472
473
sub format {
474
    my ( $self, $template ) = @_;
475
476
    if ($template) {
477
        require Template;
478
479
        my $tt = Template->new();
480
481
        my $item = $self->{_object};
482
483
        my $output;
484
        eval {
485
            $tt->process( \$template, { item => $item }, \$output );
486
        };
487
        if ( $@ ){
488
            siplog("LOG_DEBUG", "Error processing template: $template");
489
            return "";
490
        }
491
        return $output;
492
    }
493
}
494
435
1;
495
1;
436
__END__
496
__END__
437
497
(-)a/C4/SIP/Sip/MsgType.pm (+1 lines)
Lines 1270-1275 sub handle_item_information { Link Here
1270
        $resp .= maybe_add( FID_PRINT_LINE, $item->print_line, $server );
1270
        $resp .= maybe_add( FID_PRINT_LINE, $item->print_line, $server );
1271
1271
1272
        $resp .= $item->build_additional_item_fields_string( $server );
1272
        $resp .= $item->build_additional_item_fields_string( $server );
1273
        $resp .= $item->build_custom_field_string( $server );
1273
    }
1274
    }
1274
1275
1275
    $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} );
1276
    $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} );
(-)a/etc/SIPconfig.xml (+1 lines)
Lines 86-91 Link Here
86
              <AllFinesNeedOverride>0</AllFinesNeedOverride>
86
              <AllFinesNeedOverride>0</AllFinesNeedOverride>
87
          </syspref_overrides>
87
          </syspref_overrides>
88
          <custom_patron_field field="DE" template="[% patron.dateexpiry %]" />
88
          <custom_patron_field field="DE" template="[% patron.dateexpiry %]" />
89
          <custom_item_field field="IN" template="[% item.itemnumber %]" />
89
      </login>
90
      </login>
90
  </accounts>
91
  </accounts>
91
92
(-)a/t/db_dependent/SIP/Message.t (-2 / +31 lines)
Lines 21-27 Link Here
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
22
22
23
use Modern::Perl;
23
use Modern::Perl;
24
use Test::More tests => 13;
24
use Test::More tests => 14;
25
use Test::Exception;
25
use Test::Exception;
26
use Test::MockObject;
26
use Test::MockObject;
27
use Test::MockModule;
27
use Test::MockModule;
Lines 230-235 subtest "Test build_additional_item_fields_string" => sub { Link Here
230
    $schema->storage->txn_rollback;
230
    $schema->storage->txn_rollback;
231
};
231
};
232
232
233
subtest "Test build_custom_field_string" => sub {
234
    my $schema = Koha::Database->new->schema;
235
    $schema->storage->txn_begin;
236
237
    plan tests => 2;
238
239
    my $builder = t::lib::TestBuilder->new();
240
241
    my $item = $builder->build_sample_item;
242
    my $item_id = $item->id;
243
    my $item_barcode = $item->barcode;
244
    my $ils_item = C4::SIP::ILS::Item->new( $item->barcode );
245
246
    my $server = {};
247
    $server->{account}->{custom_item_field}->{field} = "XY";
248
    $server->{account}->{custom_item_field}->{template} = "[% item.id %] [% item.barcode %], woo!";
249
    my $attribute_string = $ils_item->build_additional_item_fields_string( $server );
250
    is( $attribute_string, "XY$item_id $item_barcode, woo!|", 'Attribute field generated correctly with single param' );
251
252
    $server = {};
253
    $server->{account}->{custom_item_field}->[0]->{field} = "ZY";
254
    $server->{account}->{custom_item_field}->[0]->{template} = "[% item.id %]!";
255
    $server->{account}->{custom_item_field}->[1]->{field} = "ZX";
256
    $server->{account}->{custom_item_field}->[1]->{template} = "[% item.barcode %]*";
257
    $attribute_string = $ils_item->build_additional_item_fields_string( $server );
258
    is( $attribute_string, sprintf("ZY%s!|ZX%s*|", $item_id, $item_barcode), 'Attribute field generated correctly with multiple params' );
259
260
    $schema->storage->txn_rollback;
261
};
262
233
subtest "Test cr_item_field" => sub {
263
subtest "Test cr_item_field" => sub {
234
    plan tests => 2;
264
    plan tests => 2;
235
265
236
- 

Return to bug 31236