View | Details | Raw Unified | Return to bug 12029
Collapse All | Expand All

(-)a/Koha/Patron/Messages.pm (+34 lines)
Lines 1-3 Link Here
1
1
package Koha::Patron::Messages;
2
package Koha::Patron::Messages;
2
3
3
# This file is part of Koha.
4
# This file is part of Koha.
Lines 42-49 sub _type { Link Here
42
    return 'Message';
43
    return 'Message';
43
}
44
}
44
45
46
=head3 object_class
47
48
=cut
49
45
sub object_class {
50
sub object_class {
46
    return 'Koha::Patron::Message';
51
    return 'Koha::Patron::Message';
47
}
52
}
48
53
54
=head3 unread
55
56
    Returns a result set of messages that haven't been marked read by the patron
57
58
=cut
59
60
sub unread {
61
    # return resultset of messages with an undefined patron_read_date
62
    my ($self, $params) = @_;
63
    $params ||= {};
64
    return $self->search({
65
        patron_read_date => {IS => undef},
66
        %$params,
67
    });
68
}
69
70
=head3 unread_count
71
72
    Returns a count of messages that haven't been marked read by the patron
73
74
=cut
75
76
77
sub unread_count {
78
    # return count of unread
79
    my ($self, $params) = @_;
80
    $params ||= {};
81
    return $self->unread(%$params)->count();
82
}
49
1;
83
1;
(-)a/Koha/Schema/Result/Message.pm (+14 lines)
Lines 79-84 the date and time the message was written Link Here
79
79
80
creator of message
80
creator of message
81
81
82
=head2 patron_read_date
83
84
  data_type: 'timestamp'
85
  datetime_undef_if_invalid: 1
86
  is_nullable: 1
87
88
date and time the patron dismissed the message
89
82
=cut
90
=cut
83
91
84
__PACKAGE__->add_columns(
92
__PACKAGE__->add_columns(
Lines 101-106 __PACKAGE__->add_columns( Link Here
101
  },
109
  },
102
  "manager_id",
110
  "manager_id",
103
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
111
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
112
  "patron_read_date",
113
  {
114
    data_type => "timestamp",
115
    datetime_undef_if_invalid => 1,
116
    is_nullable => 1,
117
  },
104
);
118
);
105
119
106
=head1 PRIMARY KEY
120
=head1 PRIMARY KEY
(-)a/installer/data/mysql/atomicupdate/bug_12029.pl (+28 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "12029",
5
    description => "Enable patrons to delete messages",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
10
        # Do you stuffs here
11
        my $alteration = qq{
12
            ALTER TABLE messages
13
            ADD COLUMN `patron_read_date` timestamp NULL DEFAULT NULL
14
            COMMENT 'date and time patron dismissed message'
15
            AFTER `manager_id`
16
        };
17
        if( column_exists('messages', 'patron_read_date') ) {
18
            say $out "NOTICE: Column 'messages.patron_read_date' already exists";
19
        }
20
        else {
21
            say $out "ALTERATION: $alteration";
22
            $dbh->do($alteration);
23
        }
24
25
        # Print useful stuff here
26
        say $out "INFO: Bug 12029 migration applied";
27
    },
28
};
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 3739-3744 CREATE TABLE `messages` ( Link Here
3739
  `message` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'the text of the message',
3739
  `message` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'the text of the message',
3740
  `message_date` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'the date and time the message was written',
3740
  `message_date` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'the date and time the message was written',
3741
  `manager_id` int(11) DEFAULT NULL COMMENT 'creator of message',
3741
  `manager_id` int(11) DEFAULT NULL COMMENT 'creator of message',
3742
  `patron_read_date` timestamp NULL DEFAULT NULL COMMENT 'date and time the patron dismissed the message',
3742
  PRIMARY KEY (`message_id`),
3743
  PRIMARY KEY (`message_id`),
3743
  KEY `messages_ibfk_1` (`manager_id`),
3744
  KEY `messages_ibfk_1` (`manager_id`),
3744
  KEY `messages_borrowernumber` (`borrowernumber`),
3745
  KEY `messages_borrowernumber` (`borrowernumber`),
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc (+3 lines)
Lines 216-221 Link Here
216
                            ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron_message.manager_id | uri %]">[% patron_message.get_column('manager_firstname') | html %] [% patron_message.get_column('manager_surname') | html %]</a> )
