示例#1
0
 public static function getOfertaById($idOferta)
 {
     $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", "ofertas.cuerpo", "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(array("field" => "ofertas.id", "value" => (int) $idOferta));
     $select->where($where);
     $select->group(array("ofertas.id"));
     $res = $select->execute($smartMode = TRUE);
     $class = __CLASS__;
     $oferta = new Oferta();
     $oferta->setId($res["idOferta"]);
     $oferta->setEmail($res["email"]);
     $oferta->setTitulo($res["titulo"]);
     $oferta->setCuerpo($res["cuerpo"]);
     return $oferta;
 }