@@ -, +, @@ messages - 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 | 33 ++++++++ .../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 | 82 +++++++++++++++++++ t/db_dependent/Koha/Patron/Messages.t | 41 +++++++++- 8 files changed, 193 insertions(+), 6 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_12029.pl create mode 100755 opac/dismiss_message.pl --- a/Koha/Patron/Messages.pm +++ a/Koha/Patron/Messages.pm @@ -42,8 +42,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; --- a/installer/data/mysql/atomicupdate/bug_12029.pl +++ a/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"; + }, +}; --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -3813,6 +3813,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`), --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc @@ -218,6 +218,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 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc +++ a/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