216
                            ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron_message.manager_id | uri %]">[% patron_message.get_column('manager_firstname') | html %] [% patron_message.get_column('manager_surname') | html %]</a> )
217
                        [% END %]
217
                        [% END %]
218
                        <em>"[% patron_message.message | html %]"</em>
218
                        <em>"[% patron_message.message | html %]"</em>
219
                        [% IF patron_message.patron_read_date %]
220
                           read [% patron_message.patron_read_date | $KohaDates %]
221
                        [% END %]
219
                    </span>
222
                    </span>
220
                    [% IF patron_message.branchcode == Branches.GetLoggedInBranchcode OR Koha.Preference('AllowAllMessageDeletion') %]
223
                    [% IF patron_message.branchcode == Branches.GetLoggedInBranchcode OR Koha.Preference('AllowAllMessageDeletion') %]
221
                        <a class="btn btn-link" href="/cgi-bin/koha/circ/del_message.pl?message_id=[% patron_message.message_id | html %]&amp;borrowernumber=[% patron_message.borrowernumber | html %]&amp;from=moremember" onclick='return confirm(_("Are you sure you want to delete this message? This cannot be undone."));'><i class="fa fa-trash"></i> Delete</a>
224
                        <a class="btn btn-link" href="/cgi-bin/koha/circ/del_message.pl?message_id=[% patron_message.message_id | html %]&amp;borrowernumber=[% patron_message.borrowernumber | html %]&amp;from=moremember" onclick='return confirm(_("Are you sure you want to delete this message? This cannot be undone."));'><i class="fa fa-trash"></i> Delete</a>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc (-2 / +3 lines)
Lines 1-12 Link Here
1
[% IF patron_messages.count OR opacnote %]
1
[% IF patron_messages.unread_count OR opacnote %]
2
    <div class="alert alert-info">
2
    <div class="alert alert-info">
3
        <h3>Messages for you</h3>
3
        <h3>Messages for you</h3>
4
        <ul>
4
        <ul>
5
            [% FOREACH message IN patron_messages %]
5
            [% FOREACH message IN patron_messages.unread %]
6
                <li>
6
                <li>
7
                    <strong>[% message.message | html | html_line_break %]</strong><br>
7
                    <strong>[% message.message | html | html_line_break %]</strong><br>
8
                    &nbsp;&nbsp;&nbsp;<em>Written on [% message.message_date | $KohaDates %] by [% Branches.GetName(message.branchcode) | html %]</em>
8
                    &nbsp;&nbsp;&nbsp;<em>Written on [% message.message_date | $KohaDates %] by [% Branches.GetName(message.branchcode) | html %]</em>
9
                </li>
9
                </li>
10
                <a class="btn btn-link" href="/cgi-bin/koha/dismiss_message.pl?message_id=[% message.message_id | html %]&amp;borrowernumber=[% message.borrowernumber | html %]" onclick="return true;"><i class="fa fa-trash" aria-hidden="true"></i> Dismiss</a>
10
            [% END %]
11
            [% END %]
11
12
12
            [% IF ( opacnote ) %]<li>[% opacnote | html | html_line_break %]</li>[% END %]
