예제 #1
0
 public function getLocalidades($soloNormalizadas = FALSE)
 {
     $table = new \apf\db\mysql5\Table("localidades");
     $select = new \apf\db\mysql5\Select($table);
     $select->fields(array("id", "nombre", "normalizado"));
     $where = array(array("field" => "id_provincia", "value" => $this->getId()));
     if ($soloNormalizadas) {
         $where[] = array("operator" => "AND");
         $where[] = array("field" => "normalizado", "value" => "1");
     }
     $orderBy = array("nombre");
     $select->orderBy($orderBy, "DESC");
     $select->where($where);
     $res = $select->execute($smartMode = FALSE);
     if (!$res) {
         return FALSE;
     }
     $return = array();
     foreach ($res as $r) {
         $class = "\\apf\\model\\Localidad";
         $obj = new $class($this);
         $obj->setId($r["id"]);
         $obj->setNombre($r["nombre"]);
         $obj->setNormalizado($r["normalizado"]);
         $return[] = $obj;
     }
     return $return;
 }
예제 #2
0
 public function getBarrios()
 {
     $table = new \apf\db\mysql5\Table("barrios");
     $select = new \apf\db\mysql5\Select($table);
     $select->fields(array("id", "nombre"));
     $where = array(array("field" => "id_localidad", "value" => $this->getId()));
     $orderBy = array("nombre");
     $select->orderBy($orderBy, "DESC");
     $select->where($where);
     $res = $select->execute($smartMode = FALSE);
     if (!$res) {
         return FALSE;
     }
     $return = array();
     foreach ($res as $r) {
         $class = "\\apf\\model\\Barrio";
         $obj = new $class($this);
         $obj->setId($r["id"]);
         $obj->setNombre($r["nombre"]);
         $return[] = $obj;
     }
     return $return;
 }
