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

(-)a/C4/Form/MessagingPreferences.pm (-2 / +3 lines)
Lines 24-29 use CGI qw ( -utf8 ); Link Here
24
use C4::Context;
24
use C4::Context;
25
use C4::Members::Messaging;
25
use C4::Members::Messaging;
26
use C4::Debug;
26
use C4::Debug;
27
use Koha::Patron::Message::Preferences;
27
28
28
use constant MAX_DAYS_IN_ADVANCE => 30;
29
use constant MAX_DAYS_IN_ADVANCE => 30;
29
30
Lines 73-79 adds a settings_updated template variable. Link Here
73
74
74
sub handle_form_action {
75
sub handle_form_action {
75
    my ($query, $target_params, $template, $insert, $categorycode) = @_;
76
    my ($query, $target_params, $template, $insert, $categorycode) = @_;
76
    my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
77
    my $messaging_options = Koha::Patron::Message::Preferences->get_options;
77
    # TODO: If a "NONE" box and another are checked somehow (javascript failed), we should pay attention to the "NONE" box
78
    # TODO: If a "NONE" box and another are checked somehow (javascript failed), we should pay attention to the "NONE" box
78
    my $prefs_set = 0;
79
    my $prefs_set = 0;
79
    OPTION: foreach my $option ( @$messaging_options ) {
80
    OPTION: foreach my $option ( @$messaging_options ) {
Lines 128-134 C<$template> is the Template::Toolkit object for the response. Link Here
128
sub set_form_values {
129
sub set_form_values {
129
    my ($target_params, $template) = @_;
130
    my ($target_params, $template) = @_;
130
    # walk through the options and update them with these borrower_preferences
131
    # walk through the options and update them with these borrower_preferences
131
    my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
132
    my $messaging_options = Koha::Patron::Message::Preferences->get_options;
132
    PREF: foreach my $option ( @$messaging_options ) {
133
    PREF: foreach my $option ( @$messaging_options ) {
133
        my $pref = C4::Members::Messaging::GetMessagingPreferences( { %{ $target_params }, message_name => $option->{'message_name'} } );
134
        my $pref = C4::Members::Messaging::GetMessagingPreferences( { %{ $target_params }, message_name => $option->{'message_name'} } );
134
        $option->{ $option->{'message_name'} } = 1;
135
        $option->{ $option->{'message_name'} } = 1;
(-)a/C4/Members/Messaging.pm (-39 / +1 lines)
Lines 21-28 use strict; Link Here
21
use warnings;
21
use warnings;
22
use C4::Context;
22
use C4::Context;
23
23
24
25
26
=head1 NAME
24
=head1 NAME
27
25
28
C4::Members::Messaging - manage patron messaging preferences
26
C4::Members::Messaging - manage patron messaging preferences
Lines 184-225 END_SQL Link Here
184
    return;    
182
    return;    
185
}
183
}
186
184
187
=head2 GetMessagingOptions
188
189
  my $messaging_options = C4::Members::Messaging::GetMessagingOptions()
190
191
returns a hashref of messaging options available.
192
193
=cut
194
195
sub GetMessagingOptions {
196
197
    my $sql = <<'END_SQL';
198
select message_attributes.message_attribute_id, takes_days, message_name, message_transport_type, is_digest
199
  FROM message_attributes
200
  LEFT JOIN message_transports
201
    ON message_attributes.message_attribute_id = message_transports.message_attribute_id
202
END_SQL
203
204
    my $sth = C4::Context->dbh->prepare($sql);
205
    $sth->execute();
206
    my $choices;
207
    while ( my $row = $sth->fetchrow_hashref() ) {
208
        $choices->{ $row->{'message_name'} }->{'message_attribute_id'} = $row->{'message_attribute_id'};
209
        $choices->{ $row->{'message_name'} }->{'message_name'}         = $row->{'message_name'};
210
        $choices->{ $row->{'message_name'} }->{'takes_days'}           = $row->{'takes_days'};
211
        $choices->{ $row->{'message_name'} }->{'has_digest'}           = 1 if $row->{'is_digest'};
212
        $choices->{ $row->{'message_name'} }->{'transport_' . $row->{'message_transport_type'}} = ' ';
213
    }
214
215
    my @return = values %$choices;
216
217
    @return = sort { $a->{message_attribute_id} <=> $b->{message_attribute_id} } @return;
218
219
    # warn( Data::Dumper->Dump( [ \@return ], [ 'return' ] ) );
220
    return \@return;
221
}
222
223
=head2 SetMessagingPreferencesFromDefaults
185
=head2 SetMessagingPreferencesFromDefaults
224
186
225
  C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { borrowernumber => $borrower->{'borrowernumber'}
187
  C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { borrowernumber => $borrower->{'borrowernumber'}
Lines 240-246 sub SetMessagingPreferencesFromDefaults { Link Here
240
        }
202
        }
241
    }
203
    }
242
204
243
    my $messaging_options = GetMessagingOptions();
205
    my $messaging_options = Koha::Patron::Message::Preferences->get_options;
244
    OPTION: foreach my $option ( @$messaging_options ) {
206
    OPTION: foreach my $option ( @$messaging_options ) {
245
        my $default_pref = GetMessagingPreferences( { categorycode => $params->{categorycode},
207
        my $default_pref = GetMessagingPreferences( { categorycode => $params->{categorycode},
246
                                                      message_name => $option->{'message_name'} } );
208
                                                      message_name => $option->{'message_name'} } );
(-)a/Koha/Patron/Category.pm (-1 / +2 lines)
Lines 23-28 use C4::Members::Messaging; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::DateUtils;
25
use Koha::DateUtils;
26
use Koha::Patron::Message::Preferences;
26
27
27
use base qw(Koha::Object);
28
use base qw(Koha::Object);
28
29
Lines 79-85 my $messaging = $category->default_messaging(); Link Here
79
80
80
sub default_messaging {
81
sub default_messaging {
81
    my ( $self ) = @_;
82
    my ( $self ) = @_;
82
    my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
83
    my $messaging_options = Koha::Patron::Message::Preferences->get_options;
83
    my @messaging;
84
    my @messaging;
84
    foreach my $option (@$messaging_options) {
85
    foreach my $option (@$messaging_options) {
85
        my $pref = C4::Members::Messaging::GetMessagingPreferences(
86
        my $pref = C4::Members::Messaging::GetMessagingPreferences(
(-)a/opac/opac-messaging.pl (-2 lines)
Lines 51-57 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
51
);
51
);
52
52
53
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
53
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
54
my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
55
54
56
if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) {
55
if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) {
57
    my $sms = $query->param('SMSnumber');
56
    my $sms = $query->param('SMSnumber');
58
- 

Return to bug 18595