use Sys::Syslog qw(syslog);
use Data::Dumper;
+use C4::SIP::Sip qw(add_field);
+
use C4::Debug;
use C4::Context;
use C4::Koha;
return \@holds;
}
+sub build_patron_attributes_string {
+ my ( $self, $server ) = @_;
+
+ my $string = q{};
+
+ if ( $server->{account}->{patron_attribute} ) {
+ my @attributes_to_send =
+ ref $server->{account}->{patron_attribute} eq "ARRAY"
+ ? @{ $server->{account}->{patron_attribute} }
+ : ( $server->{account}->{patron_attribute} );
+
+ foreach my $a ( @attributes_to_send ) {
+ my @attributes = Koha::Patron::Attributes->search(
+ {
+ borrowernumber => $self->{borrowernumber},
+ code => $a->{code}
+ }
+ );
+
+ foreach my $attribute ( @attributes ) {
+ my $value = $attribute->attribute();
+ $string .= add_field( $a->{field}, $value );
+ }
+ }
+ }
+
+ return $string;
+}
+
1;
__END__
use CGI qw ( -utf8 );
use C4::Auth qw(&check_api_auth);
+use Koha::Patron::Attributes;
+
use UNIVERSAL::can;
use vars qw(@ISA @EXPORT_OK);
if ( $server->{account}->{send_patron_home_library_in_af} );
$resp .= maybe_add( FID_PRINT_LINE, $patron->print_line );
+ $resp .= $patron->build_patron_attributes_string( $server );
+
} else {
# Invalid patron (cardnumber)
# Report that the user has no privs.
$resp .= maybe_add( FID_SCREEN_MSG, $patron->{branchcode}, $server);
}
$resp .= maybe_add( FID_PRINT_LINE, $patron->print_line );
+
+ $resp .= $patron->build_patron_attributes_string( $server );
} else {
# Invalid patron ID:
# This needs to be extended! Your help is appreciated..
use Modern::Perl;
-use Test::More tests => 3;
+use Test::More tests => 4;
use Koha::Database;
use t::lib::TestBuilder;
use t::lib::Mocks;
use C4::SIP::ILS::Patron;
+use Koha::Patron::Attributes;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
};
+subtest "Test build_patron_attribute_string" => sub {
+
+ plan tests => 2;
+
+ my $patron = $builder->build( { source => 'Borrower' } );
+
+ my $attribute_type = $builder->build( { source => 'BorrowerAttributeType' } );
+ my $attribute = Koha::Patron::Attribute->new(
+ {
+ borrowernumber => $patron->{borrowernumber},
+ code => $attribute_type->{code},
+ attribute => 'Test Attribute'
+ }
+ )->store();
+
+ my $attribute_type2 = $builder->build( { source => 'BorrowerAttributeType' } );
+ my $attribute2 = Koha::Patron::Attribute->new(
+ {
+ borrowernumber => $patron->{borrowernumber},
+ code => $attribute_type2->{code},
+ attribute => 'Another Test Attribute'
+ }
+ )->store();
+
+ my $ils_patron = C4::SIP::ILS::Patron->new( $patron->{cardnumber} );
+
+ my $server = {};
+ $server->{account}->{patron_attribute}->{code} = $attribute->code;
+ $server->{account}->{patron_attribute}->{field} = 'XY';
+ my $attribute_string = $ils_patron->build_patron_attributes_string( $server );
+ is( $attribute_string, "XYTest Attribute|", 'Attribute field generated correctly with single param' );
+
+ $server = {};
+ $server->{account}->{patron_attribute}->[0]->{code} = $attribute->code;
+ $server->{account}->{patron_attribute}->[0]->{field} = 'XY';
+ $server->{account}->{patron_attribute}->[1]->{code} = $attribute2->code;
+ $server->{account}->{patron_attribute}->[1]->{field} = 'YZ';
+ $attribute_string = $ils_patron->build_patron_attributes_string( $server );
+ is( $attribute_string, "XYTest Attribute|YZAnother Test Attribute|", 'Attribute field generated correctly with multiple params' );
+};
+
$schema->storage->txn_rollback;