예제 #3
0
 public static function obtenerOfertasParaUsuario(Usuario $usuario, $intervalo = 2, $tipo = "DAY")
 {
     $ofertasTable = new \apf\db\mysql5\Table("ofertas");
     $empresasTable = new \apf\db\mysql5\Table("empresas");
     $empresasDatosTable = new \apf\db\mysql5\Table("empresas_datos");
     $ofertasUbicacionTable = new \apf\db\mysql5\Table("ofertas_ubicacion");
     $localidadesTable = new \apf\db\mysql5\Table("localidades");
     $ofertasCategoriaTable = new \apf\db\mysql5\Table("ofertas_categoria");
     $categoriasTable = new \apf\db\mysql5\Table("categorias");
     $select = new \apf\db\mysql5\Select($ofertasTable);
     $fields = array("ofertas.id AS idOferta", "ofertas.email", "ofertas.titulo", "GROUP_CONCAT(categorias.id) AS categorias", "GROUP_CONCAT(localidades.id) AS localidades");
     $select->fields($fields);
     //INNER JOIN ofertas_ubicacion
     /////////////////////////////////////////////////////////
     $joinOfertasUbicacion = new \apf\db\mysql5\Join($ofertasUbicacionTable);
     $joinOfertasUbicacion->type("INNER");
     $on = array(array("field" => "ofertas.id", "value" => "ofertas_ubicacion.id_oferta", "quote" => FALSE));
     $joinOfertasUbicacion->on($on);
     $select->join($joinOfertasUbicacion);
     //INNER JOIN localidades
     /////////////////////////////////////////////////////////
     $joinLocalidades = new \apf\db\mysql5\Join($localidadesTable);
     $joinLocalidades->type("INNER");
     $on = array(array("field" => "localidades.id", "value" => "ofertas_ubicacion.id_localidad", "quote" => FALSE));
     $joinLocalidades->on($on);
     $select->join($joinLocalidades);
     //INNER JOIN ofertas_categoria
     /////////////////////////////////////////////////////////
     $joinOfertasCategoria = new \apf\db\mysql5\Join($ofertasCategoriaTable);
     $joinOfertasCategoria->type("INNER");
     $on = array(array("field" => "ofertas_categoria.id_oferta", "value" => "ofertas.id", "quote" => FALSE));
     $joinOfertasCategoria->on($on);
     $select->join($joinOfertasCategoria);
     //INNER JOIN categorias
     /////////////////////////////////////////////////////////
     $joinCategorias = new \apf\db\mysql5\Join($categoriasTable);
     $joinCategorias->type("INNER");
     $on = array(array("field" => "ofertas_categoria.id_categoria", "value" => "categorias.id", "quote" => FALSE));
     $joinCategorias->on($on);
     $select->join($joinCategorias);
     //WHERE
     /////////////////////////////////////////////////////////
     $where = array();
     $tmpWhere = array();
     $usuariosCategoria = new \apf\db\mysql5\Table("usuarios_categorias");
     $selectCategorias = new \apf\db\mysql5\Select($usuariosCategoria);
     $selectCategorias->fields(array("id_categoria"));
     $selectCategorias->where(array(array("field" => "id_usuario", "value" => $usuario->getId())));
     $tmpWhere[] = array("field" => "ofertas_categoria.id_categoria", "operator" => "IN", "value" => $selectCategorias);
     $prefUbicaciones = new \apf\db\mysql5\Table("usuarios_ubicaciones");
     $selectLocalidades = new \apf\db\mysql5\Select($prefUbicaciones);
     $selectLocalidades->fields(array("id_localidad"));
     $selectLocalidades->where(array(array("field" => "id_usuario", "value" => $usuario->getId())));
     $tmpWhere[] = array("field" => "ofertas_ubicacion.id_localidad", "operator" => "IN", "value" => $selectLocalidades);
     $postulacionesTable = new \apf\db\mysql5\Table("usuarios_postulaciones");
     $selectPostulaciones = new \apf\db\mysql5\Select($postulacionesTable);
     $selectPostulaciones->fields(array("id_oferta"));
     $selectPostulaciones->where(array(array("field" => "id_usuario", "value" => $usuario->getId())));
     $tmpWhere[] = array("field" => "ofertas.id", "operator" => "NOT IN", "value" => $selectPostulaciones);
     $prefCriterios = $usuario->getPreferencia("criterios");
     if ($prefCriterios) {
         $cantCriterios = sizeof($prefCriterios);
         foreach ($prefCriterios as $key => $criterio) {
             if ($key == 0) {
                 $tmpWhere[] = array("field" => "ofertas.titulo", "operator" => "LIKE", "value" => "%{$criterio}%", "begin_enclose" => TRUE);
             } else {
                 if ($key == $cantCriterios - 1) {
                     $tmpWhere[] = array("field" => "ofertas.titulo", "operator" => "LIKE", "value" => "%{$criterio}%", "end_enclose" => TRUE);
                 } else {
                     $tmpWhere[] = array("field" => "ofertas.titulo", "operator" => "LIKE", "value" => "%{$criterio}%");
                 }
             }
         }
     }
     foreach ($tmpWhere as $key => $value) {
         $where[] = $value;
         $op = $value["operator"] == "LIKE" ? "OR" : "AND";
         $where[] = array("operator" => $op);
     }
     unset($where[sizeof($where) - 1]);
     if ($intervalo) {
         $where[] = array("operator" => "AND");
         $where[] = array("field" => "ofertas.fecha_publicacion", "operator" => "BETWEEN", "value" => array("min" => "DATE_SUB(NOW(), INTERVAL {$intervalo} {$tipo})", "max" => "NOW()"));
     }
     $select->where($where);
     $select->group(array("ofertas.id"));
     $select->orderBy(array("fecha_publicacion"), "DESC");
     $res = $select->execute($smartMode = FALSE);
     $ofertas = array();
     $class = __CLASS__;
     foreach ($res as $r) {
         $oferta = new Oferta();
         $oferta->setId($r["idOferta"]);
         $oferta->setEmail($r["email"]);
         $oferta->setTitulo($r["titulo"]);
         $ofertas[] = $oferta;
     }
     return $ofertas;
 }