13
            [% IF ( opacnote ) %]<li>[% opacnote | html | html_line_break %]</li>[% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt (-3 / +3 lines)
Lines 261-267 Link Here
261
                                            </a>
261
                                            </a>
262
                                        </li>
262
                                        </li>
263
                                    [% END %]
263
                                    [% END %]
264
                                    [% IF patron_messages && patron_messages.count > 0 || opacnote %]
264
                                    [% IF patron_messages && patron_messages.unread_count || opacnote %]
265
                                        [% IF opacnote %]
265
                                        [% IF opacnote %]
266
                                            <li>
266
                                            <li>
267
                                                <a href="/cgi-bin/koha/opac-user.pl">
267
                                                <a href="/cgi-bin/koha/opac-user.pl">
Lines 272-279 Link Here
272
                                        [% ELSE %]
272
                                        [% ELSE %]
273
                                            <li>
273
                                            <li>
274
                                                <a href="/cgi-bin/koha/opac-user.pl">
274
                                                <a href="/cgi-bin/koha/opac-user.pl">
275
                                                    <span class="count_label">[% patron_messages.count | html %]</span>
275
                                                    <span class="count_label">[% patron_messages.unread_count | html %]</span>
276
                                                    [% tn('message', 'messages', patron_messages.count ) | html %]
276
                                                    [% tn('message', 'messages', patron_messages.unread_count ) | html %]
277
                                                </a>
277
                                                </a>
278
                                            </li>
278
                                            </li>
279
                                        [% END %]
279
                                        [% END %]
(-)a/opac/dismiss_message.pl (-1 / +121 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
# Copyright 2021 AutoParallel Technologies Inc.
3
# Copyright 2009 PTFS Inc.
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use CGI qw ( -utf8 );
23
24
use C4::Auth qw( get_template_and_user );
25
use C4::Output;
26
use Koha::Patron::Messages;
27
28
use Try::Tiny;
29
use JSON qw//;
30
31
use constant {
32
    TRUE         => 1,
33
    FALSE        => 0,
34
    json         => JSON->new->pretty,
35
    REDIRECT_URL => '/cgi-bin/koha/opac-user.pl',
36
};
37
38
sub dismiss_patron_message {
39
    # accept a CGI object as input
40
    my ($cgi) = @_;
41
42
    # get input parameters
43
    my $message_id     = $cgi->param('message_id')     || undef;
44
    my $borrowernumber = $cgi->param('borrowernumber') || undef;
45
    my $inputs = {
46
        message_id     => $message_id,
47
        borrowernumber => $borrowernumber,
48
    };
49
50
    # set default result values
51
    my $result = {
52
        success    => FALSE,
53
        comment    => 'default failure',
54
        inputs     => $inputs,
55
    };
56
57
58
    my $rs = Koha::Patron::Messages->search($inputs);
59
    my $message = $rs->next(); # Koha::Patron::Messages->find($message_id);
60
    #- exit early if no message found matching message_id
61
    if (! defined $message) {
62
        no warnings qw/uninitialized/;
63
        return {
64
            %$result,
65
            comment        => "Couldn't find message for parameters",
66
            inputs => $inputs,
67
        };
68
    }
69
70
    #- found message, so success is TRUE
71
    $result->{success} = TRUE;
72
73
    #- exit early if patron_read_date is already set
74
    if (defined $message->patron_read_date) {
75
        return {
76
            %$result,
77
            comment => "Patron read date already set",
78
            inputs => $inputs,
79
        };
80
    }
81
82
    #- update the patron_read_date to database's NOW()
83
    $message->update({
84
        patron_read_date => \'NOW()',
85
    });
86
87
    my $patron_read_date = $message->patron_read_date || undef;
88
    return {
89
        %$result,
90
        inputs  => $inputs,
91
        comment => "Set patron_read_date to ($patron_read_date)",
92
    };
93
}
94
95
my CGI $cgi;
96
my $result;
97
try {
98
    $cgi = CGI->new;
99
    $result = dismiss_patron_message($cgi);
100
101
    # uncomment assignment below if you want to view environment
102
    # $result->{env} = \%ENV;
103
104
105
}
106
catch {
107
    my ($exception) = $_;
108
109
    # no warnings qw/once/;
110
    # my $ig = 'Examine variable $exception';
111
    # push @DB::typeahead, 'x $exception';
112
    # $DB::single++;
113
114
    $result->{exception} = $exception;
115
    $result->{success} = FALSE;
116
}
117
finally {
118
    # redirect to referrer
119
    my $redir_url = $ENV{HTTP_REFERRER} || REDIRECT_URL;
120
    print $cgi->redirect($redir_url);
121
};

Return to bug 12029