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

(-)a/Koha/Patron/Message/Preferences.pm (+35 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Patron::Message::Preference;
23
use Koha::Patron::Message::Preference;
24
use Koha::Patron::Message::Transports;
24
25
25
use base qw(Koha::Objects);
26
use base qw(Koha::Objects);
26
27
Lines 34-39 Koha::Patron::Message::Preferences - Koha Patron Message Preferences object clas Link Here
34
35
35
=cut
36
=cut
36
37
38
=head3 get_options
39
40
my $messaging_options = Koha::Patron::Message::Preferences->get_options
41
42
Returns an ARRAYref of HASHrefs on available messaging options.
43
44
=cut
45
46
sub get_options {
47
    my ($self) = @_;
48
49
    my $transports = Koha::Patron::Message::Transports->search(undef,
50
        {
51
            join => ['message_attribute'],
52
            '+select' => ['message_attribute.message_name', 'message_attribute.takes_days'],
53
            '+as' => ['message_name', 'takes_days'],
54
        });
55
56
    my $choices;
57
    while (my $transport = $transports->next) {
58
        my $name = $transport->get_column('message_name');
59
        $choices->{$name}->{'message_attribute_id'} = $transport->message_attribute_id;
60
        $choices->{$name}->{'message_name'}         = $name;
61
        $choices->{$name}->{'takes_days'}           = $transport->get_column('takes_days');
62
        $choices->{$name}->{'has_digest'}           = 1 if $transport->is_digest;
63
        $choices->{$name}->{'transport_'.$transport->get_column('message_transport_type')} = ' ';
64
    }
65
66
    my @return = values %$choices;
67
    @return = sort { $a->{message_attribute_id} <=> $b->{message_attribute_id} } @return;
68
69
    return \@return;
70
}
71
37
=head3 type
72
=head3 type
38
73
39
=cut
74
=cut
(-)a/t/db_dependent/Koha/Patron/Message/Preferences.t (-2 / +33 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 15;
22
use Test::More tests => 16;
23
23
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 56-61 my $preference; Link Here
56
my $transport_preference;
56
my $transport_preference;
57
my $transport_type;
57
my $transport_type;
58
58
59
subtest 'Test Koha::Patron::Message::Preferences->get_options' => sub {
60
    plan tests => 5;
61
62
    ok(Koha::Patron::Message::Preferences->can('get_options'),
63
       "Method get_options is available");
64
    ok(my $options = Koha::Patron::Message::Preferences->get_options,
65
       "Called get_options successfully");
66
    is(ref $options, "ARRAY", "get_options returns a HASHref");
67
    my $message_attributes = Koha::Patron::Message::Attributes->search;
68
    is(@$options, $message_attributes->count, "There are equal amount of"
69
       ." options and message attributes");
70
71
    subtest 'Make sure options are correct' => sub {
72
        foreach my $option (@$options) {
73
            my $n = $option->{'message_name'};
74
            my $attr = Koha::Patron::Message::Attributes->find($option->{'message_attribute_id'});
75
            is($option->{'message_attribute_id'}, $attr->message_attribute_id,
76
               "$n: message_attribute_id is set");
77
            is($option->{'message_name'}, $attr->message_name, "$n: message_name is set");
78
            is($option->{'takes_days'}, $attr->takes_days, "$n: takes_days is set");
79
            my $transports = Koha::Patron::Message::Transports->search({
80
                message_attribute_id => $option->{'message_attribute_id'},
81
                is_digest => $option->{'has_digest'} || 0,
82
            });
83
            while (my $trnzport = $transports->next) {
84
                is($option->{'has_digest'} || 0, $trnzport->is_digest, "$n: has_digest is set for ".$trnzport->message_transport_type);
85
                is($option->{'transport_'.$trnzport->message_transport_type}, ' ', "$n: transport_".$trnzport->message_transport_type." is set");
86
            }
87
        }
88
    };
89
};
90
59
subtest 'Add a test messaging transport type' => sub {
91
subtest 'Add a test messaging transport type' => sub {
60
    plan tests => 2;
92
    plan tests => 2;
61
93
62
- 

Return to bug 17499