From 4afc8550c6a612f64bb8c9c5781399d0db549fc1 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 9 Feb 2016 15:45:55 +0000 Subject: [PATCH] Bug 9021 [QA Followup] - Switch to Koha::Object(s) Signed-off-by: Mark Tompsett Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- C4/Letters.pm | 4 +- Koha/SMS/Provider.pm | 132 ++++------------------------------------- Koha/SMS/Providers.pm | 60 +++++++++++++++++++ admin/sms_providers.pl | 22 +++++-- members/memberentry.pl | 4 +- opac/opac-messaging.pl | 3 +- 6 files changed, 96 insertions(+), 129 deletions(-) create mode 100644 Koha/SMS/Providers.pm diff --git a/C4/Letters.pm b/C4/Letters.pm index 99a39d447a..7b3261bb32 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -31,7 +31,7 @@ use C4::Log; use C4::SMS; use C4::Debug; use Koha::DateUtils; -use Koha::SMS::Provider; +use Koha::SMS::Providers; use Date::Calc qw( Add_Delta_Days ); use Encode; @@ -987,7 +987,7 @@ sub SendQueuedMessages { elsif ( lc( $message->{'message_transport_type'} ) eq 'sms' ) { if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) { my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); - my $sms_provider = Koha::SMS::Provider->find( $member->{'sms_provider_id'} ); + my $sms_provider = Koha::SMS::Providers->find( $member->{'sms_provider_id'} ); $message->{to_address} .= '@' . $sms_provider->domain(); _send_message_by_email( $message, $params->{'username'}, $params->{'password'}, $params->{'method'} ); } else { diff --git a/Koha/SMS/Provider.pm b/Koha/SMS/Provider.pm index 6331088eaf..1aa70dcada 100644 --- a/Koha/SMS/Provider.pm +++ b/Koha/SMS/Provider.pm @@ -1,6 +1,6 @@ package Koha::SMS::Provider; -# Copyright 2012 ByWater Solutions +# Copyright ByWater Solutions 2016 # # This file is part of Koha. # @@ -17,141 +17,35 @@ package Koha::SMS::Provider; # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -=head1 NAME - -Koha::SMS::Provider - class to manage sms providers - -=head1 SYNOPSIS - -Object-oriented class that encapsulates sms providers in Koha. - -=head1 DESCRIPTION - -SMS::Provider data. - -=cut - use Modern::Perl; -use C4::Context; - -use base qw(Class::Accessor); - -__PACKAGE__->mk_accessors(qw( id name domain )); - -=head2 new - - my $provider = Koha::SMS::Provider->new($data); - -Create a new Koha::SMS::Provider object based on the provided record. - -=cut - -sub new { - my $class = shift; - my $data = shift; - - my $self = $class->SUPER::new($data); - - bless $self, $class; - return $self; -} - -=head2 store - - Creates or updates the object in the database - -=cut - -sub store { - my $self = shift; - - if ( $self->id ) { - return C4::Context->dbh->do( "UPDATE sms_providers SET name = ?, domain = ? WHERE id = ?", undef, ( $self->name, $self->domain, $self->id ) ); - } else { - return C4::Context->dbh->do( "INSERT INTO sms_providers ( name, domain ) VALUES ( ?, ? )", undef, ( $self->name, $self->domain ) ); - } -} - -=head2 delete +use Carp; -=cut +use base qw(Koha::Object); -sub delete { - my $self = shift; +=head1 NAME - return C4::Context->dbh->do( "DELETE FROM sms_providers WHERE id = ?", undef, ( $self->id ) ); -} +Koha::Biblio - Koha Biblio Object class +Koha::SMS::Provider - Koha SMS Provider object class -=head2 all +=head1 API - my $providers = Koha::SMS::Provider->all(); +=head2 Class Methods =cut -sub all { - my $class = shift; - - my $query = "SELECT * FROM sms_providers ORDER BY name"; - my $sth = C4::Context->dbh->prepare($query); - $sth->execute(); - - my @providers; - while ( my $row = $sth->fetchrow_hashref() ) { - my $p = Koha::SMS::Provider->new($row); - push( @providers, $p ); - } - - return @providers; -} - -=head2 find - - my $provider = Koha::SMS::Provider->find( $id ); +=head3 type =cut -sub find { - my $class = shift; - my $id = shift; - - my $query = "SELECT * FROM sms_providers WHERE ID = ?"; - my $sth = C4::Context->dbh->prepare($query); - $sth->execute($id); - - my $row = $sth->fetchrow_hashref(); - my $p = Koha::SMS::Provider->new($row); - - return $p; +sub type { + return 'SmsProvider'; } -=head2 search +=head1 AUTHOR - my @providers = Koha::SMS::Provider->search({ [name => $name], [domain => $domain] }); +Kyle M Hall =cut -sub search { - my $class = shift; - my $params = shift; - - my $query = "SELECT * FROM sms_providers WHERE "; - - my @params = map( $params->{$_}, keys %$params ); - $query .= join( " AND ", map( "$_ = ?", keys %$params ) ); - - $query .= " ORDER BY name"; - - my $sth = C4::Context->dbh->prepare($query); - $sth->execute(@params); - - my @providers; - while ( my $row = $sth->fetchrow_hashref() ) { - my $p = Koha::SMS::Provider->new($row); - push( @providers, $p ); - } - - return @providers; -} - 1; diff --git a/Koha/SMS/Providers.pm b/Koha/SMS/Providers.pm new file mode 100644 index 0000000000..0a89878f9c --- /dev/null +++ b/Koha/SMS/Providers.pm @@ -0,0 +1,60 @@ +package Koha::SMS::Providers; + +# Copyright ByWater Solutions 2016 +# +# 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 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. +# +# 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. + +use Modern::Perl; + +use Carp; + +use Koha::SMS::Provider; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::SMS::Providers - Koha SMS Provider object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'SmsProvider'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::SMS::Provider'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/admin/sms_providers.pl b/admin/sms_providers.pl index bdc934997f..4592acf8f8 100755 --- a/admin/sms_providers.pl +++ b/admin/sms_providers.pl @@ -26,11 +26,13 @@ use C4::Auth; use C4::Output; use Koha::SMS::Provider; +use Koha::SMS::Providers; my $cgi = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { template_name => "admin/sms_providers.tt", + { + template_name => "admin/sms_providers.tt", query => $cgi, type => "intranet", authnotrequired => 0, @@ -46,13 +48,23 @@ my $domain = $cgi->param('domain'); if ( $op eq 'add_update' ) { if ( $name && $domain ) { - Koha::SMS::Provider->new( { id => $id, name => $name, domain => $domain } )->store(); + if ($id) { + my $provider = Koha::SMS::Providers->find($id); + $provider->set( { name => $name, domain => $domain } )->store() + if $provider; + } + else { + Koha::SMS::Provider->new( { name => $name, domain => $domain } ) + ->store(); + } } -} elsif ( $op eq 'delete' ) { - Koha::SMS::Provider->find($id)->delete(); +} +elsif ( $op eq 'delete' ) { + my $provider = Koha::SMS::Providers->find($id); + $provider->delete() if $provider; } -my @providers = Koha::SMS::Provider->all(); +my @providers = Koha::SMS::Providers->search(); $template->param( providers => \@providers ); diff --git a/members/memberentry.pl b/members/memberentry.pl index 48ea65ee8a..49516143d3 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -46,7 +46,7 @@ use Module::Load; if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { load Koha::NorwegianPatronDB, qw( NLGetSyncDataFromBorrowernumber ); } -use Koha::SMS::Provider; +use Koha::SMS::Providers; use vars qw($debug); @@ -70,7 +70,7 @@ my ($template, $loggedinuser, $cookie) }); if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) { - my @providers = Koha::SMS::Provider->all(); + my @providers = Koha::SMS::Providers->search(); $template->param( sms_providers => \@providers ); } diff --git a/opac/opac-messaging.pl b/opac/opac-messaging.pl index 6fe18a7c5f..3ea529e650 100755 --- a/opac/opac-messaging.pl +++ b/opac/opac-messaging.pl @@ -31,6 +31,7 @@ use C4::Members; use C4::Members::Messaging; use C4::Branch; use C4::Form::MessagingPreferences; +use Koha::SMS::Providers; my $query = CGI->new(); @@ -70,7 +71,7 @@ $template->param( BORROWER_INFO => $borrower, TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification") ); if ( C4::Context->preference("SMSSendDriver") eq 'Email' ) { - my @providers = Koha::SMS::Provider->all(); + my @providers = Koha::SMS::Providers->search(); $template->param( sms_providers => \@providers, sms_provider_id => $borrower->{'sms_provider_id'} ); } -- 2.39.5