From 3d63c64915c02c44a5e1a45e9db66be939fd4dae Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Tue, 4 Oct 2016 13:57:03 +0200 Subject: [PATCH] Bug 17397: Show name of librarian who created circulation message Test plan: 1) Apply the patch 2) Update DB structure 3) Run update_dbix_class_files.pl 4) Select patron for checking out 5) Try to add some circulation and opac messages 6) Note that now there is creator (you ;) ) shown by every message added (with link to creator profile) 7) Try to delete messages to confirm that everything works as expected Signed-off-by: Sonia Bouis Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- Koha/Patron/Message.pm | 3 ++ circ/circulation.pl | 34 +++++++++++++------ .../data/mysql/atomicupdate/bug_17397.sql | 3 ++ installer/data/mysql/kohastructure.sql | 4 ++- .../prog/en/modules/circ/circulation.tt | 15 ++++---- 5 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_17397.sql diff --git a/Koha/Patron/Message.pm b/Koha/Patron/Message.pm index a928fa5a01..5e518fbb26 100644 --- a/Koha/Patron/Message.pm +++ b/Koha/Patron/Message.pm @@ -49,6 +49,9 @@ sub store { and $self->message_type and $self->branchcode; + my $userenv = C4::Context->userenv; + $self->manager_id($userenv ? $userenv->{number} : 0); + C4::Log::logaction( "MEMBERS", "ADDCIRCMESSAGE", $self->borrowernumber, $self->message ) if C4::Context->preference("BorrowersLog"); diff --git a/circ/circulation.pl b/circ/circulation.pl index eb7973f71e..e51ed2efc4 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -566,20 +566,33 @@ if ( $borrowernumber && $borrower->{'category_type'} eq 'C') { $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; } -my $librarian_messages = Koha::Patron::Messages->search( +my $all_messages = Koha::Patron::Messages->search( { - borrowernumber => $borrowernumber, - message_type => 'L', - } -); - -my $patron_messages = Koha::Patron::Messages->search( + 'me.borrowernumber' => $borrowernumber, + }, { - borrowernumber => $borrowernumber, - message_type => 'B', + join => 'manager', + '+select' => ['manager.surname', 'manager.firstname' ], + '+as' => ['manager_surname', 'manager_firstname'], } ); +my @messages; +while ( my $content = $all_messages->next ) { + my $this_item; + + $this_item->{borrowernumber} = $content->borrowernumber; + $this_item->{message_id} = $content->message_id; + $this_item->{branchcode} = $content->branchcode; + $this_item->{message_type} = $content->message_type; + $this_item->{message_date} = $content->message_date; + $this_item->{message} = $content->message; + $this_item->{manager_id} = $content->manager_id; + $this_item->{name} = $content->_result->get_column('manager_firstname') . ' ' . $content->_result->get_column('manager_surname'); + + push @messages, $this_item; +} + my $fast_cataloging = 0; if ( Koha::BiblioFrameworks->find('FA') ) { $fast_cataloging = 1 @@ -629,8 +642,7 @@ if ($restoreduedatespec || $stickyduedate) { $template->param( patron => $patron, - librarian_messages => $librarian_messages, - patron_messages => $patron_messages, + messages => \@messages, borrower => $borrower, borrowernumber => $borrowernumber, categoryname => $borrower->{'description'}, diff --git a/installer/data/mysql/atomicupdate/bug_17397.sql b/installer/data/mysql/atomicupdate/bug_17397.sql new file mode 100644 index 0000000000..f571b7236d --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_17397.sql @@ -0,0 +1,3 @@ +ALTER TABLE `messages` +ADD `manager_id` int(11) NULL, +ADD FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 3201f23638..6893d6bd4a 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2671,7 +2671,9 @@ CREATE TABLE `messages` ( -- circulation messages left via the patron's check ou `message_type` varchar(1) NOT NULL, -- whether the message is for the librarians (L) or the patron (B) `message` text NOT NULL, -- the text of the message `message_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- the date and time the message was written - PRIMARY KEY (`message_id`) + `manager_id` int(11) default NULL, -- creator of message + PRIMARY KEY (`message_id`), + CONSTRAINT `messages_ibfk_1` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 7111ef9582..eab3ef2aa1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -850,11 +850,16 @@ No patron matched [% message | html %]

Messages:

    - [% FOREACH message IN librarian_messages %] + [% FOREACH message IN messages %]
  • - + [% IF(message.message_type == "L") %] + + [% ELSE %] + + [% END %]> [% message.message_date | $KohaDates %] [% Branches.GetName( message.branchcode ) %] + ( [% message.name %] ) "[% message.message %]" [% IF message.branchcode == branch OR Koha.Preference('AllowAllMessageDeletion') %] @@ -862,12 +867,6 @@ No patron matched [% message | html %] [% END %]
  • [% END %] - [% FOREACH message IN patron_messages %] -
  • [% message.message_date | $KohaDates %] [% Branches.GetName( message.branchcode )%] "[% message.message %]" - [% IF message.branchcode == branch OR Koha.Preference('AllowAllMessageDeletion') %] - [ Delete] - [% END %]
  • - [% END %]
Add a new message
-- 2.39.5