Example #1
0
 /**
  * Object selection
  *
  * @param array   $data       Conditionals and Order values
  * @param integer $limit      Limit
  * @param integer $limitStart Limit start
  * @param int     $total      Total rows found
  *
  * @return array Objects found
  */
 public static function select($data = array(), $limit = 0, $limitStart = 0, &$total = null)
 {
     $db = Registry::getDb();
     //Query
     $query = "SELECT * FROM `tipos` ";
     $params = array();
     //Where
     $where = " WHERE 1=1 ";
     $query .= $where;
     //Total
     $totalQuery = "SELECT * FROM `tipos` " . $where;
     $total = count($db->Query($totalQuery, $params));
     if ($total) {
         //Order
         if ($data['order'] && $data['orderDir']) {
             //Secure Field
             $orders = array("ASC", "DESC");
             if (@in_array($data['order'], array_keys(get_class_vars(__CLASS__))) && in_array($data['orderDir'], $orders)) {
                 $query .= " ORDER BY `" . $data['order'] . "` " . $data['orderDir'];
             }
         }
         //Limit
         if ($limit) {
             $query .= " LIMIT " . (int) $limitStart . ", " . (int) $limit;
         }
         $rows = $db->Query($query, $params);
         if (count($rows)) {
             $results = array();
             foreach ($rows as $row) {
                 $results[] = new Tipo($row);
             }
             return $results;
         }
     }
 }
Example #2
0
 /**
  * Object selection
  *
  * @param array   $data       Conditionals and Order values
  * @param integer $limit      Limit
  * @param integer $limitStart Limit start
  * @param int     $total      Total rows found
  *
  * @return array Objects found
  */
 public static function select($data = array(), $limit = 0, $limitStart = 0, &$total = null)
 {
     $db = Registry::getDb();
     //Query
     $query = "SELECT * FROM `users` ";
     $params = array();
     //Where
     $where = " WHERE 1=1 ";
     //Search
     if ($data["search"]) {
         $where .= "AND (`username` LIKE :username OR `email` LIKE :email )";
         $params[":username"] = "%" . $data["search"] . "%";
         $params[":email"] = "%" . $data["search"] . "%";
     }
     //Status
     if (isset($data["statusId"]) && $data["statusId"] != "-1") {
         $where .= " AND `statusId` = :statusId ";
         $params[":statusId"] = $data["statusId"];
     }
     $query .= $where;
     //Total
     $totalQuery = "SELECT * FROM `users` " . $where;
     $total = count($db->Query($totalQuery, $params));
     if ($total) {
         //Order
         if ($data['order'] && $data['orderDir']) {
             //Secure Field
             $orders = array("ASC", "DESC");
             if (@in_array($data['order'], array_keys(get_class_vars(__CLASS__))) && in_array($data['orderDir'], $orders)) {
                 $query .= " ORDER BY `" . $data['order'] . "` " . $data['orderDir'];
             }
         }
         //Limit
         if ($limit) {
             $query .= " LIMIT " . (int) $limitStart . ", " . (int) $limit;
         }
         $rows = $db->Query($query, $params);
         if (count($rows)) {
             $results = array();
             foreach ($rows as $row) {
                 $results[] = new User($row);
             }
             return $results;
         }
     }
 }
