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 431-439 sub build_additional_item_fields_string { Link Here
431
        }
431
        }
432
    }
432
    }
433
433
434
    if ( $server->{account}->{custom_item_field} ) {
435
        my @custom_fields =
436
            ref $server->{account}->{custom_item_field} eq "ARRAY"
437
            ? @{ $server->{account}->{custom_item_field} }
438
            : $server->{account}->{custom_item_field};
439
440
        foreach my $custom_field ( @custom_fields ) {
441
            my $field = $custom_field->{field};
442
            return q{} unless defined $field;
443
            my $template = $custom_field->{template};
444
            my $formatted = $self->format( $template );
445
            my $substring = maybe_add( $field, $formatted, $server );
446
            $string .= $substring;
447
        }
448
    }
449
450
    return $string;
451
}
452
453
=head2 build_custom_field_string
454
455
This method builds the part of the sip message for custom item fields as defined in the sip config
456
457
=cut
458
459
sub build_custom_field_string {
460
    my ( $self, $server ) = @_;
461
462
    my $string = q{};
463
464
434
    return $string;
465
    return $string;
435
}
466
}
436
467
468
=head2 format
469
470
This method uses a template to build a string from a Koha::Item object
471
If errors are encountered in processing template we log them and return nothing
472
473
=cut
474
475
sub format {
476
    my ( $self, $template ) = @_;
477
478
    if ($template) {
479
        require Template;
480
481
        my $tt = Template->new();
482
483
        my $item = $self->{_object};
484
485
        my $output;
486
        eval {
487
            $tt->process( \$template, { item => $item }, \$output );
488
        };
489
        if ( $@ ){
490
            siplog("LOG_DEBUG", "Error processing template: $template");
491
            return "";
492
        }
493
        return $output;
494
    }
495
}
496
437
1;
497
1;
438
__END__
498
__END__
439
499
(-)a/C4/SIP/Sip/MsgType.pm (+1 lines)
Lines 1279-1284 sub handle_item_information { Link Here
1279
        $resp .= maybe_add( FID_PRINT_LINE, $item->print_line, $server );
1279
        $resp .= maybe_add( FID_PRINT_LINE, $item->print_line, $server );
1280
1280
1281
        $resp .= $item->build_additional_item_fields_string( $server );
1281
        $resp .= $item->build_additional_item_fields_string( $server );
1282
        $resp .= $item->build_custom_field_string( $server );
1282
    }
1283
    }
1283
1284
1284
    $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} );
1285
    $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} );
(-)a/etc/SIPconfig.xml (+1 lines)
Lines 87-92 Link Here
87
              <AllFinesNeedOverride>0</AllFinesNeedOverride>
87
              <AllFinesNeedOverride>0</AllFinesNeedOverride>
88
          </syspref_overrides>
88
          </syspref_overrides>
89
          <custom_patron_field field="DE" template="[% patron.dateexpiry %]" />
89
          <custom_patron_field field="DE" template="[% patron.dateexpiry %]" />
90
          <custom_item_field field="IN" template="[% item.itemnumber %]" />
90
      </login>
91
      </login>
91
  </accounts>
92
  </accounts>
92
93
(-)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