/estadisticas/estadisticas/application/models/catalogs/HelixTypesIdCatalog.php
PHP | 331 lines | 213 code | 21 blank | 97 comment | 4 complexity | e6ebe8822dd3aa624b94f35e408b0d8d MD5 | raw file
- <?php
- /**
- * Xsn
- *
- * Xsn
- *
- * @category lib
- * @package lib_models
- * @copyright Copyright (c) 2010-1011 Xsn Group (http://www.xsn.com.mx)
- * @author <irgg>, $LastChangedBy$
- * @version 1.0.2 SVN: $Id$
- */
- /**
- * Dependences
- */
- require_once "lib/db/Catalog.php";
- require_once "application/models/beans/HelixTypesId.php";
- require_once "application/models/exceptions/HelixTypesIdException.php";
- require_once "application/models/collections/HelixTypesIdCollection.php";
- require_once "application/models/factories/HelixTypesIdFactory.php";
- /**
- * Singleton HelixTypesIdCatalog Class
- *
- * @category lib
- * @package lib_models
- * @subpackage lib_models_catalogs
- * @copyright Copyright (c) 2010-1011 Xsn Group (http://www.xsn.com.mx)
- * @copyright This File has been proudly generated by Bender (http://code.google.com/p/bender-modeler/). <chentepixtol> <zetta>
- * @author zetta & chentepixtol
- * @version 1.0.2 SVN: $Revision$
- */
- class HelixTypesIdCatalog extends Catalog
- {
- /**
- * Singleton Instance
- * @var HelixTypesIdCatalog
- */
- static protected $instance = null;
- /**
- * Método para obtener la instancia del catálogo
- * @return HelixTypesIdCatalog
- */
- public static function getInstance()
- {
- if (!isset(self::$instance))
- {
- self::$instance = new self();
- }
- return self::$instance;
- }
-
- /**
- * Constructor de la clase HelixTypesIdCatalog
- * @return HelixTypesIdCatalog
- */
- protected function HelixTypesIdCatalog()
- {
- $this->Catalog();
- }
- /**
- * Metodo para agregar un HelixTypesId a la base de datos
- * @param HelixTypesId $helixTypesId Objeto HelixTypesId
- */
- public function create($helixTypesId)
- {
- if(!($helixTypesId instanceof HelixTypesId))
- throw new HelixTypesIdException("passed parameter isn't a HelixTypesId instance");
- try
- {
- $data = array(
- 'name' => $helixTypesId->getName(),
- );
- $data = array_filter($data, 'Catalog::notNull');
- $this->db->insert(HelixTypesId::TABLENAME, $data);
- $helixTypesId->setIdType($this->db->lastInsertId());
- }
- catch(Exception $e)
- {
- throw new HelixTypesIdException("The HelixTypesId can't be saved \n" . $e->getMessage());
- }
- }
- /**
- * Metodo para Obtener los datos de un objeto por su llave primaria
- * @param int $idType
- * @param boolean $throw
- * @return HelixTypesId|null
- */
- public function getById($idType, $throw = false)
- {
- try
- {
- $criteria = new Criteria();
- $criteria->add(HelixTypesId::ID_TYPE, $idType, Criteria::EQUAL);
- $newHelixTypesId = $this->getByCriteria($criteria)->getOne();
- }
- catch(Exception $e)
- {
- throw new HelixTypesIdException("Can't obtain the HelixTypesId \n" . $e->getMessage());
- }
- if($throw && null == $newHelixTypesId)
- throw new HelixTypesIdException("The HelixTypesId at $idType not exists ");
- return $newHelixTypesId;
- }
-
- /**
- * Metodo para Obtener una colección de objetos por varios ids
- * @param array $ids
- * @return HelixTypesIdCollection
- */
- public function getByIds(array $ids)
- {
- if(null == $ids) return new HelixTypesIdCollection();
- try
- {
- $criteria = new Criteria();
- $criteria->add(HelixTypesId::ID_TYPE, $ids, Criteria::IN);
- $helixTypesIdCollection = $this->getByCriteria($criteria);
- }
- catch(Exception $e)
- {
- throw new HelixTypesIdException("HelixTypesIdCollection can't be populated\n" . $e->getMessage());
- }
- return $helixTypesIdCollection;
- }
- /**
- * Metodo para actualizar un HelixTypesId
- * @param HelixTypesId $helixTypesId
- */
- public function update($helixTypesId)
- {
- if(!($helixTypesId instanceof HelixTypesId))
- throw new HelixTypesIdException("passed parameter isn't a HelixTypesId instance");
- try
- {
- $where[] = "id_type = '{$helixTypesId->getIdType()}'";
- $data = array(
- 'name' => $helixTypesId->getName(),
- );
- $data = array_filter($data, 'Catalog::notNull');
- $this->db->update(HelixTypesId::TABLENAME, $data, $where);
- }
- catch(Exception $e)
- {
- throw new HelixTypesIdException("The HelixTypesId can't be updated \n" . $e->getMessage());
- }
- }
-
- /**
- * Metodo para guardar un helixTypesId
- * @param HelixTypesId $helixTypesId
- */
- public function save($helixTypesId)
- {
- if(!($helixTypesId instanceof HelixTypesId))
- throw new HelixTypesIdException("passed parameter isn't a HelixTypesId instance");
- if(null != $helixTypesId->getIdType())
- $this->update($helixTypesId);
- else
- $this->create($helixTypesId);
- }
- /**
- * Metodo para eliminar un helixTypesId
- * @param HelixTypesId $helixTypesId
- */
- public function delete($helixTypesId)
- {
- if(!($helixTypesId instanceof HelixTypesId))
- throw new HelixTypesIdException("passed parameter isn't a HelixTypesId instance");
- $this->deleteById($helixTypesId->getIdType());
- }
- /**
- * Metodo para eliminar un HelixTypesId a partir de su Id
- * @param int $idType
- */
- public function deleteById($idType)
- {
- try
- {
- $where = array($this->db->quoteInto('id_type = ?', $idType));
- $this->db->delete(HelixTypesId::TABLENAME, $where);
- }
- catch(Exception $e)
- {
- throw new HelixTypesIdException("The HelixTypesId can't be deleted\n" . $e->getMessage());
- }
- }
-
- /**
- * Metodo para eliminar varios HelixTypesId a partir de su Id
- * @param array $ids
- */
- public function deleteByIds(array $ids)
- {
- try
- {
- $criteria = new Criteria();
- $criteria->add(HelixTypesId::ID_TYPE, $ids, Criteria::IN);
- $this->db->delete(HelixTypesId::TABLENAME, array($criteria->createSql()));
- }
- catch(Exception $e)
- {
- throw new HelixTypesIdException("Can't delete that\n" . $e->getMessage());
- }
- }
-
- /**
- * Metodo para Obtener todos los ids en un arreglo
- * @return array
- */
- public function retrieveAllIds()
- {
- return $this->getIdsByCriteria(new Criteria());
- }
- /**
- * Metodo para obtener todos los id de HelixTypesId por criterio
- * @param Criteria $criteria
- * @return array Array con todos los id de HelixTypesId que encajen en la busqueda
- */
- public function getIdsByCriteria(Criteria $criteria = null)
- {
- $criteria = (null === $criteria) ? new Criteria() : $criteria;
- return $this->getCustomFieldByCriteria(HelixTypesId::ID_TYPE, $criteria);
- }
- /**
- * Metodo para obtener un campo en particular de un HelixTypesId dado un criterio
- * @param string $field
- * @param Criteria $criteria
- * @param $distinct
- * @return array Array con el campo de los objetos HelixTypesId que encajen en la busqueda
- */
- public function getCustomFieldByCriteria($field, Criteria $criteria = null, $distinct = false)
- {
- $criteria = (null === $criteria) ? new Criteria() : $criteria;
- $distinct = $distinct ? 'DISTINCT' : '';
- try
- {
- $sql = "SELECT {$distinct} {$field}
- FROM ".HelixTypesId::TABLENAME."
- WHERE " . $criteria->createSql();
- $result = $this->db->fetchCol($sql);
- } catch(Zend_Db_Exception $e)
- {
- throw new HelixTypesIdException("No se pudieron obtener los fields de objetos HelixTypesId\n" . $e->getMessage());
- }
- return $result;
- }
- /**
- * Metodo que regresa una coleccion de objetos HelixTypesId
- * dependiendo del criterio establecido
- * @param Criteria $criteria
- * @return HelixTypesIdCollection $helixTypesIdCollection
- */
- public function getByCriteria(Criteria $criteria = null)
- {
- $criteria = (null === $criteria) ? new Criteria() : $criteria;
- $this->db->setFetchMode(Zend_Db::FETCH_ASSOC);
- try
- {
- $sql = "SELECT * FROM ".HelixTypesId::TABLENAME."
- WHERE " . $criteria->createSql();
- $helixTypesIdCollection = new HelixTypesIdCollection();
- foreach ($this->db->fetchAll($sql) as $result){
- $helixTypesIdCollection->append($this->getHelixTypesIdInstance($result));
- }
- }
- catch(Zend_Db_Exception $e)
- {
- throw new HelixTypesIdException("Cant obtain HelixTypesIdCollection\n" . $e->getMessage());
- }
- return $helixTypesIdCollection;
- }
-
- /**
- * Metodo que cuenta HelixTypesId
- * dependiendo del criterio establecido
- * @param Criteria $criteria
- * @param string $field
- * @return int $count
- */
- public function countByCriteria(Criteria $criteria = null, $field = 'id_type')
- {
- $criteria = (null === $criteria) ? new Criteria() : $criteria;
- try
- {
- $sql = "SELECT COUNT( $field ) FROM ".HelixTypesId::TABLENAME."
- WHERE " . $criteria->createSql();
- $count = $this->db->fetchOne($sql);
- }
- catch(Zend_Db_Exception $e)
- {
- throw new HelixTypesIdException("Cant obtain the count \n" . $e->getMessage());
- }
- return $count;
- }
-
- /**
- * Método que construye un objeto HelixTypesId y lo rellena con la información del rowset
- * @param array $result El arreglo que devolvió el objeto Zend_Db despues del fetch
- * @return HelixTypesId
- */
- private function getHelixTypesIdInstance($result)
- {
- return HelixTypesIdFactory::createFromArray($result);
- }
- /* (non-PHPdoc)
- * @see Catalog::Catalog()
- */
- public function Catalog ()
- {
- // TODO Auto-generated method stub
- parent::setDatePart("YYYY-MM-dd hh:mm:ss");
- parent::setDb(DBAO::Database(1));
- }
- }
-