From 6a3c195999ba24705875b0f3a0b25b0d80a92476 Mon Sep 17 00:00:00 2001 From: Bill Raty Date: Wed, 26 Jan 2022 16:47:52 +0000 Subject: [PATCH] Bug 12029: Patrons should be able to delete their patron messages This patch adds an option for patrons to dismiss OPAC messages sent to them by the staff. The messages remain visible in the staff interface with an indication that the message has been read. To test, apply the patch and run the database update. - View a patron record in the staff interface. - Click "Add message" and select "OPAC" from the "Add a message for..." dropdown. - Add a message. - Log in to the OPAC as that patron. - On the "Your summary" page you should see the message along with a "Dismiss" link." - Clicking the "Dismiss" link should make the message disappear. - Go to the OPAC home page. The "User summary" box in the right sidebar should have the correct count of messages. - View the patron record in the staff interface again. - The list of patron messages should still include the message which was dismissed via the OPAC, but there should be indication that the message was read, e.g. "read 11-2-2022" --- Koha/Patron/Messages.pm | 34 +++++ Koha/Schema/Result/Message.pm | 14 ++ .../data/mysql/atomicupdate/bug_12029.pl | 28 ++++ installer/data/mysql/kohastructure.sql | 1 + .../prog/en/includes/patron_messages.inc | 3 + .../bootstrap/en/includes/opac-note.inc | 5 +- .../bootstrap/en/modules/opac-main.tt | 6 +- opac/dismiss_message.pl | 121 ++++++++++++++++++ 8 files changed, 207 insertions(+), 5 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_12029.pl create mode 100755 opac/dismiss_message.pl diff --git a/Koha/Patron/Messages.pm b/Koha/Patron/Messages.pm index 7cc729ac86..c9cf646d59 100644 --- a/Koha/Patron/Messages.pm +++ b/Koha/Patron/Messages.pm @@ -1,3 +1,4 @@ + package Koha::Patron::Messages; # This file is part of Koha. @@ -42,8 +43,41 @@ sub _type { return 'Message'; } +=head3 object_class + +=cut + sub object_class { return 'Koha::Patron::Message'; } +=head3 unread + + Returns a result set of messages that haven't been marked read by the patron + +=cut + +sub unread { + # return resultset of messages with an undefined patron_read_date + my ($self, $params) = @_; + $params ||= {}; + return $self->search({ + patron_read_date => {IS => undef}, + %$params, + }); +} + +=head3 unread_count + + Returns a count of messages that haven't been marked read by the patron + +=cut + + +sub unread_count { + # return count of unread + my ($self, $params) = @_; + $params ||= {}; + return $self->unread(%$params)->count(); +} 1; diff --git a/Koha/Schema/Result/Message.pm b/Koha/Schema/Result/Message.pm index 1ed5b0e16c..1779e89ed6 100644 --- a/Koha/Schema/Result/Message.pm +++ b/Koha/Schema/Result/Message.pm @@ -79,6 +79,14 @@ the date and time the message was written creator of message +=head2 patron_read_date + + data_type: 'timestamp' + datetime_undef_if_invalid: 1 + is_nullable: 1 + +date and time the patron dismissed the message + =cut __PACKAGE__->add_columns( @@ -101,6 +109,12 @@ __PACKAGE__->add_columns( }, "manager_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + "patron_read_date", + { + data_type => "timestamp", + datetime_undef_if_invalid => 1, + is_nullable => 1, + }, ); =head1 PRIMARY KEY diff --git a/installer/data/mysql/atomicupdate/bug_12029.pl b/installer/data/mysql/atomicupdate/bug_12029.pl new file mode 100755 index 0000000000..f352a66edf --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_12029.pl @@ -0,0 +1,28 @@ +use Modern::Perl; + +return { + bug_number => "12029", + description => "Enable patrons to delete messages", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + # Do you stuffs here + my $alteration = qq{ + ALTER TABLE messages + ADD COLUMN `patron_read_date` timestamp NULL DEFAULT NULL + COMMENT 'date and time patron dismissed message' + AFTER `manager_id` + }; + if( column_exists('messages', 'patron_read_date') ) { + say $out "NOTICE: Column 'messages.patron_read_date' already exists"; + } + else { + say $out "ALTERATION: $alteration"; + $dbh->do($alteration); + } + + # Print useful stuff here + say $out "INFO: Bug 12029 migration applied"; + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 4411ae7604..5847925f55 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3739,6 +3739,7 @@ CREATE TABLE `messages` ( `message` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'the text of the message', `message_date` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'the date and time the message was written', `manager_id` int(11) DEFAULT NULL COMMENT 'creator of message', + `patron_read_date` timestamp NULL DEFAULT NULL COMMENT 'date and time the patron dismissed the message', PRIMARY KEY (`message_id`), KEY `messages_ibfk_1` (`manager_id`), KEY `messages_borrowernumber` (`borrowernumber`), 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 0c1d8f88dc..64f4cabb55 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc @@ -216,6 +216,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') %] Delete 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..8b2c39f861 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,13 @@ -[% IF patron_messages.count OR opacnote %] +[% IF patron_messages.unread_count OR opacnote %]

Messages for you