Skip to content

Instantly share code, notes, and snippets.

@hogihung
Created March 31, 2016 20:23
Show Gist options
  • Save hogihung/7b8566de0965b80c79ecc24f6be3c306 to your computer and use it in GitHub Desktop.
Save hogihung/7b8566de0965b80c79ecc24f6be3c306 to your computer and use it in GitHub Desktop.
#-----------------------------------------------------------------------------
# John Hogarty
#
# Description: Class to process data related elements of a baytech and any
# devices that are connected to a baytech.
#
#-----------------------------------------------------------------------------
package OMX::Data::DB::Baytech;
use strict;
use warnings FATAL => qw(all);
use base 'OMX::Data::DB::Base';
#-----------------------------------------------------------------------------
# construct and return object, set defaults
#-----------------------------------------------------------------------------
sub new
{
my $type = shift();
my $class = ref($type) || $type;
my $self = $class->SUPER::new(@_);
my %args = @_;
$self->{target_name} = undef;
bless ($self, $class);
return $self;
}
#-----------------------------------------------------------------------------
# find_all
#-----------------------------------------------------------------------------
sub find_all
{
my $self = shift;
my $sql = shift;
print ref($self), ":find_all\n" if $self->debug;
$sql = "SELECT name, ip_addr, phone_num, region, ip_method, active
FROM oob_baytechs";
return $self->query_by_sql($sql);
}
#-----------------------------------------------------------------------------
# find_by_name
#-----------------------------------------------------------------------------
sub find_by_name
{
my $self = shift;
my $sql = shift;
my $search = $self->{search_value};
print ref($self), ":find_by_name\n" if $self->debug;
$sql = "SELECT name, ip_addr, phone_num, region, ip_method, active
FROM oob_baytechs
WHERE oob_baytechs.name = '$search'
AND oob_baytechs.active = 1";
return $self->query_by_sql($sql);
}
#-----------------------------------------------------------------------------
# find_by_ip
#-----------------------------------------------------------------------------
sub find_by_ip
{
my $self = shift;
my $sql = shift;
my $search = $self->{search_value};
print ref($self), ":find_by_ip\n" if $self->debug;
$sql = "SELECT name, ip_addr, phone_num, region, ip_method, active
FROM oob_baytechs
WHERE oob_baytechs.ip_addr = '$search'
AND oob_baytechs.active = 1";
return $self->query_by_sql($sql);
}
#-----------------------------------------------------------------------------
# find_by_phone
#-----------------------------------------------------------------------------
sub find_by_phone
{
my $self = shift;
my $sql = shift;
my $search = $self->{search_value};
print ref($self), ":find_by_phone\n" if $self->debug;
$sql = "SELECT name, ip_addr, phone_num, region, ip_method, active
FROM oob_baytechs
WHERE oob_baytechs.phone_num = '$search'
AND oob_baytechs.active = 1";
return $self->query_by_sql($sql);
}
#-----------------------------------------------------------------------------
# find_by_device
#-----------------------------------------------------------------------------
sub find_by_device
{
my $self = shift;
my $sql = shift;
my $search = $self->{search_value};
print ref($self), ":find_by_device\n" if $self->debug;
$sql = "SELECT oob_baytechs.id, oob_baytechs.name, oob_baytechs.ip_addr,
oob_baytechs.phone_num, oob_baytechs.region, oob_baytechs.ip_method
FROM oob_baytechs
INNER JOIN oob_devices
ON oob_baytechs.id=oob_devices.baytech_id
WHERE oob_devices.name = $search
AND oob_baytechs.active = 1";
return $self->query_by_sql($sql);
}
#-----------------------------------------------------------------------------
# search_value
#-----------------------------------------------------------------------------
sub search_value
{
my $self = shift;
if (@_)
{
$self->{search_value} = shift;
print ref($self), ":search_value: ", $self->{search_value}, "\n" if $self->debug;
}
return $self->{search_value};
}
return 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment