Mister Spy Say ="Hello Kids ... :D"
___ ____ _ _____
| \/ (_) | | / ___|
| . . |_ ___| |_ ___ _ __ \ `--. _ __ _ _
| |\/| | / __| __/ _ \ '__| `--. \ '_ \| | | |
| | | | \__ \ || __/ | /\__/ / |_) | |_| |
\_| |_/_|___/\__\___|_| \____/| .__/ \__, |
| | __/ |
|_| |___/
Bot Mister Spy V3
Mister Spy
Mister Spy
<?php
require_once('class.dbaccess.php');
require_once('class.animal.php');
require_once('class.filter.php');
require_once('class.page.php');
require_once('class.pdres.php');
require_once('class.exiss.php');
require_once('class.extrs.php');
class Animales extends DBAccess implements IFilterable {
public function ParseFilter(array $filter)
{
$sql = '';
return $sql;
}
public function GetAll(array $filter = NULL, Page $oPage = NULL)
{
$sql = "SELECT a.* ";
$sql.= " FROM tblAnimales a ";
$sql.= " LEFT JOIN tblExis h ON a.IdExis = h.IdExis";
$sql.= " LEFT JOIN tblPdre m ON a.IdPdre = m.IdPdre";
$sql.= " LEFT JOIN tblExtr e ON a.IdExtr = e.IdExts";
$sql.= " WHERE 1 ";
if ($filter)
$sql.= $this->ParseFilter($filter);
if ($oPage != NULL)
$sql.= " " . Pageable::ParsePage($oPage);
if (!($oRes = $this->GetQuery($sql)))
return false;
$arr = array();
while ($oRow = $oRes->GetRow())
{
$oAnimal = new Animal();
$oAnimal->ParseFromArray($oRow);
array_push($arr, $oAnimal);
$oRes->MoveNext();
}
return $arr;
}
public function GetPagesCount(Page $oPage, $filter = false)
{
$sql = "SELECT COUNT(1) / " . DB::Number($oPage->Size) . " AS Count";
$sql.= " FROM tblAnimales a ";
$sql.= " LEFT JOIN tblExis h ON a.IdExis = h.IdExis";
$sql.= " LEFT JOIN tblPdre m ON a.IdPdre = m.IdPdre";
$sql.= " LEFT JOIN tblExtr e ON a.IdExtr = e.IdExts";
$sql.= " WHERE 1 ";
if ($filter)
$sql.= " " . $this->ParseFilter($filter);
if (!($oRes = $this->GetQuery($sql)) )
return false;
if ( !($oRow = $oRes->GetRow()) )
return false;
$Count = $oRow['Count'];
$Count = ceil($Count);
return $Count;
}
public function GetCountRows(array $filter = NULL)
{
$sql = "SELECT * ";
$sql.= " FROM tblAnimales a ";
$sql.= " LEFT JOIN tblExis h ON a.IdExis = h.IdExis";
$sql.= " LEFT JOIN tblPdre m ON a.IdPdre = m.IdPdre";
$sql.= " LEFT JOIN tblExtr e ON a.IdExtr = e.IdExts";
$sql.= " WHERE 1";
if ($filter)
$sql.= $this->ParseFilter($filter);
if (!($oRes = $this->GetQuery($sql)))
return false;
$CountRows = $oRes->NumRows();
return $CountRows;
}
public function GetById($IdAnimal)
{
$sql = "SELECT * ";
$sql.= " FROM tblAnimales ";
$sql.= " WHERE IdProd = " . DB::Number($IdAnimal);
if (!($oRes = $this->GetQuery($sql)))
return false;
if (!($oRow = $oRes->GetRow()))
return false;
$oAnimal = new Animal();
$oAnimal->ParseFromArray($oRow);
return $oAnimal;
}
private function GetArrayDB(Animal $oAnimal) {
return array
(
'IdAnimal' => DB::Number($oAnimal->IdAnimal),
'IdProd' => DB::Number($oAnimal->IdProd),
'IdPa' => DB::Number($oAnimal->IdPa),
'IdMa' => DB::Number($oAnimal->IdMa),
'IdPdre' => DB::Number($oAnimal->IdPdre),
'IdExis' => DB::Number($oAnimal->IdExis),
'IdExtr' => DB::Number($oAnimal->IdExtr)
);
}
public function Create(Animal $oAnimal) {
$arr = $this->GetArrayDB($oAnimal);
if (!$this->Insert('tblAnimales', $arr))
return false;
return $oExis;
}
public function Update(Animal $oAnimal)
{
$where = " IdAnimal = " . DB::Number($oAnimal->IdAnimal);
$arr = $this->GetArrayDB($oAnimal);
if (!DBAccess::Update('tblAnimales', $arr, $where))
return false;
return $oExis;
}
public function Delete($IdAnimal)
{
if (!DBAccess::$db->Begin())
return false;
$where = " IdAnimal = " . DB::Number($IdAnimal);
if (!DBAccess::Delete('tblAnimales', $where))
{
DBAccess::$db->Rollback();
return false;
}
DBAccess::$db->Commit();
return true;
}
private function SaveAnimalEntity($entity, $idColumn, $entitiesHandler) {
print_r($idColumn . '<br>');
print_r($entity);
if ($entity->$idColumn) {
$entitiesHandler->Update($entity);
} else {
$entity = $entitiesHandler->Create($entity);
}
return $entity;
}
private function SetRelations($entity) {
if ($oPadre = $this->GetById($entity->IdPa)) {
$entity->ASOP = $oPadre->Animal->ASOC ? $oPadre->Animal->ASOC : $oPadre->Animal->ASOX;
$entity->HBAP = $oPadre->Animal->HBAE;
$entity->RGSP = $oPadre->Animal->RGST;
$entity->RPPD = $oPadre->Animal->RPEX;
$entity->VARP = $oPadre->Animal->VARI;
}
if ($oMadre = $this->GetById($entity->IdMa)) {
$entity->ASOM = $oMadre->Animal->ASOC ? $oMadre->Animal->ASOC : $oMadre->Animal->ASOX;
$entity->HBAM = $oMadre->Animal->HBAE;
$entity->RGSM = $oMadre->Animal->RGST;
$entity->RPMD = $oMadre->Animal->RPEX;
$entity->VARM = $oMadre->Animal->VARI;
}
return $entity;
}
public function Save(Animal $oAnimal) {
$idColumn = '';
$entitiesHandler = null;
if ($oAnimal->Tabla == 'tblPdre') {
$idColumn = 'IdPdre';
$entitiesHandler = new Pdres();
} elseif ($oAnimal->Tabla == 'tblExis') {
$idColumn = 'IdExis';
$entitiesHandler = new Exiss();
} else {
$idColumn = 'IdExtr';
$entitiesHandler = new Extrs();
}
$oAnimal->Animal = $this->SetRelations($oAnimal->Animal);
$oAnimal->Animal = $this->SaveAnimalEntity($oAnimal->Animal, $idColumn, $entitiesHandler);
$oAnimal->$idColumn = $oAnimal->Animal->$idColumn;
if ($oAnimal->IdAnimal) {
$this->Update($oAnimal);
} else {
$this->Create($oAnimal);
}
}
}
?>
Mr. DellatioNx196 GaLers xh3LL Backd00r 1.0, Coded By Mr. DellatioNx196 - Bogor BlackHat