1 package Koha::SMS::Provider;
3 # Copyright 2012 ByWater Solutions
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 Koha::SMS::Provider - class to manage sms providers
26 Object-oriented class that encapsulates sms providers in Koha.
38 use base qw(Class::Accessor);
40 __PACKAGE__->mk_accessors(qw( id name domain ));
44 my $provider = Koha::SMS::Provider->new($data);
46 Create a new Koha::SMS::Provider object based on the provided record.
54 my $self = $class->SUPER::new($data);
62 Creates or updates the object in the database
70 return C4::Context->dbh->do( "UPDATE sms_providers SET name = ?, domain = ? WHERE id = ?", undef, ( $self->name, $self->domain, $self->id ) );
72 return C4::Context->dbh->do( "INSERT INTO sms_providers ( name, domain ) VALUES ( ?, ? )", undef, ( $self->name, $self->domain ) );
83 return C4::Context->dbh->do( "DELETE FROM sms_providers WHERE id = ?", undef, ( $self->id ) );
88 my $providers = Koha::SMS::Provider->all();
95 my $query = "SELECT * FROM sms_providers ORDER BY name";
96 my $sth = C4::Context->dbh->prepare($query);
100 while ( my $row = $sth->fetchrow_hashref() ) {
101 my $p = Koha::SMS::Provider->new($row);
102 push( @providers, $p );
110 my $provider = Koha::SMS::Provider->find( $id );
118 my $query = "SELECT * FROM sms_providers WHERE ID = ?";
119 my $sth = C4::Context->dbh->prepare($query);
122 my $row = $sth->fetchrow_hashref();
123 my $p = Koha::SMS::Provider->new($row);
130 my @providers = Koha::SMS::Provider->search({ [name => $name], [domain => $domain] });
138 my $query = "SELECT * FROM sms_providers WHERE ";
140 my @params = map( $params->{$_}, keys %$params );
141 $query .= join( " AND ", map( "$_ = ?", keys %$params ) );
143 $query .= " ORDER BY name";
145 my $sth = C4::Context->dbh->prepare($query);
146 $sth->execute(@params);
149 while ( my $row = $sth->fetchrow_hashref() ) {
150 my $p = Koha::SMS::Provider->new($row);
151 push( @providers, $p );