/estadisticas/estadisticas/public/xStreamOld/application/models/catalogs/UserLogCatalog.php
PHP | 370 lines | 301 code | 11 blank | 58 comment | 5 complexity | 081d2e1f4077e3cdaa4e3ece33aad0a6 MD5 | raw file
- <?php
- /**
- * Bender Modeler
- *
- * Our Simple Models
- *
- * @category lib
- * @package lib_models
- * @copyright Copyright (c) 2008-2010 Bender Modeler (http://www.ctrl-zetta.com/#code)
- * @author <zetta> <chentepixtol>, $LastChangedBy$
- * @version 1.0.0 SVN: $Id$
- */
- /**
- * Dependences
- */
- require_once "lib/db/Catalog.php";
- require_once "application/models/beans/UserLog.php";
- require_once "application/models/exceptions/UserLogException.php";
- require_once "application/models/collections/UserLogCollection.php";
- require_once "application/models/factories/UserLogFactory.php";
- /**
- * Singleton UserLogCatalog Class
- *
- * @category lib
- * @package lib_models
- * @subpackage lib_models_catalogs
- * @copyright Copyright (c) 2008-2010 Bender Modeler (http://www.ctrl-zetta.com/#code)
- * @copyright This File as been proudly generated by Bender (http://code.google.com/p/bender-modeler/). <chentepixtol> <zetta>
- * @author zetta & chentepixtol
- * @version 1.0.0 SVN: $Revision$
- */
- class UserLogCatalog extends Catalog
- {
- /**
- * Singleton Instance
- * @var UserLogCatalog
- */
- static protected $instance = null;
- /**
- * Método para obtener la instancia del catálogo
- * @return UserLogCatalog
- */
- public static function getInstance()
- {
- if (!isset(self::$instance))
- {
- self::$instance = new self();
- }
- return self::$instance;
- }
-
- /**
- * Constructor de la clase UserLogCatalog
- * @return UserLogCatalog
- */
- protected function UserLogCatalog()
- {
- parent::Catalog();
- }
- /**
- * Metodo para agregar un UserLog a la base de datos
- * @param UserLog $userLog Objeto UserLog
- */
- public function create($userLog)
- {
- if(!($userLog instanceof UserLog))
- throw new UserLogException("passed parameter isn't a UserLog instance");
- try
- {
- $data = array(
- 'id_user' => $userLog->getIdUser(),
- 'event_type' => $userLog->getEventType(),
- 'ip' => $userLog->getIp(),
- 'id_responsible' => $userLog->getIdResponsible(),
- 'timestamp' => $userLog->getTimestamp(),
- 'note' => $userLog->getTimestamp(),
- );
- $data = array_filter($data, 'Catalog::notNull');
- $this->db->insert(UserLog::TABLENAME, $data);
- $userLog->setIdUserLog($this->db->lastInsertId());
- }
- catch(Exception $e)
- {
- throw new UserLogException("The UserLog can't be saved \n" . $e->getMessage());
- }
- }
- /**
- * Metodo para Obtener los datos de un objeto por su llave primaria
- * @param int $idUserLog
- * @return UserLog|null
- */
- public function getById($idUserLog)
- {
- try
- {
- $criteria = new Criteria();
- $criteria->add(UserLog::ID_USER_LOG, $idUserLog, Criteria::EQUAL);
- $newUserLog = $this->getByCriteria($criteria)->getOne();
- }
- catch(Exception $e)
- {
- throw new UserLogException("Can't obtain the UserLog \n" . $e->getMessage());
- }
- return $newUserLog;
- }
-
- /**
- * Metodo para Obtener una colección de objetos por varios ids
- * @param array $ids
- * @return UserLogCollection
- */
- public function getByIds(array $ids)
- {
- if(null == $ids) return new UserLogCollection();
- try
- {
- $criteria = new Criteria();
- $criteria->add(UserLog::ID_USER_LOG, $ids, Criteria::IN);
- $userLogCollection = $this->getByCriteria($criteria);
- }
- catch(Exception $e)
- {
- throw new UserLogException("UserLogCollection can't be populated\n" . $e->getMessage());
- }
- return $userLogCollection;
- }
- /**
- * Metodo para Obtener todos los ids en un arreglo
- * @return array
- */
- public function retrieveAllIds()
- {
- try
- {
- $result = $this->db->fetchCol('SELECT id_user_log FROM '.UserLog::TABLENAME);
- }
- catch(Exception $e)
- {
- throw new UserLogException("Can't obtain the ids\n" . $e->getMessage());
- }
- return $result;
- }
- /**
- * Metodo para actualizar un UserLog
- * @param UserLog $userLog
- */
- public function update($userLog)
- {
- if(!($userLog instanceof UserLog))
- throw new UserLogException("passed parameter isn't a UserLog instance");
- try
- {
- $where[] = "id_user_log = '{$userLog->getIdUserLog()}'";
- $data = array(
- 'id_user' => $userLog->getIdUser(),
- 'event_type' => $userLog->getEventType(),
- 'ip' => $userLog->getIp(),
- 'id_responsible' => $userLog->getIdResponsible(),
- 'timestamp' => $userLog->getTimestamp(),
- 'note' => $userLog->getTimestamp(),
- );
- $data = array_filter($data, 'Catalog::notNull');
- $this->db->update(UserLog::TABLENAME, $data, $where);
- }
- catch(Exception $e)
- {
- throw new UserLogException("The UserLog can't be updated \n" . $e->getMessage());
- }
- }
-
- /**
- * Metodo para guardar un userLog
- * @param UserLog $userLog
- */
- public function save($userLog)
- {
- if(!($userLog instanceof UserLog))
- throw new UserLogException("passed parameter isn't a UserLog instance");
- if(null != $userLog->getIdUserLog())
- $this->update($userLog);
- else
- $this->create($userLog);
- }
- /**
- * Metodo para eliminar un userLog
- * @param UserLog $userLog
- */
- public function delete($userLog)
- {
- if(!($userLog instanceof UserLog))
- throw new UserLogException("passed parameter isn't a UserLog instance");
- $this->deleteById($userLog->getIdUserLog());
- }
- /**
- * Metodo para eliminar un UserLog a partir de su Id
- * @param int $idUserLog
- */
- public function deleteById($idUserLog)
- {
- try
- {
- $where = array($this->db->quoteInto('id_user_log = ?', $idUserLog));
- $this->db->delete(UserLog::TABLENAME, $where);
- }
- catch(Exception $e)
- {
- throw new UserLogException("The UserLog can't be deleted\n" . $e->getMessage());
- }
- }
-
- /**
- * Metodo para eliminar varios UserLog a partir de su Id
- * @param array $ids
- */
- public function deleteByIds(array $ids)
- {
- try
- {
- $criteria = new Criteria();
- $criteria->add(UserLog::ID_USER_LOG, $ids, Criteria::IN);
- $this->db->delete(UserLog::TABLENAME, array($criteria->createSql()));
- }
- catch(Exception $e)
- {
- throw new UserLogException("Can't delete that\n" . $e->getMessage());
- }
- }
- /**
- * Metodo para obtener todos los id de UserLog por criterio
- * @param Criteria $criteria
- * @return array Array con todos los id de UserLog que encajen en la busqueda
- */
- public function getIdsByCriteria(Criteria $criteria = null)
- {
- $criteria = (null === $criteria) ? new Criteria() : $criteria;
- try
- {
- $sql = "SELECT id_user_log
- FROM ".UserLog::TABLENAME."
- WHERE " . $criteria->createSql();
- $ids = $this->db->fetchCol($sql);
- } catch(Exception $e)
- {
- throw new UserLogException("Can't obtain UserLog's id\n" . $e->getMessage());
- }
- return $ids;
- }
- /**
- * Metodo para obtener un campo en particular de un UserLog dado un criterio
- * @param string $field
- * @param Criteria $criteria
- * @return array Array con el campo de los objetos UserLog que encajen en la busqueda
- */
- public function getCustomFieldByCriteria($field, Criteria $criteria = null)
- {
- $criteria = (null === $criteria) ? new Criteria() : $criteria;
- try
- {
- $sql = "SELECT {$field}
- FROM ".UserLog::TABLENAME."
- WHERE " . $criteria->createSql();
- $result = $this->db->fetchCol($sql);
- } catch(Zend_Db_Exception $e)
- {
- throw new UserLogException("No se pudieron obtener los ids de objetos {$Bean}\n" . $e->getMessage());
- }
- return $result;
- }
- /**
- * Metodo que regresa una coleccion de objetos UserLog
- * dependiendo del criterio establecido
- * @param Criteria $criteria
- * @return UserLogCollection $userLogCollection
- */
- public function getByCriteria(Criteria $criteria = null)
- {
- $criteria = (null === $criteria) ? new Criteria() : $criteria;
- $this->db->setFetchMode(Zend_Db::FETCH_ASSOC);
- try
- {
- $sql = "SELECT * FROM ".UserLog::TABLENAME."
- WHERE " . $criteria->createSql();
- $userLogCollection = new UserLogCollection();
- foreach ($this->db->fetchAll($sql) as $result){
- $userLogCollection->append($this->getUserLogInstance($result));
- }
- }
- catch(Zend_Db_Exception $e)
- {
- throw new UserLogException("Cant obtain UserLogCollection\n" . $e->getMessage());
- }
- return $userLogCollection;
- }
-
- /**
- * Metodo que cuenta UserLog
- * dependiendo del criterio establecido
- * @param Criteria $criteria
- * @param string $field
- * @return int $count
- */
- public function countByCriteria(Criteria $criteria = null, $field = 'id_user_log')
- {
- $criteria = (null === $criteria) ? new Criteria() : $criteria;
- try
- {
- $sql = "SELECT COUNT( $field ) FROM ".UserLog::TABLENAME."
- WHERE " . $criteria->createSql();
- $count = $this->db->fetchOne($sql);
- }
- catch(Zend_Db_Exception $e)
- {
- throw new UserLogException("Cant obtain the count \n" . $e->getMessage());
- }
- return $count;
- }
-
- /**
- * Método que construye un objeto UserLog y lo rellena con la información del rowset
- * @param array $result El arreglo que devolvió el objeto Zend_Db despues del fetch
- * @return UserLog
- */
- private function getUserLogInstance($result)
- {
- return UserLogFactory::createFromArray($result);
- }
-
- /**
- * Obtiene un UserLogCollection dependiendo del idUser
- * @param int $idUser
- * @return UserLogCollection
- */
- public function getByIdUser($idUser)
- {
- $criteria = new Criteria();
- $criteria->add(UserLog::ID_USER, $idUser, Criteria::EQUAL);
- $userLogCollection = $this->getByCriteria($criteria);
- return $userLogCollection;
- }
-
- /**
- * Obtiene un UserLogCollection dependiendo del idResponsible
- * @param int $idResponsible
- * @return UserLogCollection
- */
- public function getByIdResponsible($idResponsible)
- {
- $criteria = new Criteria();
- $criteria->add(UserLog::ID_RESPONSIBLE, $idResponsible, Criteria::EQUAL);
- $userLogCollection = $this->getByCriteria($criteria);
- return $userLogCollection;
- }
- }
-