Bug 16011: $VERSION - remove use vars $VERSION
[koha_ffzg] / C4 / Members / Messaging.pm
index 7f7464c..72d942d 100644 (file)
@@ -4,28 +4,28 @@ package C4::Members::Messaging;
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use strict;
 use warnings;
 use C4::Context;
 
-use vars qw($VERSION);
+use vars qw();
 
 BEGIN {
     # set the version for version checking
-    $VERSION = 3.00;
+    $VERSION = 3.07.00.049;
 }
 
 =head1 NAME
@@ -61,21 +61,23 @@ sub GetMessagingPreferences {
 
     return unless exists $params->{message_name};
     return unless exists $params->{borrowernumber} xor exists $params->{categorycode}; # yes, xor
-
     my $sql = <<'END_SQL';
 SELECT borrower_message_preferences.*,
        borrower_message_transport_preferences.message_transport_type,
-       message_attributes.*,
-       message_transports.*
-  FROM borrower_message_preferences
-  LEFT JOIN borrower_message_transport_preferences
-    ON borrower_message_transport_preferences.borrower_message_preference_id = borrower_message_preferences.borrower_message_preference_id
-  LEFT JOIN message_attributes
-    ON message_attributes.message_attribute_id = borrower_message_preferences.message_attribute_id
-  LEFT JOIN message_transports
-    ON message_transports.message_attribute_id = message_attributes.message_attribute_id
-    AND message_transports.message_transport_type = borrower_message_transport_preferences.message_transport_type
-  WHERE message_attributes.message_name = ?
+       message_attributes.message_name,
+       message_attributes.takes_days,
+       message_transports.is_digest,
+       message_transports.letter_module,
+       message_transports.letter_code
+FROM   borrower_message_preferences
+LEFT JOIN borrower_message_transport_preferences
+ON     borrower_message_transport_preferences.borrower_message_preference_id = borrower_message_preferences.borrower_message_preference_id
+LEFT JOIN message_attributes
+ON     message_attributes.message_attribute_id = borrower_message_preferences.message_attribute_id
+LEFT JOIN message_transports
+ON     message_transports.message_attribute_id = message_attributes.message_attribute_id
+AND    message_transports.message_transport_type = borrower_message_transport_preferences.message_transport_type
+WHERE  message_attributes.message_name = ?
 END_SQL
 
     my @bind_params = ( $params->{'message_name'} );
@@ -93,13 +95,12 @@ END_SQL
     my %transports; # helps build a list of unique message_transport_types
     ROW: while ( my $row = $sth->fetchrow_hashref() ) {
         next ROW unless $row->{'message_attribute_id'};
-        # warn( Data::Dumper->Dump( [ $row ], [ 'row' ] ) );
         $return->{'days_in_advance'} = $row->{'days_in_advance'} if defined $row->{'days_in_advance'};
         $return->{'wants_digest'}    = $row->{'wants_digest'}    if defined $row->{'wants_digest'};
-               $return->{'letter_code'}     = $row->{'letter_code'};
-        $transports{$row->{'message_transport_type'}} = 1;
+        $return->{'letter_code'}     = $row->{'letter_code'};
+        next unless defined $row->{'message_transport_type'};
+        $return->{'transports'}->{ $row->{'message_transport_type'} } = $row->{'letter_code'};
     }
-    @{$return->{'transports'}} = keys %transports;
     return $return;
 }
 
@@ -212,17 +213,20 @@ END_SQL
         $choices->{ $row->{'message_name'} }->{'message_name'}         = $row->{'message_name'};
         $choices->{ $row->{'message_name'} }->{'takes_days'}           = $row->{'takes_days'};
         $choices->{ $row->{'message_name'} }->{'has_digest'}           = 1 if $row->{'is_digest'};
-        $choices->{ $row->{'message_name'} }->{'transport-' . $row->{'message_transport_type'}} = ' ';
+        $choices->{ $row->{'message_name'} }->{'transport_' . $row->{'message_transport_type'}} = ' ';
     }
 
     my @return = values %$choices;
+
+    @return = sort { $a->{message_attribute_id} <=> $b->{message_attribute_id} } @return;
+
     # warn( Data::Dumper->Dump( [ \@return ], [ 'return' ] ) );
     return \@return;
 }
 
 =head2 SetMessagingPreferencesFromDefaults
 
-  C4::Members::Messaging::SetMessagingPreferenceFromDefaults( { borrowernumber => $borrower->{'borrowernumber'}
+  C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { borrowernumber => $borrower->{'borrowernumber'}
                                                                 categorycode   => 'CPL' } );
 
 Given a borrowernumber and a patron category code (from the C<borrowernumber> and C<categorycode> keys
@@ -247,8 +251,9 @@ sub SetMessagingPreferencesFromDefaults {
         # FIXME - except for setting the borrowernumber, it really ought to be possible
         # to have the output of GetMessagingPreferences be able to be the input
         # to SetMessagingPreference
+        my @message_transport_types = keys %{ $default_pref->{transports} };
         $default_pref->{message_attribute_id}    = $option->{'message_attribute_id'};
-        $default_pref->{message_transport_types} = $default_pref->{transports};
+        $default_pref->{message_transport_types} = \@message_transport_types;
         $default_pref->{borrowernumber}          = $params->{borrowernumber};
         SetMessagingPreference( $default_pref );
     }
@@ -307,7 +312,7 @@ L<C4::Letters>
 
 =head1 AUTHOR
 
-Koha Development Team <info@koha.org>
+Koha Development Team <http://koha-community.org/>
 
 Andrew Moore <andrew.moore@liblime.com>