Advertisement
yacel100

modelProyecto

Jun 17th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.44 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * This is the model class for table "proyecto".
  5.  *
  6.  * The followings are the available columns in table 'proyecto':
  7.  * @property integer $id_pro
  8.  * @property integer $id_are
  9.  * @property string $nombre_pro
  10.  * @property string $correo_con_pro
  11.  * @property string $direccion_pro
  12.  * @property boolean $publicado_pro
  13.  * @property boolean $activo_pro
  14.  * @property string $fecha_cre_pro
  15.  * @property string $fecha_lim_pro
  16.  * @property string $descripcion_pro
  17.  * @property integer $telefono_con_pro
  18.  * @property integer $stock_biblioteca_pro
  19.  * @property string $cod_biblioteca_pro
  20.  *
  21.  * The followings are the available model relations:
  22.  * @property Archivo[] $archivos
  23.  * @property Tag[] $tags
  24.  * @property Area $idAre
  25.  * @property Estudiante[] $estudiantes
  26.  * @property Prestamo[] $prestamos
  27.  */
  28. class Proyecto extends CActiveRecord
  29. {
  30.  
  31.     var $cod_sis_e;
  32.     var $banderaAct=false;
  33.     /**
  34.      * Returns the static model of the specified AR class.
  35.      * @param string $className active record class name.
  36.      * @return Proyecto the static model class
  37.      */
  38.     public static function model($className=__CLASS__)
  39.     {
  40.         return parent::model($className);
  41.     }
  42.  
  43.     /**
  44.      * @return string the associated database table name
  45.      */
  46.     public function tableName()
  47.     {
  48.         return 'proyecto';
  49.     }
  50.  
  51.     /**
  52.      * @return array validation rules for model attributes.
  53.      */
  54.     public function rules()
  55.     {
  56.         // NOTE: you should only define rules for those attributes that
  57.         // will receive user inputs.
  58.         return array(
  59.             array('fecha_lim_pro', 'required'),
  60.             array('id_are, telefono_con_pro, stock_biblioteca_pro', 'numerical', 'integerOnly'=>true),
  61.             array('nombre_pro', 'length', 'max'=>150),
  62.             array('nombre_pro', 'validCharacter'),
  63.             array('correo_con_pro', 'length', 'max'=>50),
  64.             array('correo_con_pro', 'email'),
  65.             array('direccion_pro', 'length', 'max'=>200),
  66.             array('cod_biblioteca_pro', 'length', 'max'=>20),
  67.             array('telefono_con_pro', 'numerical','integerOnly'=>true),
  68.             array('descripcion_pro', 'safe'),
  69.             array('cod_sis_e','validSis'),
  70.             array('cod_sis_e', 'length', 'max'=>9,'min'=>9),
  71.             // The following rule is used by search().
  72.             // Please remove those attributes that should not be searched.
  73.             array('id_pro, id_are, nombre_pro, correo_con_pro, direccion_pro, publicado_pro, activo_pro, fecha_cre_pro, fecha_lim_pro, descripcion_pro, telefono_con_pro, stock_biblioteca_pro, cod_biblioteca_pro', 'safe', 'on'=>'search'),
  74.         );
  75.     }
  76.  
  77.     /**
  78.      * @return array relational rules.
  79.      */
  80.     public function relations()
  81.     {
  82.         // NOTE: you may need to adjust the relation name and the related
  83.         // class name for the relations automatically generated below.
  84.         return array(
  85.             'archivos' => array(self::HAS_MANY, 'Archivo', 'id_pro'),
  86.             'tags' => array(self::MANY_MANY, 'Tag', 'proyecto_tag(id_pro, id_tag)'),
  87.             'idAre' => array(self::BELONGS_TO, 'Area', 'id_are'),
  88.             'estudiantes' => array(self::MANY_MANY, 'Estudiante', 'proyecto_estudiante(id_pro, id_est)'),
  89.             'prestamos' => array(self::HAS_MANY, 'Prestamo', 'id_pro'),
  90.         );
  91.     }
  92.  
  93.     /**
  94.      * @return array customized attribute labels (name=>label)
  95.      */
  96.     public function attributeLabels()
  97.     {
  98.         return array(
  99.             'id_pro' => 'Id Pro',
  100.             'id_are' => 'Area del Proyecto',
  101.             'nombre_pro' => 'Titulo Proyecto',
  102.             'correo_con_pro' => 'Correo Electronico de Contacto',
  103.             'direccion_pro' => 'Direccion de Ubicacion',
  104.             'publicado_pro' => 'Publicado',
  105.             'activo_pro' => 'Activo',
  106.             'fecha_cre_pro' => 'Fecha de Creacion del Proyecto',
  107.             'fecha_lim_pro' => 'Fecha Limite del Proyecto',
  108.             'descripcion_pro' => 'Descripcion del Proyecto',
  109.             'telefono_con_pro' => 'Telefono de Contacto',
  110.             'cod_sis_e' => 'Codigo Sis',
  111.             'stock_biblioteca_pro' => 'Stock Biblioteca Pro',
  112.             'cod_biblioteca_pro' => 'Codigo',
  113.         );
  114.     }
  115.  
  116.     /**
  117.      * Retrieves a list of models based on the current search/filter conditions.
  118.      * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  119.      */
  120.     public function search()
  121.     {
  122.         // Warning: Please modify the following code to remove attributes that
  123.         // should not be searched.
  124.  
  125.         $criteria=new CDbCriteria;
  126.  
  127.         $criteria->compare('id_pro',$this->id_pro);
  128.         $criteria->compare('id_are',$this->id_are);
  129.         $criteria->compare('nombre_pro',$this->nombre_pro,true);
  130.         $criteria->compare('correo_con_pro',$this->correo_con_pro,true);
  131.         $criteria->compare('direccion_pro',$this->direccion_pro,true);
  132.         $criteria->compare('publicado_pro',$this->publicado_pro);
  133.         $criteria->compare('activo_pro',$this->activo_pro);
  134.         $criteria->compare('fecha_cre_pro',$this->fecha_cre_pro,true);
  135.         $criteria->compare('fecha_lim_pro',$this->fecha_lim_pro,true);
  136.         $criteria->compare('descripcion_pro',$this->descripcion_pro,true);
  137.         $criteria->compare('telefono_con_pro',$this->telefono_con_pro);
  138.         $criteria->compare('stock_biblioteca_pro',$this->stock_biblioteca_pro);
  139.         $criteria->compare('cod_biblioteca_pro',$this->cod_biblioteca_pro,true);
  140.  
  141.         return new CActiveDataProvider($this, array(
  142.             'criteria'=>$criteria,
  143.         ));
  144.     }
  145.     public function validSis($attribute,$params)
  146.     {
  147.  
  148.         $res = true;
  149.         // $val  = intval($this->$attribute);
  150.         if(!$this->banderaAct){
  151.             $val = preg_match('/^[\d_]{0,28}$/i', $this->$attribute);
  152.             if($this->$attribute != '' ) {
  153.                     if($val){
  154.                             $model = Estudiante::model()->findByAttributes(array('cod_sis_est'=>$this->$attribute));
  155.  
  156.                             if ($model == null ) $this->addError($attribute, "Es codigo sis {$this->$attribute} no es valido.");
  157.                             else if(count($model->proyectos) != 0) $this->addError($attribute, "El estudiante con codigo sis {$this->$attribute} ya fue registrado.");
  158.                     }
  159.                     else $this->addError($attribute, 'El codigo sis debe contener solo numeros.');
  160.  
  161.             }else  $this->addError($attribute, 'El codigo sis no puede ser vacio.');
  162.         }
  163.     }
  164.  
  165.     public function validCharacter($attribute ,$params)
  166.     {
  167.         $valid = true;
  168.  
  169.         $valid = $valid && preg_match('/^[a-z\d_\s]{11,28}$/i', $this->$attribute);
  170.  
  171.         if (!$valid)
  172.                 $this->addError($attribute, "El nombre del Proyecto {$this->$attribute} debe ser mayor a 10 caracteres y \nsolo contener letras mayusculas, minusculas y numeros.");
  173.  
  174.         return $valid;
  175.  
  176.     }
  177.  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement