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

(-)a/Koha/Patron/Message/Preference.pm (+22 lines)
Lines 154-159 sub new_from_default { Link Here
154
    return $self;
154
    return $self;
155
}
155
}
156
156
157
=head3 message_name
158
159
$preference->message_name
160
161
Gets message_name for this messaging preference.
162
163
Setter not implemented.
164
165
=cut
166
167
sub message_name {
168
    my ($self) = @_;
169
170
    if ($self->{'_message_name'}) {
171
        return $self->{'_message_name'};
172
    }
173
    $self->{'_message_name'} = Koha::Patron::Message::Attributes->find({
174
        message_attribute_id => $self->message_attribute_id,
175
    })->message_name;
176
    return $self->{'_message_name'};
177
}
178
157
=head3 message_transport_types
179
=head3 message_transport_types
158
180
159
$preference->message_transport_types
181
$preference->message_transport_types
(-)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 (-2 / +11 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 17;
22
use Test::More tests => 18;
23
23
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 351-356 subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub Link Here
351
    };
351
    };
352
};
352
};
353
353
354
subtest 'Test Koha::Patron::Message::Preference->message_name' => sub {
355
    plan tests => 1;
356
357
    my $message_name_pref = Koha::Patron::Message::Preferences->search_with_message_name({
358
        borrowernumber => $patron->{'borrowernumber'},
359
        message_name => $attribute->message_name,
360
    })->next;
361
    is($message_name_pref->message_name, $attribute->message_name, "Found preference with message_name");
362
};
363
354
$schema->storage->txn_rollback;
364
$schema->storage->txn_rollback;
355
365
356
1;
366
1;
357
- 

Return to bug 17499