Example #3
0
 /**
  * Obtiene registros de la base de datos.
  * @param  array   $data       Condicionales / ordenación
  * @param  integer $limit      Límite de resultados (Paginación)
  * @param  integer $limitStart Inicio de la limitación (Paginación)
  * @param  int     $total      Total de filas encontradas (Paginación)
  * @return array   Modelos de la clase actual
  */
 public function select($data = array(), $limit = 0, $limitStart = 0, &$total = null)
 {
     $db = Registry::getDb();
     //Query
     $query = "SELECT * FROM `eventos` WHERE 1=1 ";
     $params = array();
     //Where
     if (isset($data["fecha"])) {
         $query .= " AND `fechaInicio` >= :fechaInicio AND `fechaFin` <= :fechaFin ";
         $params[":fechaInicio"] = $data["fecha"] . " 03:00:00:00";
         $params[":fechaFin"] = date("Y-m-d 02:59:59:24", strtotime($data["fecha"] . " +1 day"));
     }
     if ($data["orderNum"]) {
         $query .= " AND `order` = :orderNum ";
         $params[":orderNum"] = $data["orderNum"];
     }
     if ($data["minOrderNum"]) {
         $query .= " AND `order` >= :minOrderNum ";
         $params[":minOrderNum"] = $data["minOrderNum"];
     }
     //Tipo
     if ($data["tipo"]) {
         $query .= "AND `tipo` IN (SELECT `id` FROM `tipos` WHERE `codigo` = :tipo) ";
         $params[":tipo"] = $data["tipo"];
     }
     //Total
     $total = count($db->Query($query, $params));
     if ($total) {
         //Order
         if ($data['order'] && $data['orderDir']) {
             //Secure Field
             $orders = array("ASC", "DESC");
             if (@in_array($data['order'], array_keys(get_class_vars(__CLASS__))) && in_array($data['orderDir'], $orders)) {
                 $query .= " ORDER BY `" . $data['order'] . "` " . $data['orderDir'];
             }
         } else {
             $query .= " ORDER BY `order` ASC ";
         }
         //Limit
         if ($limit) {
             $query .= " LIMIT " . (int) $limitStart . ", " . (int) $limit;
         }
         $rows = $db->Query($query, $params);
         if (count($rows)) {
             foreach ($rows as $row) {
                 $results[] = new Evento($row);
             }
             return $results;
         }
     }
 }
Example #4
0
 /**
  * Object selection
  *
  * @param array   $data       Conditionals and Order values
  * @param integer $limit      Limit
  * @param integer $limitStart Limit start
  * @param int     $total      Total rows found
  *
  * @return array Objects found
  */
 public static function select($data = array(), $limit = 0, $limitStart = 0, &$total = null)
 {
     $db = Registry::getDb();
     //Query
     $query = "SELECT * FROM `entradas` ";
     $params = array();
     //Where
     $where = " WHERE 1=1 ";
     //Search
     if ($data["search"]) {
         $where .= "AND (`nombre` LIKE :nombre OR `houseNumber` LIKE :houseNumber) ";
         $params[":houseNumber"] = "%" . $data["search"] . "%";
         $params[":nombre"] = "%" . $data["search"] . "%";
     }
     //Tipo
     if ($data["tipo"]) {
         $where .= "AND `tipoId` IN (SELECT `id` FROM `tipos` WHERE `codigo` = :tipo) ";
         $params[":tipo"] = $data["tipo"];
     }
     //Vinculada
     if (isset($data["vinculada"]) && $data['vinculada'] != -1) {
         if ($data['vinculada']) {
             $where .= "AND `programaId` > 0 ";
         } else {
             $where .= "AND (`programaId` = 0 OR  `programaId` IS NULL) ";
         }
     }
     $query .= $where;
     //Total
     $totalQuery = "SELECT * FROM `entradas` " . $where;
     $total = count($db->Query($totalQuery, $params));
     if ($total) {
         //Order
         if ($data['order'] && $data['orderDir']) {
             //Secure Field
             $orders = array("ASC", "DESC");
             if (@in_array($data['order'], array_keys(get_class_vars(__CLASS__))) && in_array($data['orderDir'], $orders)) {
                 $query .= " ORDER BY `" . $data['order'] . "` " . $data['orderDir'];
             }
         }
         //Limit
         if ($limit) {
             $query .= " LIMIT " . (int) $limitStart . ", " . (int) $limit;
         }
         $rows = $db->Query($query, $params);
         if (count($rows)) {
             $results = array();
             foreach ($rows as $row) {
                 $results[] = new Entrada($row);
             }
             return $results;
         }
     }
 }