From 71b22b663c8e0d72789b05cc0e90f03ac5e60eec Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Wed, 11 Sep 2019 11:39:31 +0200 Subject: [PATCH] Bug 25816: Add opac messages in SIP display. Test plan: - Add one or more opac messages to a patron (patron detail -> add message -> Add a message for: OPAC) - Check that the messages will be displayed, with correctly formatted dates. You can use src/C4/SIP/interactive_patron_dump.pl for easier testing. Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/SIP/ILS/Patron.pm | 17 +++++++++++++++++ t/db_dependent/SIP/Patron.t | 29 ++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 4b3e76f1a8..7e7746b576 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -28,6 +28,8 @@ use Koha::Libraries; use Koha::Patrons; use Koha::Checkouts; use Koha::TemplateUtils qw( process_tt ); +use Koha::Patron::Messages; +use Koha::DateUtils qw(dt_from_string output_pref); our $kp; # koha patron @@ -164,6 +166,21 @@ sub new { } } } + my $patron_messages = Koha::Patron::Messages->search( + { + borrowernumber => $kp->{borrowernumber}, + message_type => 'B', + } + ); + my @messages_array; + while ( my $message = $patron_messages->next ) { + my $messagedt = dt_from_string( $message->message_date, 'iso' ); + my $formatted_date = output_pref({ dt => $messagedt, dateonly => 1}); + push @messages_array, $formatted_date . ": " . $message->message; + } + if (@messages_array) { + $ilspatron{screen_msg} .= ". Messages for you: " . join(' / ', @messages_array); + } # FIXME: populate fine_items recall_items $ilspatron{unavail_holds} = _get_outstanding_holds($kp->{borrowernumber}); diff --git a/t/db_dependent/SIP/Patron.t b/t/db_dependent/SIP/Patron.t index d7e86eb444..56cafc0fe0 100755 --- a/t/db_dependent/SIP/Patron.t +++ b/t/db_dependent/SIP/Patron.t @@ -4,7 +4,7 @@ # This needs to be extended! Your help is appreciated.. use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use t::lib::Mocks; use t::lib::TestBuilder; @@ -405,3 +405,30 @@ subtest "NoIssuesChargeGuarantorsWithGuarantees tests" => sub { $schema->storage->txn_rollback; }; + +subtest "Patron messages tests" => sub { + plan tests => 1; + $schema->storage->txn_begin; + my $today = output_pref({ dt => dt_from_string(), dateonly => 1}); + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + my $library = $builder->build_object ({ class => 'Koha::Libraries' }); + my $new_message_1 = Koha::Patron::Message->new( + { borrowernumber => $patron->id, + branchcode => $library->branchcode, + message_type => 'B', + message => 'my message 1', + })->store; + + my $new_message_2 = Koha::Patron::Message->new( + { borrowernumber => $patron->id, + branchcode => $library->branchcode, + message_type => 'B', + message => 'my message 2', + })->store; + + + my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); + like( $sip_patron->screen_msg, qr/Messages for you: $today: my message 1 \/ $today: my message 2/,"Screen message includes patron messages"); + + $schema->storage->txn_rollback; +}; -- 2.39.5