Adding a simple ORM mapper for campaigns.
git-svn-id: svn://192.168.202.10@300 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package Astguiclient::Campaign;
|
||||
|
||||
use strict;
|
||||
|
||||
=head1 name
|
||||
|
||||
Astguiclient::Campaign - .
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module is essentially a ORM to the vicidial_campaigns table.
|
||||
|
||||
=head2 new
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
return bless {}, $class;
|
||||
}
|
||||
|
||||
=head2 find
|
||||
|
||||
Decide what campaigns to load up. Has several options explained
|
||||
below.
|
||||
|
||||
=head3 Parameters
|
||||
|
||||
=over
|
||||
|
||||
=item type
|
||||
|
||||
This is a scalar telling what type of campaigns to load up. Default
|
||||
will load up "all".
|
||||
|
||||
=item * all
|
||||
|
||||
Loads up all available campaigns.
|
||||
|
||||
=item * active_agents
|
||||
|
||||
Loads up campaigns with active_agents.
|
||||
|
||||
=item id => 'campaign_id'
|
||||
|
||||
Will load up campaign only with the given id
|
||||
|
||||
=cut
|
||||
|
||||
sub find {
|
||||
my $self = shift;
|
||||
my $type = shift unless(ref $_[0]);
|
||||
my %args = (
|
||||
id => undef,
|
||||
@_
|
||||
);
|
||||
|
||||
my $sql;
|
||||
if( defined $args{id} ) {
|
||||
$args{id} = Astguiclient->dbi->quote( $args{id} );
|
||||
$sql = "SELECT * FROM vicidial_campaigns WHERE id = $args{id}";
|
||||
} elsif( $type eq 'all' ) {
|
||||
$sql = "SELECT * FROM vicidial_campaigns";
|
||||
} elsif( $type eq 'active_agents' ) {
|
||||
$sql =
|
||||
"SELECT * FROM vicidial_campaigns
|
||||
ON vicidial_campaigns.id = vicidial_live_agents.campaign_id
|
||||
WHERE vicidial_live_agents.status IN ( $ACTIVE_AGENTS )";
|
||||
}
|
||||
|
||||
my $sth = Astguiclient->dbi->prepare( $sql );
|
||||
$sth->execute();
|
||||
while( my $ref = $sth->fetchrow_hashref() ) {
|
||||
push( @records, Astguiclient::Campaign::Record->new( $ref ) );
|
||||
}
|
||||
|
||||
return @records;
|
||||
}
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Jason Yates <jaywhy@gmail.com>
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
Copyright (C) 2006 Matt Florell <vicidial@gmail.com>
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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 this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
=cut
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,126 @@
|
||||
package Astguiclient::Campaign::Agent;
|
||||
|
||||
use strict;
|
||||
use base qw(Class::Accessor::Fast);
|
||||
|
||||
__PACKAGE__->mk_accessor( qw/ active total list / );
|
||||
|
||||
=head1 name
|
||||
|
||||
Astguiclient::Campaign::Agent - .
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
=head2 new
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my %args = @_;
|
||||
|
||||
my $self = bless \%args, $class;
|
||||
$self->load()
|
||||
return $self;
|
||||
}
|
||||
|
||||
=head2 find
|
||||
|
||||
Load the agent information. This is called automatically by new,
|
||||
however if reload is required call again.
|
||||
|
||||
$self->find(
|
||||
conditions => [ "STATUS in ( ?, ?)", @bind_params ]
|
||||
);
|
||||
|
||||
=head3 Parameters
|
||||
|
||||
=over
|
||||
|
||||
=item conditions
|
||||
|
||||
A way to send into conditions in the where clause of the query. If
|
||||
bind parameters are needed, the query should and be sent in as an
|
||||
array ref.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub find {
|
||||
my $self = shift;
|
||||
my %args = (
|
||||
conditions => undef,
|
||||
@_,
|
||||
);
|
||||
|
||||
# Create the SQL statement.
|
||||
my $sql = "SELECT * FROM vicidial_live_agents WHERE campaign_id = ?";
|
||||
my @bind_params = ( $self->{id} );
|
||||
if( $args{conditions} ) {
|
||||
# If the condition has bind parameters
|
||||
if( ref( $args{conditions} ) ) {
|
||||
$sql .= " AND $args{conditions}[0]";
|
||||
push( @bind_params, @{ $args{conditions}[1] } );
|
||||
} else {
|
||||
# No bind params just sent in scalar.
|
||||
$sql .= " AND $args{conditions}";
|
||||
}
|
||||
}
|
||||
my $sth = Astguiclient->dbi->prepare();
|
||||
$sth->execute( @bind_params )
|
||||
my @records;
|
||||
while( my $ref = $sth->fetchrow_hashref() ) {
|
||||
push( @records, $ref );
|
||||
}
|
||||
|
||||
return @records;
|
||||
}
|
||||
|
||||
=head2 active
|
||||
|
||||
If in array or list context will return a list of active agents. In
|
||||
scalar context will return a count of active agents.
|
||||
|
||||
=cut
|
||||
|
||||
sub active {
|
||||
my $self = shift;
|
||||
|
||||
if( !wantarray ) {
|
||||
# Return a count of the live agents.
|
||||
return Astguiclient->dbi->selectrow_array("SELECT count(*) FROM vicidial_live_agents
|
||||
WHERE campaign_id = ? STATUS IN ( $ACTIVE_STATUS )",
|
||||
undef,
|
||||
$self->{id}
|
||||
);
|
||||
} else {
|
||||
$self->find( conditions => "STATUS in ( $ACTIVE_STATUS )" );
|
||||
}
|
||||
}
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Jason Yates <jaywhy@gmail.com>
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
Copyright (C) 2006 Matt Florell <vicidial@gmail.com>
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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 this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
=cut
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,59 @@
|
||||
package Astguiclient::Campaign::Record;
|
||||
|
||||
use strict;
|
||||
use base qw(Class::Accessor::Fast);
|
||||
|
||||
use Astguiclient::Campaign::Agent;
|
||||
|
||||
__PACKAGE__->mk_accessors(qw/ agent /);
|
||||
|
||||
=head1 name
|
||||
|
||||
Astguiclient::Campaign - .
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module is essentially a ORM to the vicidial_campaigns table.
|
||||
|
||||
=head2 new
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $self = bless shift, $class;
|
||||
|
||||
$self->agent(
|
||||
Astguiclient::Campaign::Agent->new( id => $self->{campaign_id} )
|
||||
);
|
||||
}
|
||||
|
||||
=head2 agent
|
||||
|
||||
Returns the agent object.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Jason Yates <jaywhy@gmail.com>
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
Copyright (C) 2006 Matt Florell <vicidial@gmail.com>
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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 this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
=cut
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user