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

(-)a/Koha/Patron.pm (+27 lines)
Lines 2063-2068 sub recalls { Link Here
2063
    return Koha::Recalls->search({ borrowernumber => $self->borrowernumber });
2063
    return Koha::Recalls->search({ borrowernumber => $self->borrowernumber });
2064
}
2064
}
2065
2065
2066
=head3 has_messaging_preference
2067
2068
my $bool = $patron->has_messaging_preference({
2069
    message_name => $message_name, # A value from message_attributes.message_name
2070
    message_transport_type => $message_transport_type, # email, sms, phone, itiva, etc...
2071
    wants_digest => $wants_digest, # 1 if you are looking for the digest version, don't pass if you just want either
2072
});
2073
2074
=cut
2075
2076
sub has_messaging_preference {
2077
    my ( $self, $params ) = @_;
2078
2079
    my $message_name           = $params->{message_name};
2080
    my $message_transport_type = $params->{message_transport_type};
2081
    my $wants_digest           = $params->{wants_digest};
2082
2083
    return $self->_result->search_related_rs(
2084
        'borrower_message_preferences',
2085
        $params,
2086
        {
2087
            prefetch =>
2088
              [ 'borrower_message_transport_preferences', 'message_attribute' ]
2089
        }
2090
    )->count;
2091
}
2092
2066
=head2 Internal methods
2093
=head2 Internal methods
2067
2094
2068
=head3 _type
2095
=head3 _type
(-)a/t/db_dependent/Patron/Messaging.t (-1 / +137 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# This file is part of Koha.
4
#
5
# Copyright (C) 2018  Andreas Jonsson <andreas.jonsson@kreablo.se>
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 Test::More tests => 1;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
25
use File::Spec;
26
use File::Basename;
27
28
use Koha::DateUtils qw( dt_from_string );
29
30
my $schema = Koha::Database->new->schema;
31
my $dbh    = C4::Context->dbh;
32
33
my $library;
34
my $borrower;
35
36
subtest 'Default behaviour tests' => sub {
37
38
    plan tests => 3;
39
40
    $schema->storage->txn_begin;
41
42
    # Set only to avoid exception.
43
    t::lib::Mocks::mock_preference( 'dateformat', 'metric' );
44
45
    my $builder = t::lib::TestBuilder->new;
46
47
    $library = $builder->build(
48
        {
49
            source => 'Branch',
50
        }
51
    );
52
53
    $borrower = $builder->build(
54
        {
55
            source => 'Borrower',
56
            value  => {
57
                branchcode => $library->{branchcode},
58
            }
59
        }
60
    );
61
62
    $dbh->do(<<DELETESQL);
63
DELETE FROM letter
64
 WHERE module='circulation'
65
   AND code = 'PREDUEDGST'
66
   AND message_transport_type='email'
67
   AND branchcode=''
68
DELETESQL
69
70
    $dbh->do(<<DELETESQL);
71
DELETE FROM message_attributes WHERE message_name = 'Advance_Notice'
72
DELETESQL
73
74
    my $message_attribute = $builder->build(
75
        {
76
            source => 'MessageAttribute',
77
            value  => {
78
                message_name => 'Advance_Notice'
79
            }
80
        }
81
    );
82
83
    my $letter = $builder->build(
84
        {
85
            source => 'Letter',
86
            value  => {
87
                module                 => 'circulation',
88
                code                   => 'PREDUEDGST',
89
                branchcode             => '',
90
                message_transport_type => 'email',
91
                lang                   => 'default',
92
                is_html                => 0,
93
                content                => '<<count>> <<branches.branchname>>'
94
            }
95
        }
96
    );
97
    my $borrower_message_preference = $builder->build(
98
        {
99
            source => 'BorrowerMessagePreference',
100
            value  => {
101
                borrowernumber  => $borrower->{borrowernumber},
102
                wants_digest    => 1,
103
                days_in_advance => 1,
104
                message_attribute_id =>
105
                  $message_attribute->{message_attribute_id}
106
            }
107
        }
108
    );
109
110
    my $borrower_message_transport_preference = $builder->build(
111
        {
112
            source => 'BorrowerMessageTransportPreference',
113
            value  => {
114
                borrower_message_preference_id => $borrower_message_preference
115
                  ->{borrower_message_preference_id},
116
                message_transport_type => 'email'
117
            }
118
        }
119
    );
120
121
    my $borrower_message_transport_preference_1 = $builder->build(
122
        {
123
            source => 'BorrowerMessageTransportPreference',
124
            value  => {
125
                borrower_message_preference_id => $borrower_message_preference
126
                  ->{borrower_message_preference_id},
127
                message_transport_type => 'phone'
128
            }
129
        }
130
    );
131
132
    my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
133
134
    is( $patron->has_messaging_preference({ message_name => 'Advance_Notice', message_transport_type => 'email' }), 1, "Patron has Advance_Notice email preference" );
135
    is( $patron->has_messaging_preference({ message_name => 'Advance_Notice', message_transport_type => 'phone' }), 1, "Patron has Advance_Notice phone preference" );
136
    is( $patron->has_messaging_preference({ message_name => 'Advance_Notice', message_transport_type => 'sms' }), 0, "Patron has no Advance_Notice sms preference" );
137
};

Return to bug 30076