Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Proyecto Biblios
- * Proyecto desarrollado por 3WD.
- *
- * @package CodeIgniter
- * @author 3WD - Tomas Losis <tomas.losis@treswd.com>
- * @since Version 1.0 Marzo 2012
- * @description Modelo de tabla de paises
- */
- class Mauthor extends CI_Model {
- private $tbl_author_ppi = 'autores_ppi';
- private $tbl_author_censo83 = 'autores_censo83';
- private $tbl_autores = 'autores';
- private $tbl_autores_ppi_ano = 'autores_ppi_ano';
- // RENAME TABLE `autores_ppi_aƱo` TO `autores_ppi_ano`
- private $tbl_autores_filiacion = 'autores_filiacion';
- private $tbl_pais = 'paises';
- private $tbl_ciudad = 'ciudades';
- private $tbl_filiacion = 'filiacion';
- function __construct() {
- // Call the Model constructor
- parent::__construct();
- }
- public function getAllList($sort, $direction, $limit = 10, $offset = 0) {
- $search = $this->session->userdata('search');
- $this->db->select("*");
- $this->db->from('autores');
- if (!empty($search)) {
- $this->db->where('(nom_usuario like "%' . $search . '%" OR ape_usuario like "%' . $search . '%" OR email like "%' . $search . '%")');
- }
- $this->db->order_by($sort, $direction);
- $this->db->limit($limit, $offset);
- return $this->db->get();
- }
- public function getNumList() {
- $search = $this->session->userdata('search');
- $this->db->select("*");
- $this->db->from('autores');
- if (!empty($search)) {
- $this->db->where('(nom_usuario like "%' . $search . '%" OR ape_usuario like "%' . $search . '%" OR email like "%' . $search . '%")');
- }
- $this->db->order_by('id_autor', 'desc');
- $query = $this->db->get();
- return $query->num_rows();
- }
- public function insert($nombre, $apellido, $genero, $nacionalidad, $cedula, $nacimiento, $email, $email2, $idUnesco, $palclaves, $maisanta, $telOficina, $telCelular) {
- //insercion en tabla maestra
- $data = array(
- 'NOMBRE' => $nombre,
- 'ID_UNESCO' => $idUnesco,
- 'APELLIDO' => $apellido,
- 'AUTOR' => strtoupper($nombre) . " " . strtoupper($apellido),
- 'GENERO' => $genero,
- 'NACIONALID' => $nacionalidad,
- 'CI' => $cedula,
- 'FECHA_NACI' => $nacimiento,
- 'PALCLAVES' => $palclaves,
- 'MAISANTA' => $maisanta,
- 'TELE_OFI' => $telOficina,
- 'TELE_CEL' => $telCelular,
- 'EMAIL' => $email,
- 'EMAIL_1' => $email2,
- 'ES_PPI' => 'N',
- 'ES_CENSO83' => 'N'
- );
- $this->db->insert('autores', $data);
- $id_user_wp = $this->db->insert_id();
- return $id_user_wp;
- }
- public function delete($idautor) {
- $this->db->where('ID_AUTOR', $idautor);
- return $this->db->delete('autores');
- }
- public function get_row($idautor) {
- $query = $this->db->query("SELECT NOMBRE, APELLIDO, GENERO, NACIONALID, CI, FECHA_NACI, EMAIL, EMAIL_1, PALCLAVES, MAISANTA, TELE_OFI, TELE_CEL, ES_PPI, ES_CENSO83, ID_UNESCO FROM autores WHERE ID_AUTOR='" . $idautor . "' LIMIT 1");
- if ($row = $query->row())
- return array($row->NOMBRE, $row->APELLIDO, $row->GENERO, $row->NACIONALID, $row->CI, $row->FECHA_NACI, $row->EMAIL, $row->EMAIL_1, $row->PALCLAVES, $row->MAISANTA, $row->TELE_OFI, $row->TELE_CEL, $row->ES_PPI, $row->ES_CENSO83, $row->ID_UNESCO);
- else
- return FALSE;
- }
- public function update($id, $nombre, $apellido, $genero, $nacionalidad, $cedula, $nacimiento, $email, $email2, $idUnesco, $palclaves, $maisanta, $telOficina, $telCelular) {
- //insercion en tabla maestra
- $data = array(
- 'NOMBRE' => $nombre,
- 'ID_UNESCO' => $idUnesco,
- 'APELLIDO' => $apellido,
- 'AUTOR' => strtoupper($nombre) . " " . strtoupper($apellido),
- 'GENERO' => $genero,
- 'NACIONALID' => $nacionalidad,
- 'CI' => $cedula,
- 'FECHA_NACI' => $nacimiento,
- 'PALCLAVES' => $palclaves,
- 'MAISANTA' => $maisanta,
- 'TELE_OFI' => $telOficina,
- 'TELE_CEL' => $telCelular,
- 'EMAIL' => $email,
- 'EMAIL_1' => $email2,
- 'ES_PPI' => 'N',
- 'ES_CENSO83' => 'N'
- );
- $this->db->where('ID_AUTOR', $id);
- $this->db->update('autores', $data);
- }
- /**
- * Get all magazines for show up in a Modal Window
- * @param int $limit
- * @param int $start
- * @return boolean
- */
- public function getAllAuthor($limit, $start) {
- $this->db->limit($limit, $start);
- $query = $this->db->get('autores');
- if ($query->num_rows() > 0) {
- foreach ($query->result() as $row) {
- $data[] = $row;
- }
- return $data;
- }
- return false;
- }
- /**
- * Count how many magazines exists
- * @return int
- */
- public function getCountList() {
- $this->db->select("*");
- $this->db->from('autores');
- return $this->db->get()->num_rows();
- }
- /**
- * Associated new authors
- */
- public function associateAuthor($data = array()) {
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$data || empty($data))
- return FALSE;
- $this->db->select('*');
- $this->db->where('ID_ARTICULO', $data['id_article']);
- $this->db->where('ID_AUTOR', $data['id_author']);
- if ($this->db->get('articulos_autores')->num_rows() > 0) {
- return FALSE;
- } else {
- $this->db->select('ORDEN_AUTORES');
- $this->db->where('ID_ARTICULO', $data['id_article']);
- $this->db->order_by('ORDEN_AUTORES', 'DESC');
- $result = $this->db->get('articulos_autores')->result();
- $data_insert = array(
- 'ID_ARTICULO' => $data['id_article'],
- 'ID_AUTOR' => $data['id_author'],
- 'ORDEN_AUTORES' => $result[0]->ORDEN_AUTORES + 1
- );
- $this->db->insert('articulos_autores', $data_insert);
- }
- }
- public function getOne($author_id) {
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$author_id)
- return FALSE;
- $this->db->where('id_autor', (int) $author_id);
- return $this->db->get('autores')->row();
- }
- public function getFieldsName($table_name) {
- return $this->db->list_fields($table_name);
- }
- /**
- * Get PPI author data based on author_id parameter
- * @param mixed $author_id The primary key as identifier
- * @return boolean Whether or not there were any errors
- */
- public function getPPI($author_id) {
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$author_id)
- return FALSE;
- $this->db->where($this->tbl_author_ppi . '.ID_AUTOR', (int) $author_id);
- return $this->db->get($this->tbl_author_ppi)->row_array();
- }
- /**
- * Get PPI author data based on author_id parameter
- * @param mixed $author_id The primary key as identifier
- * @return boolean Whether or not there were any errors
- */
- public function getPPIByID($ppi_id) {
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$ppi_id)
- return FALSE;
- $this->db->where($this->tbl_author_ppi . '.ID_AUTOR_PPI', (int) $ppi_id);
- return $this->db->get($this->tbl_author_ppi)->row_array();
- }
- /**
- * Add PPI author data
- *
- * @param array $author_id The new data for the array
- * @return boolean Whether or not there were any errors
- */
- public function addPPI($data = array()) {
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$data || empty($data))
- return FALSE;
- if ($this->db->insert($this->tbl_author_ppi, $data)) {
- return TRUE;
- }
- }
- /**
- * Add Censo83 author data
- *
- * @param array $author_id The new data for the array
- * @return boolean Whether or not there were any errors
- */
- public function addCenso83($data = array()) {
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$data || empty($data))
- return FALSE;
- if ($this->db->insert($this->tbl_author_censo83, $data)) {
- return TRUE;
- }
- }
- public function getCenso83($id_author) {
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$id_author)
- return FALSE;
- return $this->db->where('id_autor', (int) $id_author)->get($this->tbl_author_censo83)->result();
- }
- /**
- * Add PPI author data
- *
- * @param array $author_id The new data for the array
- * @return boolean Whether or not there were any errors
- */
- public function updatePPI($data = array(), $ppi_id) {
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$data || empty($data) || !$ppi_id || $ppi_id == NULL)
- return FALSE;
- $this->db->where('ID_AUTOR_PPI', (int) $ppi_id);
- if ($this->db->update($this->tbl_author_ppi, $data)) {
- return TRUE;
- }
- }
- /**
- * Get PPI by year for certain author
- * @param mixed $author_id
- * @return boolean if $author_id = NULL or empty or MySQL Object on success
- */
- public function getPPIByAuthor($author_id) {
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$author_id || $author_id == NULL)
- return FALSE;
- $this->db->where('ID_AUTOR', (int) $author_id);
- $this->db->order_by('ANO', 'ASC');
- return $this->db->get($this->tbl_autores_ppi_ano)->result();
- }
- /**
- * Count how many filiated authors are in DB
- * @return integer
- */
- public function getFiliatedAuthors() {
- $query = $this->db->query("SELECT ID_AUTOR FROM autores_filiacion GROUP BY ID_AUTOR");
- return $query->num_rows();
- }
- /**
- * Return how many unfiliated authors are in DB
- * @return type
- */
- public function getUnFiliatedAuthors() {
- $sql = "SELECT COUNT(*) AS qty FROM autores LEFT JOIN autores_filiacion ON (autores.ID_AUTOR = autores_filiacion.ID_AUTOR) WHERE autores.ID_AUTOR NOT IN (SELECT DISTINCT ID_AUTOR FROM autores_filiacion)";
- return $this->db->query($sql)->row()->qty;
- }
- /**
- * Get data from non filiated authors
- * @param integer $limit
- * @param integer $start
- * @return mixed
- */
- public function getNonFiliatedAuthor($limit, $start) {
- $this->db->limit($limit, $start);
- $this->db->join('autores_filiacion', 'autores.ID_AUTOR = autores_filiacion.ID_AUTOR', 'LEFT');
- $this->db->where('autores.ID_AUTOR NOT IN (SELECT DISTINCT ID_AUTOR FROM autores_filiacion)');
- $query = $this->db->get('autores');
- return $query->result();
- }
- /**
- * Count how many PPI authors are in DB
- * @return mixed
- */
- public function getPPIAuthors() {
- $query = $this->db->query("SELECT ID_AUTOR FROM autores_ppi GROUP BY ID_AUTOR");
- return $query->num_rows();
- }
- /**
- * Count how many Censo83 are in DB
- * @return mixed
- */
- public function getCenso83Authors() {
- $query = $this->db->query("SELECT ID_AUTOR FROM autores_censo83 GROUP BY ID_AUTOR");
- return $query->num_rows();
- }
- /**
- * Adds a new PPI to a author
- * @param array $data
- * @return boolean
- */
- public function addPPIByYear($data = array()) {
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$data || empty($data))
- return FALSE;
- //aqui debe colocarse un validador
- if ($this->db->insert($this->tbl_autores_ppi_ano, $data)) {
- return TRUE;
- }
- return FALSE;
- }
- /**
- * Funcion que permite la busqueda/consulta de autores
- * @param array $data
- * @param int $limit
- * @param int $offset
- * @param array $criteria
- * @return boolean
- */
- public function getAllAuthorData($data = array(), $limit = 10, $offset = 0, $criteria = NULL) {
- $this->db->query("SET NAMES 'utf8'");
- $this->db->select('autores.id_autor, autores.nombre, autores.apellido, autores.nacionalid');
- $this->db->from('autores');
- $this->db->distinct();
- if (!empty($data['nombre']) && $data['nombre'] != "") {
- $this->db->like('autores.nombre', $data['nombre'], 'both');
- }
- if (!empty($data['apellido']) && $data['apellido'] != "") {
- $this->db->like('autores.apellido', $data['apellido'], 'both');
- }
- if (!empty($data['gender']) && $data['gender'] != "") {
- $this->db->or_where('autores.genero', $data['gender']);
- }
- if (!empty($data['nacionalidad']) && $data['nacionalidad'] != "") {
- $this->db->or_where('autores.nacionalid', $data['nacionalidad']);
- }
- if (!empty($data['cedula']) && $data['cedula'] != "cedula") {
- $this->db->or_where('autores.ci', $data['cedula']);
- }
- if (!empty($data['fecha_nacimiento']) && $data['fecha_nacimiento'] != "fecha_nacimiento") {
- $this->db->or_where('autores.fecha_naci', $data['fecha_nacimiento']);
- }
- if (!empty($data['email_default']) && $data['email_default'] != "") {
- $this->db->or_where('autores.email', $data['email_default']);
- }
- if (!empty($data['email_alternativo']) && $data['email_alternativo'] != "") {
- $this->db->or_where('autores.email_1', $data['email_alternativo']);
- }
- $this->db->join($this->tbl_autores_filiacion, 'autores.id_autor = autores_filiacion.id_autor', 'left');
- $this->db->join($this->tbl_filiacion, 'autores_filiacion.id_filiacion = filiacion.id_filiacion', 'left');
- if (!empty($data['ciudad']) && $data['ciudad'] != "") {
- $this->db->join($this->tbl_ciudad, 'filiacion.id_ciudad = ciudades.id_ciudad', 'left');
- $this->db->or_like('ciudades.ciudad', $data['ciudad'], 'both');
- }
- if (!empty($data['pais']) && $data['pais'] != "") {
- $this->db->join($this->tbl_pais, 'filiacion.id_pais = paises.id_pais', 'left');
- $this->db->like('paises.pais', $data['pais'], 'both');
- }
- $this->db->limit($limit, $offset);
- $query = $this->db->get();
- if ($query->num_rows() > 0) {
- return $query->result();
- } else {
- return FALSE;
- }
- }
- /**
- * Contar los autores de un PPI
- * @param array $data
- * @return int
- */
- public function getCountAuthorData($data = array()) {
- $this->db->select('autores.id_autor, autores.nombre, autores.apellido, autores.nacionalid');
- $this->db->from('autores');
- $this->db->distinct();
- if (!empty($data['nombre']) && $data['nombre'] != "") {
- $this->db->like('autores.nombre', $data['nombre'], 'both');
- }
- if (!empty($data['apellido']) && $data['apellido'] != "") {
- $this->db->like('autores.apellido', $data['apellido'], 'both');
- }
- if (!empty($data['gender']) && $data['gender'] != "") {
- $this->db->or_where('autores.genero', $data['gender']);
- }
- if (!empty($data['nacionalidad']) && $data['nacionalidad'] != "") {
- $this->db->or_where('autores.nacionalid', $data['nacionalidad']);
- }
- if (!empty($data['cedula']) && $data['cedula'] != "cedula") {
- $this->db->or_where('autores.ci', $data['cedula']);
- }
- if (!empty($data['fecha_nacimiento']) && $data['fecha_nacimiento'] != "fecha_nacimiento") {
- $this->db->or_where('autores.fecha_naci', $data['fecha_nacimiento']);
- }
- if (!empty($data['email']) && $data['email'] != "") {
- $this->db->or_where('autores.email', $data['email']);
- }
- if (!empty($data['email_alternativo']) && $data['email_alternativo'] != "") {
- $this->db->or_where('autores.email_1', $data['email_alternativo']);
- }
- $this->db->join($this->tbl_autores_filiacion, 'autores.id_autor = autores_filiacion.id_autor', 'left');
- $this->db->join($this->tbl_filiacion, 'autores_filiacion.id_filiacion = filiacion.id_filiacion', 'left');
- if (!empty($data['ciudad']) && $data['ciudad'] != "") {
- $this->db->join($this->tbl_ciudad, 'filiacion.id_ciudad = ciudades.id_ciudad', 'left');
- $this->db->or_like('ciudades.ciudad', $data['ciudad'], 'both');
- }
- if (!empty($data['pais']) && $data['pais'] != "") {
- $this->db->join($this->tbl_pais, 'filiacion.id_pais = paises.id_pais', 'left');
- $this->db->like('paises.pais', $data['pais'], 'both');
- }
- $query = $this->db->get();
- return $query->num_rows();
- }
- /**
- * Obtener los detalles de un PPI dado su ID
- * @param int $ppi_id
- * @return boolean
- */
- public function getOnePPI($ppi_id) {
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$ppi_id || empty($ppi_id))
- return FALSE;
- $this->db->where('ID_AUTOR_PPI_ANO', (int) $ppi_id);
- return $this->db->get($this->tbl_autores_ppi_ano)->row();
- }
- /**
- * Actualizar el PPI por aƱo de un autor
- * @param array $data
- * @param int $ppi_id
- * @return boolean
- */
- public function UpdatePPIByYear($data = array(), $ppi_id = NULL) {
- // print_r($data);
- // echo $ppi_id;
- // die();
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$data || empty($data) || !$ppi_id || $ppi_id == NULL)
- return FALSE;
- $this->db->where('ID_AUTOR_PPI_ANO', (int) $ppi_id);
- if ($this->db->update($this->tbl_autores_ppi_ano, $data)) {
- return TRUE;
- }
- }
- /**
- * Eliminar el registro de un PPI por aƱo dado su ID
- * @param int $ppi_id
- * @return boolean
- */
- public function deletePPIByYear($ppi_id) {
- // Security fallback to be sure we run a valid query and don't get MySQL errors
- if (!$ppi_id || empty($ppi_id))
- return FALSE;
- if ($this->db->delete($this->tbl_autores_ppi_ano, array('ID_AUTOR_PPI_ANO' => $ppi_id))) {
- return TRUE;
- }
- return FALSE;
- }
- //metodo utilizado en controller/caffiliation.php
- public function validated_delete_author_affiliation($id) {
- $query = $this->db->query("SELECT ID_FILIACION FROM autores_filiacion WHERE ID_FILIACION='" . $id . "' LIMIT 1");
- if ($row = $query->row())
- return TRUE;
- else
- return FALSE;
- }
- public function validated_delete_article_authors($id) {
- $query = $this->db->query("SELECT ID_AUTOR FROM articulos_autores WHERE ID_AUTOR='" . $id . "' LIMIT 1");
- if ($row = $query->row())
- return TRUE;
- else
- return FALSE;
- }
- public function delete_autores_ppi($id) {
- $this->db->where('ID_AUTOR', $id);
- return $this->db->delete('autores_ppi');
- }
- public function delete_autores_censo83($id) {
- $this->db->where('ID_AUTOR', $id);
- return $this->db->delete('autores_censo83');
- }
- public function delete_autores_ppi_aƱo($id) {
- $this->db->where('ID_AUTOR', $id);
- return $this->db->delete('autores_ppi_ano');
- }
- public function delete_autores_filiacion($id) {
- $this->db->where('ID_AUTOR', $id);
- return $this->db->delete('autores_filiacion');
- }
- public function validated_duplicated_year_ppi($id_author, $year) {
- $query = $this->db->query("SELECT ID_AUTOR_PPI_ANO FROM autores_ppi_ano WHERE ID_AUTOR='" . $id_author . "' AND ANO='" . $year . "' LIMIT 1");
- if ($row = $query->row())
- return TRUE;
- else
- return FALSE;
- }
- }
- /* End of file muser.php */
- /* Location: ./application/backend/models/muser.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement