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 = 0, $count = 100) { $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' ); // 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 " . join(' AND ', $filter_list ); } } } $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 * FROM noticiaspais ' . $where_clause . $order .$limit_clause; //echo $sql; $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['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; } } 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(); $query = $this->db->query("SELECT * FROM noticiaspais WHERE id = $idField 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 add( $data ) { // Load the database library $this->load->database(); // Build up the SQL query string $sql = $this->db->insert_string('noticiaspais', $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('noticiaspais', $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 noticiaspais 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 byTitulo($titulo) { $results = array(); // Load the db library $this->load->database(); $query = $this->db->query("SELECT * FROM noticiaspais WHERE 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); if($t){ //encontro return $t["id"]; }else{ $dataCla = array( 'titulo' => $titulo, 'descripcion' => $descripcion, 'link' => $link , 'pubdate' => $pubdate ); //$this->ci->load->model('noticiaspaismodel', 'nm'); $idcla=$this->add($dataCla); return $idcla; } } function ultimasNoticias($max=5) { $results = array(); $this->load->database(); $sql=" select * from noticiaspais order by id desc limit $max"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { $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; } } return $results; } function parasitemap() { $results = array(); $this->load->database(); $sql=" select id from noticiaspais order by id desc limit 40000 "; $query = $this->db->query($sql); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { $query_results['id'] = $row['id']; $results[] = $query_results; } } return $results; } } ?>