1 package Koha::Patron::MessagePreferences;
3 # Copyright Koha-Suomi Oy 2016
5 # This file is part of Koha.
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.
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.
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>.
23 use Koha::Patron::MessagePreference::Attributes;
24 use Koha::Patron::MessagePreference;
25 use Koha::Patron::MessagePreference::Transports;
27 use base qw(Koha::Objects);
31 Koha::Patron::MessagePreferences - Koha Patron Message Preferences object class
39 =head3 find_with_message_name
41 Koha::Patron::MessagePreferences->find_with_message_name({
42 borrowernumber => 123,
43 message_name => 'Hold_Filled',
46 Converts C<message_name> into C<message_attribute_id> and continues find.
50 sub find_with_message_name {
53 if (ref($id) eq "HASH" && $id->{'message_name'}) {
54 my $attr = Koha::Patron::MessagePreference::Attributes->find({
55 message_name => $id->{'message_name'},
57 $id->{'message_attribute_id'} = ($attr) ?
58 $attr->message_attribute_id : undef;
59 delete $id->{'message_name'};
62 return $self->SUPER::find($id);
67 my $messaging_options = Koha::Patron::MessagePreferences->get_options
69 Returns an ARRAYref of HASHrefs on available messaging options.
76 my $transports = Koha::Patron::MessagePreference::Transports->search(undef,
78 join => ['message_attribute'],
79 '+select' => ['message_attribute.message_name', 'message_attribute.takes_days'],
80 '+as' => ['message_name', 'takes_days'],
84 while (my $transport = $transports->next) {
85 my $name = $transport->get_column('message_name');
86 $choices->{$name}->{'message_attribute_id'} = $transport->message_attribute_id;
87 $choices->{$name}->{'message_name'} = $name;
88 $choices->{$name}->{'takes_days'} = $transport->get_column('takes_days');
89 $choices->{$name}->{'has_digest'} ||= 1 if $transport->is_digest;
90 $choices->{$name}->{'has_digest_off'} ||= 1 if !$transport->is_digest;
91 $choices->{$name}->{'transport_'.$transport->get_column('message_transport_type')} = ' ';
94 my @return = values %$choices;
95 @return = sort { $a->{message_attribute_id} <=> $b->{message_attribute_id} } @return;
100 =head3 search_with_message_name
102 Koha::Patron::MessagePreferences->search_with_message_name({
103 borrowernumber => 123,
104 message_name => 'Hold_Filled',
107 Converts C<message_name> into C<message_attribute_id> and continues search. Use
108 Koha::Patron::MessagePreferences->search with a proper join for more complicated
113 sub search_with_message_name {
114 my ($self, $params, $attributes) = @_;
116 if (ref($params) eq "HASH" && $params->{'message_name'}) {
117 my $attr = Koha::Patron::MessagePreference::Attributes->find({
118 message_name => $params->{'message_name'},
120 $params->{'message_attribute_id'} = ($attr) ?
121 $attr->message_attribute_id : undef;
122 delete $params->{'message_name'};
125 return $self->SUPER::search($params, $attributes);
133 return 'BorrowerMessagePreference';
141 return 'Koha::Patron::MessagePreference';
146 Lari Taskula <lari.taskula@hypernova.fi>