Commit 4afc8550 authored by Kyle M Hall's avatar Kyle M Hall

Bug 9021 [QA Followup] - Switch to Koha::Object(s)

Signed-off-by: Mark Tompsett's avatarMark Tompsett <mtompset@hotmail.com>
Signed-off-by: joubu's avatarJonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: default avatarKyle M Hall <kyle@bywatersolutions.com>
parent 7178c7c0
......@@ -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 {
......
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 <kyle@bywatersolutions.com>
=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;
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 <kyle@bywatersolutions.com>
=cut
1;
......@@ -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 );
......
......@@ -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 );
}
......
......@@ -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'} );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment