From 265214fb56f7ba27280f7c4714a11ac07c9f7058 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 --- Koha/Patron/Message.pm | 3 ++ circ/circulation.pl | 34 +++++++++++++++------- installer/data/mysql/atomicupdate/bug_17397.sql | 3 ++ installer/data/mysql/kohastructure.sql | 4 ++- .../prog/en/modules/circ/circulation.tt | 11 ++----- 5 files changed, 35 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 a928fa5..5e518fb 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 fcd967d..59dda6a 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -564,20 +564,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 (defined getframeworkinfo('FA')) { $fast_cataloging = 1 @@ -625,8 +638,7 @@ if ($restoreduedatespec || $stickyduedate) { } $template->param( - 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 0000000..f571b72 --- /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 e38efc5..20a0663 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2659,7 +2659,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 e0284b2..6668aa5 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,12 @@ No patron matched [% message | html %]

Messages:

Add a new message
-- 2.1.4