From 368dfdc7d0e43db6c31bc3bc8d6a294b00d585e3 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Wed, 15 Feb 2023 21:57:08 +1300 Subject: [PATCH] Bug 12029: Ability for patrons to dismiss OPAC messages This enhancement adds the ability for patrons to dismiss an OPAC message, marking it as read to remove it from their summary page. To test: 1) Update database and restart services 2) Log into the staff interface and go to your patron account 3) Click the Add message button 4) Add a message for the OPAC and Save 5) Log into the OPAC. Note there is a message on the homepage saying you have a message. Go to your user summary and confirm the message displays. 6) Click the button to dismiss the message. A confirmation box should pop up - hitting Cancel should stop the action. 7) Dismiss the message again and this time Confirm. Make sure the message is gone from the OPAC user summary and from the homepage. 8) Confirm tests pass t/db_dependent/Koha/Patron/Messages.t 9) Create a few more messages for the OPAC 10) Log into the OPAC and dismiss one of the messages 11) Confirm the count of unread messages on the OPAC home page is correct Sponsored-by: Koha-US Signed-off-by: Christopher Brannon Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- Koha/Patron/Messages.pm | 23 ++++++++ .../prog/en/includes/patron_messages.inc | 3 ++ .../bootstrap/en/includes/opac-note.inc | 9 +++- .../bootstrap/en/modules/opac-main.tt | 10 ++-- .../bootstrap/en/modules/opac-user.tt | 4 ++ opac/opac-dismiss-message.pl | 54 +++++++++++++++++++ 6 files changed, 96 insertions(+), 7 deletions(-) create mode 100755 opac/opac-dismiss-message.pl diff --git a/Koha/Patron/Messages.pm b/Koha/Patron/Messages.pm index 7cc729ac86..063c70364b 100644 --- a/Koha/Patron/Messages.pm +++ b/Koha/Patron/Messages.pm @@ -34,6 +34,25 @@ Koha::Patron::Messages - Koha Message Object set class =cut +=head3 filter_by_unread + + Returns a resultset of messages that have not been marked read by the patron + +=cut + +sub filter_by_unread { + my ( $self, $params ) = @_; + + $params ||= {}; + + return $self->search( + { + patron_read_date => { is => undef }, + %$params, + } + ); +} + =head3 _type =cut @@ -42,6 +61,10 @@ sub _type { return 'Message'; } +=head3 object_class + +=cut + sub object_class { return 'Koha::Patron::Message'; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc index 19ba6cee80..cefe1d10a9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc @@ -308,6 +308,9 @@ ( [% patron_message.get_column('manager_firstname') | html %] [% patron_message.get_column('manager_surname') | html %] ) [% END %] "[% patron_message.message | html %]" + [% IF patron_message.patron_read_date %] + Read: [% patron_message.patron_read_date | $KohaDates %] + [% END %] [% IF patron_message.branchcode == Branches.GetLoggedInBranchcode OR Koha.Preference('AllowAllMessageDeletion') %] [% IF moremember %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc index 22e6a068ce..6ed5e724f2 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc @@ -1,12 +1,17 @@ -[% IF patron_messages.count OR opacnote %] +[% IF patron_messages.filter_by_unread.count OR opacnote %]

Messages for you

    - [% FOREACH message IN patron_messages %] + [% FOREACH message IN patron_messages.filter_by_unread %]
  • [% message.message | html | html_line_break %]
       Written on [% message.message_date | $KohaDates %] by [% Branches.GetName(message.branchcode) | html %]
  • +
    + + + +
    [% END %] [% IF ( opacnote ) %]
  • [% opacnote | html | html_line_break %]
  • [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt index 4ffbc8e024..cca221a4e0 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt @@ -283,19 +283,19 @@ [% END %] - [% IF patron_messages && patron_messages.count > 0 || opacnote %] + [% IF patron_messages && patron_messages.filter_by_unread.count > 0 || opacnote %] [% IF opacnote %]
  • - [% patron_messages.count + 1 | html %] - [% tn('message', 'messages', patron_messages.count + 1 ) | html %] + [% patron_messages.filter_by_unread.count + 1 | html %] + [% tn('message', 'messages', patron_messages.filter_by_unread.count + 1 ) | html %]
  • [% ELSE %]
  • - [% patron_messages.count | html %] - [% tn('message', 'messages', patron_messages.count ) | html %] + [% patron_messages.filter_by_unread.count | html %] + [% tn('message', 'messages', patron_messages.filter_by_unread.count ) | html %]
  • [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt index 37d36399ea..c6ce700486 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -1292,6 +1292,10 @@ $("#addNoteTitle").text(""); $("#addNote").val(""); }); + + $(".dismiss-message-button").click(function(e){ + return confirmDelete(_("Are you sure you want to dismiss this message?")); + }); }); function submitNote( title, issue_id, note ){ diff --git a/opac/opac-dismiss-message.pl b/opac/opac-dismiss-message.pl new file mode 100755 index 0000000000..84c5906b6a --- /dev/null +++ b/opac/opac-dismiss-message.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl + +# Copyright 2023 Aleisha Amohia +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use CGI qw ( -utf8 ); +use C4::Koha; +use C4::Context; +use C4::Output qw( output_html_with_http_headers ); +use C4::Auth qw( get_template_and_user ); +use Koha::DateUtils qw( dt_from_string ); +use Koha::Patrons; + +my $query = CGI->new; + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "opac-user.tt", + query => $query, + type => "opac", + } +); + +my $patron_id = $query->param('patron_id'); +my $patron = Koha::Patrons->find( $patron_id ); +my $message_id = $query->param('message_id'); +my $message = $patron->messages->find( $message_id ); + +unless ( $message ) { + # exit early + print $query->redirect("/cgi-bin/koha/opac-user.pl"); + exit; +} + +$message->update({ patron_read_date => dt_from_string }); + +print $query->redirect("/cgi-bin/koha/opac-user.pl"); + +output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; -- 2.39.5