Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This is the model class for table "proyecto".
- *
- * The followings are the available columns in table 'proyecto':
- * @property integer $id_pro
- * @property integer $id_are
- * @property string $nombre_pro
- * @property string $correo_con_pro
- * @property string $direccion_pro
- * @property boolean $publicado_pro
- * @property boolean $activo_pro
- * @property string $fecha_cre_pro
- * @property string $fecha_lim_pro
- * @property string $descripcion_pro
- * @property integer $telefono_con_pro
- * @property integer $stock_biblioteca_pro
- * @property string $cod_biblioteca_pro
- *
- * The followings are the available model relations:
- * @property Archivo[] $archivos
- * @property Tag[] $tags
- * @property Area $idAre
- * @property Estudiante[] $estudiantes
- * @property Prestamo[] $prestamos
- */
- class Proyecto extends CActiveRecord
- {
- var $cod_sis_e;
- var $banderaAct=false;
- /**
- * Returns the static model of the specified AR class.
- * @param string $className active record class name.
- * @return Proyecto the static model class
- */
- public static function model($className=__CLASS__)
- {
- return parent::model($className);
- }
- /**
- * @return string the associated database table name
- */
- public function tableName()
- {
- return 'proyecto';
- }
- /**
- * @return array validation rules for model attributes.
- */
- public function rules()
- {
- // NOTE: you should only define rules for those attributes that
- // will receive user inputs.
- return array(
- array('fecha_lim_pro', 'required'),
- array('id_are, telefono_con_pro, stock_biblioteca_pro', 'numerical', 'integerOnly'=>true),
- array('nombre_pro', 'length', 'max'=>150),
- array('nombre_pro', 'validCharacter'),
- array('correo_con_pro', 'length', 'max'=>50),
- array('correo_con_pro', 'email'),
- array('direccion_pro', 'length', 'max'=>200),
- array('cod_biblioteca_pro', 'length', 'max'=>20),
- array('telefono_con_pro', 'numerical','integerOnly'=>true),
- array('descripcion_pro', 'safe'),
- array('cod_sis_e','validSis'),
- array('cod_sis_e', 'length', 'max'=>9,'min'=>9),
- // The following rule is used by search().
- // Please remove those attributes that should not be searched.
- 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'),
- );
- }
- /**
- * @return array relational rules.
- */
- public function relations()
- {
- // NOTE: you may need to adjust the relation name and the related
- // class name for the relations automatically generated below.
- return array(
- 'archivos' => array(self::HAS_MANY, 'Archivo', 'id_pro'),
- 'tags' => array(self::MANY_MANY, 'Tag', 'proyecto_tag(id_pro, id_tag)'),
- 'idAre' => array(self::BELONGS_TO, 'Area', 'id_are'),
- 'estudiantes' => array(self::MANY_MANY, 'Estudiante', 'proyecto_estudiante(id_pro, id_est)'),
- 'prestamos' => array(self::HAS_MANY, 'Prestamo', 'id_pro'),
- );
- }
- /**
- * @return array customized attribute labels (name=>label)
- */
- public function attributeLabels()
- {
- return array(
- 'id_pro' => 'Id Pro',
- 'id_are' => 'Area del Proyecto',
- 'nombre_pro' => 'Titulo Proyecto',
- 'correo_con_pro' => 'Correo Electronico de Contacto',
- 'direccion_pro' => 'Direccion de Ubicacion',
- 'publicado_pro' => 'Publicado',
- 'activo_pro' => 'Activo',
- 'fecha_cre_pro' => 'Fecha de Creacion del Proyecto',
- 'fecha_lim_pro' => 'Fecha Limite del Proyecto',
- 'descripcion_pro' => 'Descripcion del Proyecto',
- 'telefono_con_pro' => 'Telefono de Contacto',
- 'cod_sis_e' => 'Codigo Sis',
- 'stock_biblioteca_pro' => 'Stock Biblioteca Pro',
- 'cod_biblioteca_pro' => 'Codigo',
- );
- }
- /**
- * Retrieves a list of models based on the current search/filter conditions.
- * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
- */
- public function search()
- {
- // Warning: Please modify the following code to remove attributes that
- // should not be searched.
- $criteria=new CDbCriteria;
- $criteria->compare('id_pro',$this->id_pro);
- $criteria->compare('id_are',$this->id_are);
- $criteria->compare('nombre_pro',$this->nombre_pro,true);
- $criteria->compare('correo_con_pro',$this->correo_con_pro,true);
- $criteria->compare('direccion_pro',$this->direccion_pro,true);
- $criteria->compare('publicado_pro',$this->publicado_pro);
- $criteria->compare('activo_pro',$this->activo_pro);
- $criteria->compare('fecha_cre_pro',$this->fecha_cre_pro,true);
- $criteria->compare('fecha_lim_pro',$this->fecha_lim_pro,true);
- $criteria->compare('descripcion_pro',$this->descripcion_pro,true);
- $criteria->compare('telefono_con_pro',$this->telefono_con_pro);
- $criteria->compare('stock_biblioteca_pro',$this->stock_biblioteca_pro);
- $criteria->compare('cod_biblioteca_pro',$this->cod_biblioteca_pro,true);
- return new CActiveDataProvider($this, array(
- 'criteria'=>$criteria,
- ));
- }
- public function validSis($attribute,$params)
- {
- $res = true;
- // $val = intval($this->$attribute);
- if(!$this->banderaAct){
- $val = preg_match('/^[\d_]{0,28}$/i', $this->$attribute);
- if($this->$attribute != '' ) {
- if($val){
- $model = Estudiante::model()->findByAttributes(array('cod_sis_est'=>$this->$attribute));
- if ($model == null ) $this->addError($attribute, "Es codigo sis {$this->$attribute} no es valido.");
- else if(count($model->proyectos) != 0) $this->addError($attribute, "El estudiante con codigo sis {$this->$attribute} ya fue registrado.");
- }
- else $this->addError($attribute, 'El codigo sis debe contener solo numeros.');
- }else $this->addError($attribute, 'El codigo sis no puede ser vacio.');
- }
- }
- public function validCharacter($attribute ,$params)
- {
- $valid = true;
- $valid = $valid && preg_match('/^[a-z\d_\s]{11,28}$/i', $this->$attribute);
- if (!$valid)
- $this->addError($attribute, "El nombre del Proyecto {$this->$attribute} debe ser mayor a 10 caracteres y \nsolo contener letras mayusculas, minusculas y numeros.");
- return $valid;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement