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

(-)a/Koha/Patron/Message/Preference.pm (-2 / +25 lines)
Lines 156-161 sub new_from_default { Link Here
156
    return $self;
156
    return $self;
157
}
157
}
158
158
159
=head3 message_name
160
161
$preference->message_name
162
163
Gets message_name for this messaging preference.
164
165
Setter not implemented.
166
167
=cut
168
169
sub message_name {
170
    my ($self) = @_;
171
172
    if ($self->{'_message_name'}) {
173
        return $self->{'_message_name'};
174
    }
175
    $self->{'_message_name'} = Koha::Patron::Message::Attributes->find({
176
        message_attribute_id => $self->message_attribute_id,
177
    })->message_name;
178
    return $self->{'_message_name'};
179
}
180
159
=head3 message_transport_types
181
=head3 message_transport_types
160
182
161
$preference->message_transport_types
183
$preference->message_transport_types
Lines 385-392 sub _validate_message_transport_types { Link Here
385
                    is_digest => $tmp->{'wants_digest'},
407
                    is_digest => $tmp->{'wants_digest'},
386
            })) {
408
            })) {
387
                Koha::Exceptions::BadParameter->throw(
409
                Koha::Exceptions::BadParameter->throw(
388
                    error => "Message transport option for '$type' (".
410
                    error => "Message transport option '$type' (".
389
                    ($tmp->{'wants_digest'} ? 'digest':'no digest').") does not exist",
411
                    ($tmp->{'wants_digest'} ? 'digest':'no digest').") for ".
412
                    $self->message_name . 'does not exist',
390
                    parameter => 'message_transport_type',
413
                    parameter => 'message_transport_type',
391
                );
414
                );
392
            }
415
            }
(-)a/Koha/Patron/Message/Preferences.pm (+55 lines)
Lines 20-25 package Koha::Patron::Message::Preferences; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Patron::Message::Attributes;
23
use Koha::Patron::Message::Preference;
24
use Koha::Patron::Message::Preference;
24
use Koha::Patron::Message::Transports;
25
use Koha::Patron::Message::Transports;
25
26
Lines 35-40 Koha::Patron::Message::Preferences - Koha Patron Message Preferences object clas Link Here
35
36
36
=cut
37
=cut
37
38
39
=head3 find_with_message_name
40
41
Koha::Patron::Message::Preferences->find_with_message_name({
42
    borrowernumber => 123,
43
    message_name => 'Hold_Filled',
44
});
45
46
Converts C<message_name> into C<message_attribute_id> and continues find.
47
48
=cut
49
50
sub find_with_message_name {
51
    my ($self, $id) = @_;
52
53
    if (ref($id) eq "HASH" && $id->{'message_name'}) {
54
        my $attr = Koha::Patron::Message::Attributes->find({
55
            message_name => $id->{'message_name'},
56
        });
57
        $id->{'message_attribute_id'} = ($attr) ?
58
                    $attr->message_attribute_id : undef;
59
        delete $id->{'message_name'};
60
    }
61
62
    return $self->SUPER::find($id);
63
}
64
38
=head3 get_options
65
=head3 get_options
39
66
40
my $messaging_options = Koha::Patron::Message::Preferences->get_options
67
my $messaging_options = Koha::Patron::Message::Preferences->get_options
Lines 69-74 sub get_options { Link Here
69
    return \@return;
96
    return \@return;
70
}
97
}
71
98
99
=head3 search
100
101
Koha::Patron::Message::Preferences->search_with_message_name({
102
    borrowernumber => 123,
103
    message_name => 'Hold_Filled',
104
});
105
106
Converts C<message_name> into C<message_attribute_id> and continues search. Use
107
Koha::Patron::Message::Preferences->search with a proper join for more complicated
108
searches.
109
110
=cut
111
112
sub search_with_message_name {
113
    my ($self, $params, $attributes) = @_;
114
115
    if (ref($params) eq "HASH" && $params->{'message_name'}) {
116
        my $attr = Koha::Patron::Message::Attributes->find({
117
            message_name => $params->{'message_name'},
118
        });
119
        $params->{'message_attribute_id'} = ($attr) ?
120
                    $attr->message_attribute_id : undef;
121
        delete $params->{'message_name'};
122
    }
123
124
    return $self->SUPER::search($params, $attributes);
125
}
126
72
=head3 type
127
=head3 type
73
128
74
=cut
129
=cut
(-)a/t/db_dependent/Koha/Patron/Message/Preferences.t (-3 / +21 lines)
Lines 19-26 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
22
use Test::More tests => 7;
23
use Test::More tests => 6;
24
23
25
use t::lib::Mocks;
24
use t::lib::Mocks;
26
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 320-325 subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub Link Here
320
    };
319
    };
321
};
320
};
322
321
322
subtest 'Test Koha::Patron::Message::Preference->message_name' => sub {
323
    plan tests => 1;
324
325
    $schema->storage->txn_begin;
326
327
    my $patron      = build_a_test_patron();
328
    my $attribute   = build_a_test_attribute();
329
    my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
330
        patron => $patron,
331
        attr   => $attribute,
332
    });
333
    my $message_name_pref = Koha::Patron::Message::Preferences->search_with_message_name({
334
        borrowernumber => $patron->{'borrowernumber'},
335
        message_name => $attribute->message_name,
336
    })->next;
337
    is($message_name_pref->message_name, $attribute->message_name, "Found preference with message_name");
338
339
    $schema->storage->txn_rollback;
340
};
341
323
subtest 'Test adding a new preference with invalid parameters' => sub {
342
subtest 'Test adding a new preference with invalid parameters' => sub {
324
    plan tests => 4;
343
    plan tests => 4;
325
344
326
- 

Return to bug 17499