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

(-)a/Koha/Patron/Messages.pm (-16 / +2 lines)
Lines 50-62 sub object_class { Link Here
50
    return 'Koha::Patron::Message';
50
    return 'Koha::Patron::Message';
51
}
51
}
52
52
53
=head3 unread
53
=head3 filter_by_unread
54
54
55
    Returns a result set of messages that haven't been marked read by the patron
55
    Returns a result set of messages that haven't been marked read by the patron
56
56
57
=cut
57
=cut
58
58
59
sub unread {
59
sub filter_by_unread {
60
    # return resultset of messages with an undefined patron_read_date
60
    # return resultset of messages with an undefined patron_read_date
61
    my ($self, $params) = @_;
61
    my ($self, $params) = @_;
62
    $params ||= {};
62
    $params ||= {};
Lines 65-82 sub unread { Link Here
65
        %$params,
65
        %$params,
66
    });
66
    });
67
}
67
}
68
69
=head3 unread_count
70
71
    Returns a count of messages that haven't been marked read by the patron
72
73
=cut
74
75
76
sub unread_count {
77
    # return count of unread
78
    my ($self, $params) = @_;
79
    $params ||= {};
80
    return $self->unread(%$params)->count();
81
}
82
1;
68
1;
(-)a/installer/data/mysql/atomicupdate/bug_12029.pl (-1 / +1 lines)
Lines 8-14 return { Link Here
8
        my ($dbh, $out) = @$args{qw(dbh out)};
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
9
10
        # Do you stuffs here
10
        # Do you stuffs here
11
        my $alteration = qq{
11
        my $alteration = q{
12
            ALTER TABLE messages
12
            ALTER TABLE messages
13
            ADD COLUMN `patron_read_date` timestamp NULL DEFAULT NULL
13
            ADD COLUMN `patron_read_date` timestamp NULL DEFAULT NULL
14
            COMMENT 'date and time patron dismissed message'
14
            COMMENT 'date and time patron dismissed message'
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc (-2 / +2 lines)
Lines 1-8 Link Here
1
[% IF patron_messages.unread_count OR opacnote %]
1
[% IF patron_messages.filter_by_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.unread %]
5
            [% FOREACH message IN patron_messages.filter_by_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>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt (-3 / +3 lines)
Lines 263-269 Link Here
263
                                            </a>
263
                                            </a>
264
                                        </li>
264
                                        </li>
265
                                    [% END %]
265
                                    [% END %]
266
                                    [% IF patron_messages && patron_messages.unread_count || opacnote %]
266
                                    [% IF patron_messages && patron_messages.filter_by_unread.count || opacnote %]
267
                                        [% IF opacnote %]
267
                                        [% IF opacnote %]
268
                                            <li>
268
                                            <li>
269
                                                <a href="/cgi-bin/koha/opac-user.pl">
269
                                                <a href="/cgi-bin/koha/opac-user.pl">
Lines 274-281 Link Here
274
                                        [% ELSE %]
274
                                        [% ELSE %]
275
                                            <li>
275
                                            <li>
276
                                                <a href="/cgi-bin/koha/opac-user.pl">
276
                                                <a href="/cgi-bin/koha/opac-user.pl">
277
                                                    <span class="count_label">[% patron_messages.unread_count | html %]</span>
277
                                                    <span class="count_label">[% patron_messages.filter_by_unread.count | html %]</span>
278
                                                    [% tn('message', 'messages', patron_messages.unread_count ) | html %]
278
                                                    [% tn('message', 'messages', patron_messages.filter_by_unread.count ) | html %]
279
                                                </a>
279
                                                </a>
280
                                            </li>
280
                                            </li>
281
                                        [% END %]
281
                                        [% END %]
(-)a/opac/dismiss_message.pl (-2 / +3 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
# This file is part of Koha.
3
#
4
# Copyright (C) 2022 Auto-Parallel Technologies, Inc.
2
# Copyright (C) 2022 Auto-Parallel Technologies, Inc.
3
4
#
5
# This file is part of Koha.
5
#
6
#
6
# Koha is free software; you can redistribute it and/or modify it
7
# Koha is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License as published by
8
# under the terms of the GNU General Public License as published by
(-)a/t/db_dependent/Koha/Patron/Messages.t (-7 / +6 lines)
Lines 100-106 is( Koha::Patron::Messages->search->count, $nb_of_messages + 1, 'Delete should h Link Here
100
is( get_nb_of_logactions(), $nb_of_logaction + 3, 'With BorrowersLog on, 1 new log should have been added when deleting a new message' );
100
is( get_nb_of_logactions(), $nb_of_logaction + 3, 'With BorrowersLog on, 1 new log should have been added when deleting a new message' );
101
101
102
# START BUG-12029
102
# START BUG-12029
103
my $starting_unread_count = Koha::Patron::Messages->unread_count();
103
my $starting_unread_count = Koha::Patron::Messages->filter_by_unread()->count();
104
104
105
my $new_message_4 = Koha::Patron::Message->new(
105
my $new_message_4 = Koha::Patron::Message->new(
106
    {
106
    {
Lines 113-129 my $new_message_4 = Koha::Patron::Message->new( Link Here
113
)->store;
113
)->store;
114
114
115
is(
115
is(
116
    Koha::Patron::Messages->unread_count(),
116
    Koha::Patron::Messages->filter_by_unread()->count(),
117
    $starting_unread_count + 1,
117
    $starting_unread_count + 1,
118
    "Unread count should return a new count one higher"
118
    "Unread count should return a new count one higher"
119
);
119
);
120
is(
120
is(
121
    Koha::Patron::Messages->unread->count(),
121
    Koha::Patron::Messages->filter_by_unread()->count(),
122
    $starting_unread_count + 1,
122
    $starting_unread_count + 1,
123
    "Unread should be able to have count called on it and return the same number"
123
    "Unread should be able to have count called on it and return the same number"
124
);
124
);
125
125
126
ok( ( grep { $_->message eq $new_message_4->message } @{ Koha::Patron::Messages->unread->as_list } ),
126
ok( ( grep { $_->message eq $new_message_4->message } @{ Koha::Patron::Messages->filter_by_unread()->as_list() } ),
127
    "Unread should return our new_message_4" );
127
    "Unread should return our new_message_4" );
128
128
129
# Set a message to be read
129
# Set a message to be read
Lines 133-140 $new_message_4->update( Link Here
133
    }
133
    }
134
);
134
);
135
135
136
is( Koha::Patron::Messages->unread_count(),
136
is( Koha::Patron::Messages->filter_by_unread()->count(),
137
    $starting_unread_count, "Unread count should return the original count of messages" );
137
    $starting_unread_count, "Unread count should return the original count of messages (run dbic if this fails)." );
138
# END BUG-12029
138
# END BUG-12029
139
139
140
140
141
- 

Return to bug 12029