<?php
//this class will be notified if corresponding agent is deleted
//if ping is priorited. the priority sets to null
//
Final Class Automate Extends EntityBase implements Observer {
private $id;
private $agent;
private $caller;
private $script;
public function __construct(){
//PHYSIC TABLE DEFINITION for Ping Monitoring
//-----------------------------------------------------
$tablename = 'automate';
$field_agent = 'agent';
$field_id = 'at_id';
$field_caller = 'caller';
$field_script = 'script';
//-----------------------------------------------------
$rawfields = array('agent'=>$field_agent,'caller'=>$field_caller,'script'=>$field_script);
$agent = new Agent();
$attributes = array($agent->getAbsField('description'),$field_caller,$field_script);
$condition = $agent->getAbsField('id').'='.$tablename.'.'.$field_agent;
parent::__construct(array($tablename,$agent->getPrimaryTable()),$field_id,$attributes,$rawfields,$condition);
}
//this is only wrapper to provide single object
//just copy paste for all children
public function selectByID($id){
if($id[0]=='p'){
//special for ping monitoring to simplify query table
$tempstring = explode('_',$id);
$id = $tempstring[1];
}
$tempobj = parent::selectByID($id);
if($tempobj){
foreach($this->rawfields as $key => $value){
$this->$key = $tempobj->$value;
}
}
}
//join table with agent
//FIXME: still coupled with table field name
public function selectCouple($attr1,$attr2){
$sql = 'SELECT agents.'.$attr1.' as '.$attr1.',agents.'.$attr2.' as '.$attr2.' FROM '.$this->getTableQuery().' WHERE '.$this->condition;
$temp = $this->dba->query($sql);
$array = array();
for($i=0;$i<sizeof($temp);$i++){
$array[$temp[$i]->$attr1]=$temp[$i]->$attr2;
}
return $array;
}
public function getAgentID(){
return $this->agent;
}
public function getCaller(){
return $this->caller;
}
public function getScript(){
return $this->script;
}
//special case notify remove for ping monitoring
public function notifyRemove($obj,$id){
if($obj instanceOf Agent){
if($this->isExist($id)){
$this->remove($id);
}
}
}
public function __destruct(){
parent::__destruct();
}
}
?>