Ver Mensaje Individual
  #29 (permalink)  
Antiguo 05/10/2011, 01:03
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

Model
Código PHP:
<?php

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     boolean
        @param      Integer
    */

    
public function exists_by_id_aseguradora($id_aseguradora = FALSE) {
    
        
$out = 0;

        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     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 . ' = \'' . $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     integer
        @param      Integer
        @param      String
        @param      MEDIUMTEXT
        @param      String
        @param      String
        @param      Boolean
    */

    
public function update_by_id_aseguradora($id_aseguradora, $aseguradora, $direccion, $logo, $url_portal, $activo) {
    
        
$out = 0;
    
        if(
$id_aseguradora) {

    
            
$sql = '

            UPDATE ' 
. TABLE_ASEGURADORAS . ' SET 
                    ' 
. TABLE_ASEGURADORAS_FIELD_ASEGURADORA . ' = \'' . $aseguradora . '\', 
                ' 
. TABLE_ASEGURADORAS_FIELD_DIRECCION . ' = \'' . $direccion . '\', 
                ' 
. TABLE_ASEGURADORAS_FIELD_LOGO . ' = \'' . $logo . '\', 
                ' 
. TABLE_ASEGURADORAS_FIELD_URL_PORTAL . ' = \'' . $url_portal . '\', 
                ' 
. TABLE_ASEGURADORAS_FIELD_ACTIVO . ' = \'' . $activo . '\'
            WHERE ' 
. TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA . ' = \'' . $id_aseguradora . '\'

            '
;
    
            
$query = mysql_query($sql);
            
$out = mysql_affected_rows();

        }

        return 
$out;

    }

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


    /*
        @package    Aseguradoras

        @access     public
        @return     integer
        @param      Integer
    */

    
public function delete_by_id_aseguradora($id_aseguradora = FALSE) {
    
        
$out = 0;

        if(
$id_aseguradora) {

            
$sql = 
            
'   
                DELETE FROM ' 
. TABLE_ASEGURADORAS . ' 
                WHERE ' 
. TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA . ' = \'' . $id_aseguradora . '\'

            '
;

            
$query = mysql_query($sql);

            
$out = mysql_affected_rows();

        }

        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);
    }

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

}
__________________
Gracias por el Karma :D

empleo ofertas de trabajo