Ver Mensaje Individual
  #16 (permalink)  
Antiguo 30/09/2011, 01:09
miktrv
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 18 años, 2 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Modelo

Código PHP:
<?php

/*

  Description
  @author    _ssx
  @package    Aseguradoras

 */

class Aseguradoras_model extends CI_Model {
    
/*
      @package    Aseguradoras

      @access     public
      @return     void
     */

    
public function __construct() {

        
parent::__construct();
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     array
      @param      String
     */

    
public function get_all($sql_extra = '') {

        
$out = array();

        
$sql = '
        
            SELECT
                ' 
. TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA . ', 
            ' 
. TABLE_ASEGURADORAS_FIELD_ASEGURADORA . ', 
            ' 
. TABLE_ASEGURADORAS_FIELD_DIRECCION . ', 
            ' 
. TABLE_ASEGURADORAS_FIELD_LOGO . ', 
            ' 
. TABLE_ASEGURADORAS_FIELD_URL_PORTAL . ', 
            ' 
. TABLE_ASEGURADORAS_FIELD_ACTIVO . '

            FROM ' 
. TABLE_ASEGURADORAS . '

        '
;

        if (!empty(
$sql_extra)) {
            
$sql .= ' ' . $sql_extra;
        }

        
$query = mysql_query($sql);

        while (
$row = mysql_fetch_array($query)) {

            
$temp_object = new Aseguradoras_entity();
            
$temp_object->set_id_aseguradora($row[TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA]);
            
$temp_object->set_aseguradora($row[TABLE_ASEGURADORAS_FIELD_ASEGURADORA]);
            
$temp_object->set_direccion($row[TABLE_ASEGURADORAS_FIELD_DIRECCION]);
            
$temp_object->set_logo($row[TABLE_ASEGURADORAS_FIELD_LOGO]);
            
$temp_object->set_url_portal($row[TABLE_ASEGURADORAS_FIELD_URL_PORTAL]);
            
$temp_object->set_activo($row[TABLE_ASEGURADORAS_FIELD_ACTIVO]);

            
//add object to array
            
array_push($out, $temp_object);
        }

        return 
$out;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     array
      @param      Integer
      @param      Integer
      @param      String
     */

    
public function get_all_extends($limit_left = FALSE, $limit_right = FALSE, $condition = '') {

        
$sql_extra = '';

        if (!empty(
$condition)) {
            
$sql_extra .= ' WHERE ' . $condition;
        }

        if (
is_numeric($limit_left)) {
            
$sql_extra .= ' LIMIT ' . $limit_left;
        }

        if (
is_numeric($limit_right) and is_numeric($limit_left)) {
            
$sql_extra .= ', ' . $limit_right;
        }


        return 
$this->get_all($sql_extra);
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     integer
      @param      String
     */

    
public function get_count($condition = '') {

        
$out = 0;

        
$sql =
                
'   
            SELECT 
            COUNT(' 
. TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA . ') AS count 
            FROM ' 
. TABLE_ASEGURADORAS . ' 

        '
;

        if (!empty(
$condition)) {
            
$sql .= ' WHERE ' . $condition;
        }

        
$query = mysql_query($sql);

        
$row = mysql_fetch_array($query);

        
$out = $row['count'];

        return 
$out;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     Aseguradoras
      @param      Integer
     */

    
public function get_by_id_aseguradora($id_aseguradora = FALSE) {

        
$Aseguradoras_entity = new Aseguradoras_entity();

        if (
$id_aseguradora) {

            
$Aseguradoras_entity->set_id_aseguradora($id_aseguradora);

            
$sql = '

            SELECT
                    ' 
. TABLE_ASEGURADORAS_FIELD_ASEGURADORA . ', 
                ' 
. TABLE_ASEGURADORAS_FIELD_DIRECCION . ', 
                ' 
. TABLE_ASEGURADORAS_FIELD_LOGO . ', 
                ' 
. TABLE_ASEGURADORAS_FIELD_URL_PORTAL . ', 
                ' 
. TABLE_ASEGURADORAS_FIELD_ACTIVO . '

            FROM ' 
. TABLE_ASEGURADORAS . '
            WHERE ' 
. TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA . ' = \'' . $Aseguradoras_entity->get_id_aseguradora() . '\'

            '
;

            
$query = mysql_query($sql);
            
$row = mysql_fetch_array($query);
            
$Aseguradoras_entity->set_aseguradora($row[TABLE_ASEGURADORAS_FIELD_ASEGURADORA]);
            
$Aseguradoras_entity->set_direccion($row[TABLE_ASEGURADORAS_FIELD_DIRECCION]);
            
$Aseguradoras_entity->set_logo($row[TABLE_ASEGURADORAS_FIELD_LOGO]);
            
$Aseguradoras_entity->set_url_portal($row[TABLE_ASEGURADORAS_FIELD_URL_PORTAL]);
            
$Aseguradoras_entity->set_activo($row[TABLE_ASEGURADORAS_FIELD_ACTIVO]);
        }

        return 
$Aseguradoras_entity;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     boolean
      @param      Integer
     */

    
public function exists_by_id_aseguradora($id_aseguradora = FALSE) {

        
$out = FALSE;

        if (
$id_aseguradora) {

            
$sql =
                    
'   
                SELECT 
                COUNT(' 
. TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA . ') AS count 
                FROM ' 
. TABLE_ASEGURADORAS . ' 
                WHERE ' 
. TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA . ' = \'' . $id_aseguradora . '\'

            '
;

            
$query = mysql_query($sql);

            
$row = mysql_fetch_array($query);

            if (
$row['count'] == 1) {

                
$out = TRUE;
            }
        }

        return 
$out;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     boolean
      @param      Integer
     */

    
public function delete_by_id_aseguradora($id_aseguradora = FALSE) {

        
$out = FALSE;

        if (
$id_aseguradora) {

            
$sql = '

                DELETE FROM ' 
. TABLE_ASEGURADORAS . '
                WHERE ' 
. TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA . ' = \'' . $id_aseguradora . '\'
                LIMIT 1

            '
;

            
mysql_query($sql);

            if (
mysql_affected_rows() == 1) {

                
$out = TRUE;
            }
        }

        return 
$out;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     boolean
      @param      String
      @param      MEDIUMTEXT
      @param      String
      @param      String
      @param      Boolean
     */

    
public function insert($aseguradora = '', $direccion = '', $logo = '', $url_portal = '', $activo = 1) {

        
$out = FALSE;

        if (
$activo) {
            
$activo = 1;
        } else {
            
$activo = 0;
        }


        
$sql = '

        INSERT INTO ' 
. TABLE_ASEGURADORAS . '
        (
            ' 
. TABLE_ASEGURADORAS_FIELD_ASEGURADORA . ', 
            ' 
. TABLE_ASEGURADORAS_FIELD_DIRECCION . ', 
            ' 
. TABLE_ASEGURADORAS_FIELD_LOGO . ', 
            ' 
. TABLE_ASEGURADORAS_FIELD_URL_PORTAL . ', 
            ' 
. TABLE_ASEGURADORAS_FIELD_ACTIVO . '

        )
        VALUES
        (
            \'' 
. $aseguradora . '\', 
            \'' 
. $direccion . '\', 
            \'' 
. $logo . '\', 
            \'' 
. $url_portal . '\', 
            \'' 
. $activo . '\'

        )
        ;
        '
;

        if (
mysql_query($sql) and mysql_affected_rows() == 1) {
            
$out = TRUE;
        }

        return 
$out;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     boolean
      @param      String
      @param      MEDIUMTEXT
      @param      String
      @param      String
      @param      Boolean
     */

    
public function insert_extends($aseguradora = '', $direccion = '', $logo = '', $url_portal = '', $activo = 1) {
        return 
$this->insert($aseguradora, $direccion, $logo, $url_portal, $activo);
    }

//----------------------------------------------------------------------------------------------
}

De los modelos me falta cambiar algún tipo de dato como el mediumtext que no lo uso, y en general, las consultas a la base de datos irán con la librería de CI, ahora están asi pero el generador se puede configurar para cambiar el acceso BBDD fácilmente. De hecho, la idea es que pudas colocar lo que quieras, así cada persona puede usar sus propias librerias si asi lo desea
__________________
Gracias por el Karma :D

empleo ofertas de trabajo