Bug 17397: Show name of librarian who created circulation message
authorJosef Moravec <josef.moravec@gmail.com>
Tue, 4 Oct 2016 11:57:03 +0000 (13:57 +0200)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 28 Oct 2016 15:37:27 +0000 (15:37 +0000)
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 <koha@univ-lyon3.fr>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Koha/Patron/Message.pm
circ/circulation.pl
installer/data/mysql/atomicupdate/bug_17397.sql [new file with mode: 0644]
installer/data/mysql/kohastructure.sql
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt

index a928fa5..5e518fb 100644 (file)
@@ -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");
 
index eb7973f..e51ed2e 100755 (executable)
@@ -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 (file)
index 0000000..f571b72
--- /dev/null
@@ -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;
index 3201f23..6893d6b 100644 (file)
@@ -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;
 
 --
index 7111ef9..eab3ef2 100644 (file)
@@ -850,11 +850,16 @@ No patron matched <span class="ex">[% message | html %]</span>
     <div id="messages" class="circmessage">
         <h4>Messages:</h4>
         <ul>
-            [% FOREACH message IN librarian_messages %]
+            [% FOREACH message IN messages %]
                 <li>
-                    <span class="circ-hlt">
+                    [% IF(message.message_type == "L") %]
+                        <span class="circ-hlt">
+                    [% ELSE %]
+                        <span>
+                    [% END %]>
                         [% message.message_date | $KohaDates %]
                         [% Branches.GetName( message.branchcode ) %]
+                        ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% message.manager_id %]">[% message.name %]</a> )
                         <i>"[% message.message %]"</i>
                     </span>
                     [% IF message.branchcode == branch OR Koha.Preference('AllowAllMessageDeletion') %]
@@ -862,12 +867,6 @@ No patron matched <span class="ex">[% message | html %]</span>
                     [% END %]
                 </li>
             [% END %]
-            [% FOREACH message IN patron_messages %]
-                <li><span class="">[% message.message_date | $KohaDates %] [% Branches.GetName( message.branchcode )%] <i>"[% message.message %]"</i></span>
-                [% IF message.branchcode == branch OR Koha.Preference('AllowAllMessageDeletion') %]
-                    [<a href="/cgi-bin/koha/circ/del_message.pl?message_id=[% message.message_id %]&amp;borrowernumber=[% message.borrowernumber %]"><i class="fa fa-trash"></i> Delete</a>]
-                [% END %]</li>
-            [% END %]
         </ul>
         <a id="addnewmessageLabel" href="#add_message_form" data-toggle="modal"><i class="fa fa-plus"></i> Add a new message</a>
     </div>