obj =& get_instance(); $this->ci =& get_instance(); $this->ci->load->library('encrypt'); } // ////////////////////////////////////////////////////////////////////////// // Function: findAll() // // Description: Retrieves and returns data listing from the database // // ////////////////////////////////////////////////////////////////////////// function findAll($start = NULL, $count = NULL) { return $this->find(NULL, $start, $count); } // function findById($key_value) { // return $this->find(array('id' => '$key_value')); // } function findByFilter($filter_rules, $start = NULL, $count = NULL) { return $this->find($filter_rules, $start, $count); } function find($filters = NULL, $start = NULL, $count = NULL) { $results = array(); // Load the database library $this->load->database(); // /////////////////////////////////////////////////////////////////////// // Make a note of the current table record count // /////////////////////////////////////////////////////////////////////// $this->table_record_count = $this->db->count_all( 'eventos' ); $ciu=$this->ubica->ciu; //ciu=$ciu and // Filter could be an array or filter values or an SQL string. $where_clause = ''; if ($filters) { if ( is_string($filters) ) { $where_clause = $filters; } elseif ( is_array($filters) ) { // Build your filter rules if ( count($filters) > 0 ) { foreach ($filters as $field => $value) { $filter_list[] = " $field = '$value' "; } $where_clause = "WHERE ciu=$ciu and " . join(' AND ', $filter_list ); } } }else{ $where_clause = "WHERE ciu=$ciu "; } $limit_clause = ''; if ($start) { if ($count) { $limit_clause = " LIMIT $start, $count "; } else { $limit_clause = " LIMIT $start "; } } $order=' order by id '; // Build up the SQL query string and run the query $sql = 'SELECT *, st_x(the_geom) as x, st_y(the_geom) as y FROM eventos ' . $where_clause . $order .$limit_clause; $query = $this->db->query($sql); if ($query->num_rows() > 0) { // //////////////////////////////////////////////////////////////////// // NOTE: At this stage you could return the entire result set, like: // NOTE: ...return $query->result_array(); // NOTE: ...The generated code loops through the result set to provide // NOTE: ...the oppurtunity to provide further customisations on the // NOTE: ...code (especially if you are generating in verbose mode). // //////////////////////////////////////////////////////////////////// foreach ($query->result_array() as $row) // Go through the result set { // Build up a list for each column from the database and place it in // ...the result set $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'c'); $query_results['categoria'] = $this->ci->c->retrieve_by_pkey($row['idcategoria']); $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->get_user_by_id($query_results['idusuario']); $results[] = $query_results; } } return $results; } // TODO: this won't be possible if there is no primary key for the table. function retrieve_by_pkey($idField) { $results = array(); // Load the db library $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu and $query = $this->db->query("SELECT *, fecha_i-current_date as inc_i, fecha_f-current_date as inc_f, st_x(the_geom) as x, st_y(the_geom) as y FROM eventos WHERE ciu=$ciu and activo=1 and id = $idField LIMIT 1"); if ($query->num_rows() > 0) { $row = $query->row_array(); $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'ecm'); $query_results['categoria'] = $this->ci->ecm->retrieve_by_pkey($row['idcategoria']); /////////////////FECHAS $query_results['inc_i'] = $row['inc_i']; $query_results['inc_f'] = $row['inc_f']; $arreglo_fecha_i=$this->getFecha($query_results['inc_i']); $query_results['txtdia_i']=utf8_encode($arreglo_fecha_i["txtdia"]); $query_results['txtmes_i']=utf8_encode($arreglo_fecha_i["txtmes"]); $query_results['numdia_i']=$arreglo_fecha_i["numdia"];; $arreglo_fecha_f=$this->getFecha($query_results['inc_f']); $query_results['txtdia_f']=utf8_encode($arreglo_fecha_f["txtdia"]); $query_results['txtmes_f']=utf8_encode($arreglo_fecha_f["txtmes"]); $query_results['numdia_f']=$arreglo_fecha_f["numdia"];; /////////////FIN FECHAS $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results = $query_results; } else { $results = false; } return $results; } function add( $data ) { $data["ciu"]=$this->ubica->ciu; // Load the database library $this->load->database(); // Build up the SQL query string $sql = $this->db->insert_string('eventos', $data); $query = $this->db->query($sql); return $this->db->insert_id(); } function modify($keyvalue, $data) { // Load the database library $this->load->database(); // Build up the SQL query string $where = "id = $keyvalue"; $sql = $this->db->update_string('eventos', $data, $where); $query = $this->db->query($sql); } function delete_by_pkey($idField) { // Load the db library $this->load->database(); // /////////////////////////////////////////////////////////////////////// // TODO: Just to eliminate nasty mishaps, the delete query has been // TODO: ...deliberately disabled. Enable it if you mean to by uncommenting // TODO: ...the query function call below // /////////////////////////////////////////////////////////////////////// // $query = $this->db->query("DELETE FROM cla_clasificado WHERE id = '$idField' "); return true; } // Function used to initilialise class variables. // NOTE: Not particularly useful unless you are using model persistence // NOTE: You may want to add default values here. function getByUser($idUsuario) { $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu $sql="select * from eventos where ciu=$ciu and idusuario=$idUsuario and activo=1 order by id"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'c'); $query_results['categoria'] = $this->ci->c->retrieve_by_pkey($row['idcategoria']); $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; } } return $results; } function verificarPropietario($idUsuario,$idEvento) { $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu $sql="select * from eventos where ciu=$ciu and idusuario=$idUsuario and id=$idEvento and activo=1 "; $query = $this->db->query($sql); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { $query_results['id'] = $row['id']; $results[] = $query_results; } $res=true; }else $res=false; return $res; } function eliminar_logica($idEvento){ // Load the db library $this->load->database(); // /////////////////////////////////////////////////////////////////////// // TODO: Just to eliminate nasty mishaps, the delete query has been // TODO: ...deliberately disabled. Enable it if you mean to by uncommenting // TODO: ...the query function call below // /////////////////////////////////////////////////////////////////////// $query = $this->db->query("UPDATE eventos SET activo=0 WHERE id = $idEvento "); return true; } //Buscar Clasificados de una Categoria(inmo, vehiculos, varios, arriendos) con distancia medida desde (x,y) function searchClaCategoria($categoria, $px, $py) { $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; $sql="SELECT *,cla_clasificado.id as idcla,X(the_geom) as x, Y(the_geom) as y, CAST('0.0' AS REAL) as rank ,cast(st_distance(the_geom,GeomFromText( 'POINT('||$px||' '|| $py ||')',32717)) as numeric(10,2)) as distancia FROM cla_clasificado, cla_categoria cat, cla_sub_categoria subcat WHERE ciu=$ciu and eliminado=0 and activo=2 and id_cla_subcategoria=subcat.id and cat.id=subcat.id_cla_categoria and cat.id=$categoria ORDER BY distancia"; //echo $sql; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'c'); $query_results['categoria'] = $this->ci->c->retrieve_by_pkey($row['idcategoria']); $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; } } return $results; } function searchUltimos($px, $py) { $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; $sql="SELECT *,X(the_geom) as x, Y(the_geom) as y, CAST('0.0' AS REAL) as rank ,cast(st_distance(the_geom,GeomFromText( 'POINT('||$px||' '|| $py ||')',32717)) as numeric(10,2)) as distancia FROM eventos WHERE ciu=$ciu and activo=1 ORDER BY id desc,distancia limit 30"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'c'); $query_results['categoria'] = $this->ci->c->retrieve_by_pkey($row['idcategoria']); $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; } } return $results; } function searchRandom() { $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; $sql="SELECT *,X(the_geom) as x, Y(the_geom) as y, CAST('0.0' AS REAL) as rank ,0 as distancia FROM eventos WHERE ciu=$ciu and activo=1 ORDER BY id,distancia limit 15"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'c'); $query_results['categoria'] = $this->ci->c->retrieve_by_pkey($row['idcategoria']); $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; } } return $results; } function searchUltimos2() { $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; $sql="SELECT *,X(the_geom) as x, Y(the_geom) as y, CAST('0.0' AS REAL) as rank ,0 as distancia FROM eventos WHERE ciu=$ciu and activo=1 ORDER BY id,distancia limit 15"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'c'); $query_results['categoria'] = $this->ci->c->retrieve_by_pkey($row['idcategoria']); $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; } } return $results; } //todos los clasificados para SITEMAP EVENTOS function todos() { $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; $sql="SELECT *,X(the_geom) as x, Y(the_geom) as y, CAST('0.0' AS REAL) as rank ,0 as distancia FROM eventos WHERE ciu=$ciu and activo=1 ORDER BY id,distancia"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'c'); $query_results['categoria'] = $this->ci->c->retrieve_by_pkey($row['idcategoria']); $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; } } return $results; } /***** * Para generar todo un KML para el sitemap de todos los Clasificados * */ function getAllKml() { $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu //$sql="select st_askml(the_geom) as kml, * from informacion i "; $sql='select *,st_askml(the_geom) as kml from eventos c where ciu=$ciu order by c.id'; //echo $sql; $query = $this->db->query($sql); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'c'); $query_results['categoria'] = $this->ci->c->retrieve_by_pkey($row['idcategoria']); $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $query_results['kml'] = $row['kml']; $results[] = $query_results; } } return $results; } function ultimosCercanos($x,$y,$notInActividades="",$limite=6) { //ver en cla_clasificados } function incrementarVisita($idEvento){ // Load the db library $this->load->database(); // /////////////////////////////////////////////////////////////////////// // TODO: Just to eliminate nasty mishaps, the delete query has been // TODO: ...deliberately disabled. Enable it if you mean to by uncommenting // TODO: ...the query function call below // /////////////////////////////////////////////////////////////////////// $query = $this->db->query("UPDATE eventos SET visitas=visitas+1 WHERE id = $idEvento "); return true; } function eventosHoy() { $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; $sql="select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where ciu=$ciu and eventos.idcategoria=cat.id and current_date >= fecha_i and current_date <= fecha_f and activo=1 order by cat.id"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $query_results['txtdia']=$this->getDia(-2); $this->ci->load->model('eventos_categoriasmodel', 'cax'); $query_results['categoria'] = $this->ci->cax->retrieve_by_pkey($row['idcategoria']); $arreglo_fecha=$this->getFecha(0); $query_results['txtdia']=utf8_encode($arreglo_fecha["txtdia"]); $query_results['txtmes']=utf8_encode($arreglo_fecha["txtmes"]); $query_results['numdia']=$arreglo_fecha["numdia"];; /////////////////FECHAS $query_results['inc_i'] = $row['inc_i']; $query_results['inc_f'] = $row['inc_f']; $arreglo_fecha_i=$this->getFecha($query_results['inc_i']); $query_results['txtdia_i']=utf8_encode($arreglo_fecha_i["txtdia"]); $query_results['txtmes_i']=utf8_encode($arreglo_fecha_i["txtmes"]); $query_results['numdia_i']=$arreglo_fecha_i["numdia"];; $arreglo_fecha_f=$this->getFecha($query_results['inc_f']); $query_results['txtdia_f']=utf8_encode($arreglo_fecha_f["txtdia"]); $query_results['txtmes_f']=utf8_encode($arreglo_fecha_f["txtmes"]); $query_results['numdia_f']=$arreglo_fecha_f["numdia"];; /////////////FIN FECHAS $query_results['distancia'] = null; $this->ci->load->model('dx_auth/users', 'userss'); $query_results['user'] = $rol=$this->ci->userss->getUserUC($query_results['idusuario']); $results[] = $query_results; } } return $results; } function eventosHoyDistancia($x,$y) { $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; $sql="select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y, cast(st_distance(the_geom,GeomFromText( 'POINT($x $y )',32717)) as numeric(10,2)) as distancia from eventos, eventos_categorias cat where ciu=$ciu and eventos.idcategoria=cat.id and current_date >= fecha_i and current_date <= fecha_f and activo=1 order by cat.id"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $query_results['txtdia']=$this->getDia(-2); $this->ci->load->model('eventos_categoriasmodel', 'cax'); $query_results['categoria'] = $this->ci->cax->retrieve_by_pkey($row['idcategoria']); $arreglo_fecha=$this->getFecha(0); $query_results['txtdia']=utf8_encode($arreglo_fecha["txtdia"]); $query_results['txtmes']=utf8_encode($arreglo_fecha["txtmes"]); $query_results['numdia']=$arreglo_fecha["numdia"];; /////////////////FECHAS $query_results['inc_i'] = $row['inc_i']; $query_results['inc_f'] = $row['inc_f']; $arreglo_fecha_i=$this->getFecha($query_results['inc_i']); $query_results['txtdia_i']=utf8_encode($arreglo_fecha_i["txtdia"]); $query_results['txtmes_i']=utf8_encode($arreglo_fecha_i["txtmes"]); $query_results['numdia_i']=$arreglo_fecha_i["numdia"];; $arreglo_fecha_f=$this->getFecha($query_results['inc_f']); $query_results['txtdia_f']=utf8_encode($arreglo_fecha_f["txtdia"]); $query_results['txtmes_f']=utf8_encode($arreglo_fecha_f["txtmes"]); $query_results['numdia_f']=$arreglo_fecha_f["numdia"];; /////////////FIN FECHAS $query_results['distancia'] = $row['distancia']; $this->ci->load->model('dx_auth/users', 'userss'); $query_results['user'] = $rol=$this->ci->userss->getUserUC($query_results['idusuario']); $results[] = $query_results; } } return $results; } function eventosSemana() { $results = array(); $this->load->database(); //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; // $sql="select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y //from eventos, eventos_categorias cat //where eventos.idcategoria=cat.id and date_part('week', current_date) >= date_part('week', fecha_i) and date_part('week', current_date) <= date_part('week', fecha_f) //and current_date <= fecha_f and date_part('day', fecha_f) > date_part('day', current_date) //order by cat.id, eventos.fecha_i"; $ciu=$this->ubica->ciu; //ciu=$ciu $sql="select * from ( select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f, 1 as icnc, EXTRACT(DOW FROM current_date) as hoy,-1 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+1 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f, 2 as icnc,EXTRACT(DOW FROM current_date), EXTRACT(DOW FROM current_date)+2 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+2 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f, 3 as icnc,EXTRACT(DOW FROM current_date),EXTRACT(DOW FROM current_date)+3 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+3 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f,4 as icnc, EXTRACT(DOW FROM current_date), EXTRACT(DOW FROM current_date)+4 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+4 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f, 5 as icnc,EXTRACT(DOW FROM current_date), EXTRACT(DOW FROM current_date)+5 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+5 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f,6 as icnc,EXTRACT(DOW FROM current_date), EXTRACT(DOW FROM current_date)+6 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+6 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f,7 as icnc, EXTRACT(DOW FROM current_date), EXTRACT(DOW FROM current_date)+7 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+7 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) ) as a order by dia, idcategoria "; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); $incdia=1; foreach ($query->result_array() as $row) // Go through the result set { $query_results['hoy'] = $row['hoy']; $query_results['dia'] = $row['dia']; $query_results['inc'] = $row['icnc']; if($query_results['dia']>6){ $d=($query_results['dia']-7); $query_results['dia']=$d; } $arreglo_fecha=$this->getFecha($query_results['inc']); $query_results['txtdia']=utf8_encode($arreglo_fecha["txtdia"]); $query_results['txtmes']=utf8_encode($arreglo_fecha["txtmes"]); $query_results['numdia']=$arreglo_fecha["numdia"];; /////////////////FECHAS $query_results['inc_i'] = $row['inc_i']; $query_results['inc_f'] = $row['inc_f']; $arreglo_fecha_i=$this->getFecha($query_results['inc_i']); $query_results['txtdia_i']=utf8_encode($arreglo_fecha_i["txtdia"]); $query_results['txtmes_i']=utf8_encode($arreglo_fecha_i["txtmes"]); $query_results['numdia_i']=$arreglo_fecha_i["numdia"];; $arreglo_fecha_f=$this->getFecha($query_results['inc_f']); $query_results['txtdia_f']=utf8_encode($arreglo_fecha_f["txtdia"]); $query_results['txtmes_f']=utf8_encode($arreglo_fecha_f["txtmes"]); $query_results['numdia_f']=$arreglo_fecha_f["numdia"];; /////////////FIN FECHAS $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'cax'); $query_results['categoria'] = $this->ci->cax->retrieve_by_pkey($row['idcategoria']); $query_results['distancia'] = null; $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; $incdia++; } } return $results; } function eventosSemanaDistancia($x,$y) { $results = array(); $this->load->database(); //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; // $sql="select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y //from eventos, eventos_categorias cat //where eventos.idcategoria=cat.id and date_part('week', current_date) >= date_part('week', fecha_i) and date_part('week', current_date) <= date_part('week', fecha_f) //and current_date <= fecha_f and date_part('day', fecha_f) > date_part('day', current_date) //order by cat.id, eventos.fecha_i"; $ciu=$this->ubica->ciu; //ciu=$ciu $sql="select *, cast(st_distance(the_geom,GeomFromText( 'POINT($x $y )',32717)) as numeric(10,2)) as distancia from ( select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f, 1 as icnc, EXTRACT(DOW FROM current_date) as hoy,-1 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+1 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f, 2 as icnc,EXTRACT(DOW FROM current_date), EXTRACT(DOW FROM current_date)+2 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+2 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f, 3 as icnc,EXTRACT(DOW FROM current_date),EXTRACT(DOW FROM current_date)+3 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+3 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f,4 as icnc, EXTRACT(DOW FROM current_date), EXTRACT(DOW FROM current_date)+4 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+4 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f, 5 as icnc,EXTRACT(DOW FROM current_date), EXTRACT(DOW FROM current_date)+5 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+5 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f,6 as icnc,EXTRACT(DOW FROM current_date), EXTRACT(DOW FROM current_date)+6 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+6 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f,7 as icnc, EXTRACT(DOW FROM current_date), EXTRACT(DOW FROM current_date)+7 as dia, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+7 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) ) as a order by dia, idcategoria "; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); $incdia=1; foreach ($query->result_array() as $row) // Go through the result set { $query_results['hoy'] = $row['hoy']; $query_results['dia'] = $row['dia']; $query_results['inc'] = $row['icnc']; if($query_results['dia']>6){ $d=($query_results['dia']-7); $query_results['dia']=$d; } $arreglo_fecha=$this->getFecha($query_results['inc']); $query_results['txtdia']=utf8_encode($arreglo_fecha["txtdia"]); $query_results['txtmes']=utf8_encode($arreglo_fecha["txtmes"]); $query_results['numdia']=$arreglo_fecha["numdia"];; /////////////////FECHAS $query_results['inc_i'] = $row['inc_i']; $query_results['inc_f'] = $row['inc_f']; $arreglo_fecha_i=$this->getFecha($query_results['inc_i']); $query_results['txtdia_i']=utf8_encode($arreglo_fecha_i["txtdia"]); $query_results['txtmes_i']=utf8_encode($arreglo_fecha_i["txtmes"]); $query_results['numdia_i']=$arreglo_fecha_i["numdia"];; $arreglo_fecha_f=$this->getFecha($query_results['inc_f']); $query_results['txtdia_f']=utf8_encode($arreglo_fecha_f["txtdia"]); $query_results['txtmes_f']=utf8_encode($arreglo_fecha_f["txtmes"]); $query_results['numdia_f']=$arreglo_fecha_f["numdia"];; /////////////FIN FECHAS $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'cax'); $query_results['categoria'] = $this->ci->cax->retrieve_by_pkey($row['idcategoria']); $query_results['distancia'] = $row['distancia']; $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; $incdia++; } } return $results; } function getFecha($diasmas=0){ setlocale(LC_ALL,"es_ES@euro","es_ES","esp"); $timest=time(); $timest = date("m/d/Y", strtotime(date("m/d/Y")." +$diasmas day")); $timest=strtotime($timest); $rfecha["txtdia"]= strftime("%A",$timest); //ej: miercoes $rfecha["txtmes"]= strftime("%B",$timest); //ej: febrero $rfecha["numdia"]= strftime("%d",$timest); //ej: 8 $rfecha["numano"]= strftime("%Y",$timest); //ej: 2013 //echo strftime("%A %d de %B del %Y",$timest); //echo utf8_encode( $rfecha["txtdia"])." ".$rfecha["numdia"]." de ".$rfecha["txtmes"]." del".$rfecha["numano"]; return $rfecha; } function getDia($num){ $r=""; switch ($num) { case 0: $r= "Domingo"; break; case 1: $r= "Lunes"; break; case 2: $r= "Martes"; break; case 3: $r= "Miércoles"; break; case 4: $r= "Jueves"; break; case 5: $r= "Viernes"; break; case 6: $r= "Sábado"; break; case -1: $r= "Mañana"; break; case -2: $r= "Hoy"; break; } return $r; } function eventosProximos() { $results = array(); $this->load->database(); //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; $ciu=$this->ubica->ciu; //ciu=$ciu $sql="select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f, eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where ciu=$ciu and eventos.idcategoria=cat.id and activo=1 and current_date <= fecha_f and date_part('week', fecha_f) >date_part('week', current_date) order by cat.id, eventos.fecha_i"; //echo $sql; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'cax'); $query_results['categoria'] = $this->ci->cax->retrieve_by_pkey($row['idcategoria']); /////////////////FECHAS $query_results['inc_i'] = $row['inc_i']; $query_results['inc_f'] = $row['inc_f']; $arreglo_fecha_i=$this->getFecha($query_results['inc_i']); $query_results['txtdia_i']=utf8_encode($arreglo_fecha_i["txtdia"]); $query_results['txtmes_i']=utf8_encode($arreglo_fecha_i["txtmes"]); $query_results['numdia_i']=$arreglo_fecha_i["numdia"];; $arreglo_fecha_f=$this->getFecha($query_results['inc_f']); $query_results['txtdia_f']=utf8_encode($arreglo_fecha_f["txtdia"]); $query_results['txtmes_f']=utf8_encode($arreglo_fecha_f["txtmes"]); $query_results['numdia_f']=$arreglo_fecha_f["numdia"];; /////////////FIN FECHAS $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; } } return $results; } function eventosTodos() { //UNION DE LOS SELECTS DE HOY, SEMANA Y PROXIMOS $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; $sql="select distinct id,* from( select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and current_date >= fecha_i and current_date <= fecha_f union select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and current_date <= fecha_f and date_part('week', fecha_f) >date_part('week', current_date) union select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+1 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+2 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+3 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select eventos.*,cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+4 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+5 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+6 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) union all select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and fecha_f > current_date and EXTRACT(DOY FROM current_date)+7 between EXTRACT(DOY FROM fecha_i) and EXTRACT(DOY FROM fecha_f) )A order by id "; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'c'); $query_results['categoria'] = $this->ci->c->retrieve_by_pkey($row['idcategoria']); $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; } } return $results; } function ultimosEventos2($max=8) { // $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu $sql=" select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where ciu=$ciu and eventos.idcategoria=cat.id and current_date <= fecha_f limit $max"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'ecat'); $query_results['categoria'] = $this->ci->ecat->retrieve_by_pkey($row['idcategoria']); $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; } } return $results; } function ultimosEventos($max=8) { //UNION DE LOS SELECTS DE HOY, SEMANA Y PROXIMOS $results = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; $sql="select * from ( select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and date_part('week', current_date) >= date_part('week', fecha_i) and date_part('week', current_date) <= date_part('week', fecha_f) and current_date <= fecha_f and date_part('day', fecha_f) > date_part('day', current_date) union select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and current_date >= fecha_i and current_date <= fecha_f union select eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and date_part('month', current_date) >= date_part('month', fecha_i) and date_part('month', current_date) <= date_part('month', fecha_f) and current_date <= fecha_f and date_part('week', fecha_f) >date_part('week', current_date) )a order by fecha_i limit $max "; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'c'); //$query_results['categoria'] = $this->ci->c->retrieve_by_pkey($row['idcategoria']); $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; } } return $results; } function eventosDestacados($max=4) { //UNION DE LOS SELECTS DE HOY, SEMANA Y PROXIMOS $results = array(); $results2 = array(); $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu //$sql="select * from buscarsubcategoria_distance('$cadena',$px,$py)"; $sql=" select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f,eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and destacado=1 and current_date <= fecha_f and date_part('day', fecha_f) > date_part('day', current_date) order by eventos.fecha_i limit $max "; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'c'); $query_results['categoria'] = $this->ci->c->retrieve_by_pkey($row['idcategoria']); /////////////////FECHAS $query_results['inc_i'] = $row['inc_i']; $query_results['inc_f'] = $row['inc_f']; $arreglo_fecha_i=$this->getFecha($query_results['inc_i']); $query_results['txtdia_i']=utf8_encode($arreglo_fecha_i["txtdia"]); $query_results['txtmes_i']=utf8_encode($arreglo_fecha_i["txtmes"]); $query_results['numdia_i']=$arreglo_fecha_i["numdia"];; $arreglo_fecha_f=$this->getFecha($query_results['inc_f']); $query_results['txtdia_f']=utf8_encode($arreglo_fecha_f["txtdia"]); $query_results['txtmes_f']=utf8_encode($arreglo_fecha_f["txtmes"]); $query_results['numdia_f']=$arreglo_fecha_f["numdia"];; /////////////FIN FECHAS $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; } } if($query->num_rows() < $max){ // no hay suficientes destacados $newmax=$max-$query->num_rows(); $sql=" select fecha_i-current_date as inc_i, fecha_f-current_date as inc_f,eventos.*, cat.nombre as categoria,X(the_geom) as x, Y(the_geom) as y from eventos, eventos_categorias cat where activo=1 and ciu=$ciu and eventos.idcategoria=cat.id and destacado<>1 and current_date <= fecha_f and date_part('day', fecha_f) > date_part('day', current_date) order by eventos.fecha_i limit $newmax "; $query2 = $this->db->query($sql); if ($query2->num_rows() > 0) { $this->ci->load->model('dx_auth/users', 'users'); foreach ($query2->result_array() as $row) // Go through the result set { $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['fecha_i'] = $row['fecha_i']; $query_results['fecha_f'] = $row['fecha_f']; $query_results['hora'] = $row['hora']; $query_results['telefono'] = $row['telefono']; $query_results['direccion'] = $row['direccion']; $query_results['facebook'] = $row['facebook']; $query_results['foto'] = $row['foto']; $query_results['precio'] = $row['precio']; $query_results['descripcion'] = $row['descripcion']; $query_results['idusuario'] = $row['idusuario']; $query_results['idcategoria'] = $row['idcategoria']; $query_results['activo'] = $row['activo']; $query_results['fecha_creacion'] = $row['fecha_creacion']; $query_results['activo'] = $row['activo']; $query_results['idencode'] = $this->encrypt->encode($row['id']); $query_results['x'] = $row['x']; $query_results['y'] = $row['y']; $query_results['visitas'] = $row['visitas']; $this->ci->load->model('eventos_categoriasmodel', 'c'); $query_results['categoria'] = $this->ci->c->retrieve_by_pkey($row['idcategoria']); /////////////////FECHAS $query_results['inc_i'] = $row['inc_i']; $query_results['inc_f'] = $row['inc_f']; $arreglo_fecha_i=$this->getFecha($query_results['inc_i']); $query_results['txtdia_i']=utf8_encode($arreglo_fecha_i["txtdia"]); $query_results['txtmes_i']=utf8_encode($arreglo_fecha_i["txtmes"]); $query_results['numdia_i']=$arreglo_fecha_i["numdia"];; $arreglo_fecha_f=$this->getFecha($query_results['inc_f']); $query_results['txtdia_f']=utf8_encode($arreglo_fecha_f["txtdia"]); $query_results['txtmes_f']=utf8_encode($arreglo_fecha_f["txtmes"]); $query_results['numdia_f']=$arreglo_fecha_f["numdia"];; /////////////FIN FECHAS $this->ci->load->model('dx_auth/users', 'users'); $query_results['user'] = $rol=$this->ci->users->getUserUC($query_results['idusuario']); $results[] = $query_results; } } } return $results; } function byTitulo($titulo) { $results = array(); // Load the db library $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu $query = $this->db->query("SELECT * FROM noticias WHERE ciu=$ciu and titulo = '$titulo' LIMIT 1"); if ($query->num_rows() > 0) { $row = $query->row_array(); $query_results['id'] = $row['id']; $query_results['titulo'] = $row['titulo']; $query_results['descripcion'] = $row['descripcion']; $query_results['link'] = $row['link']; $query_results['fecha'] = $row['fecha']; $query_results['pubdate'] = $row['pubdate']; $results = $query_results; } else { $results = false; } return $results; } function byTituloPais($titulo) { $results = array(); // Load the db library $this->load->database(); $ciu=$this->ubica->ciu; //ciu=$ciu $query = $this->db->query("SELECT * FROM noticiaspais WHERE ciu=$ciu and titulo = '$titulo' LIMIT 1"); if ($query->num_rows() > 0) { $row = $query->row_array(); $query_results['id'] = $row['id']; $query_results['titulo'] = $row['titulo']; $query_results['descripcion'] = $row['descripcion']; $query_results['link'] = $row['link']; $query_results['fecha'] = $row['fecha']; $query_results['pubdate'] = $row['pubdate']; $results = $query_results; } else { $results = false; } return $results; } function ingresar($titulo, $descripcion, $link, $pubdate ){ $t=$this->byTitulo($titulo); $ciu=$this->ubica->ciu; if($t){ //encontro return $t["id"]; }else{ $dataCla = array( 'titulo' => $titulo, 'descripcion' => $descripcion, 'link' => $link , 'pubdate' => $pubdate, 'ciu' => $ciu ); $this->ci->load->model('noticiasmodel', 'nm'); $idcla=$this->ci->nm->add($dataCla); return $idcla; } } function ingresarPais($titulo, $descripcion, $link, $pubdate ){ $t=$this->byTituloPais($titulo); $ciu=$this->ubica->ciu; if($t){ //encontro return $t["id"]; }else{ $dataCla = array( 'titulo' => $titulo, 'descripcion' => $descripcion, 'link' => $link , 'pubdate' => $pubdate, 'ciu' => $ciu ); $this->ci->load->model('noticiaspaismodel', 'nm'); $idcla=$this->ci->nm->add($dataCla); return $idcla; } } } ?>