Ok, modelo Grupos:
<?php
/**
* This is the model class for table "{{grupos}}".
*
* The followings are the available columns in table '{{grupos}}':
* @property integer $codigrup
* @property string $codisede
* @property integer $codigrad
* @property string $nombgrup
*/
class Grupos extends CActiveRecord {
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Grupos 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 '{{grupos}}';
}
/**
* @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('codisede, codigrad, nombgrup', 'required'),
array('codigrad', 'numerical', 'integerOnly' => true),
array('codisede', 'length', 'max' => 20),
array('nombgrup', 'length', 'max' => 30),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('codigrup, codisede, codigrad, nombgrup', '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(
'sede' => array(self::BELONGS_TO, 'Sedes', 'codisede'),
'grado' => array(self::BELONGS_TO, 'Grados', 'codigrad'),
'cursos' => array(self::HAS_MANY, 'Cursos', 'codigrup')
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels() {
return array(
'codigrup' => 'Codigo',
'codisede' => 'Sede',
'codigrad' => 'Grado',
'nombgrup' => 'Nombre',
);
}
/**
* 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('codigrup', $this->codigrup);
$criteria->compare('codisede', $this->codisede, true);
$criteria->compare('codigrad', $this->codigrad);
$criteria->compare('nombgrup', $this->nombgrup, true);
$criteria->with = array('sede', 'grado');
return new CActiveDataProvider($this, array(
'criteria' => $criteria, 'pagination' => array('pageSize' => 20)
));
}
}
Modeo Grados
<?php
/**
* This is the model class for table "{{grados}}".
*
* The followings are the available columns in table '{{grados}}':
* @property integer $codigrad
* @property integer $codinive
* @property string $descgrad
*/
class Grados extends CActiveRecord {
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Grados 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 '{{grados}}';
}
/**
* @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('codigrad, codinive, descgrad', 'required'),
array('codigrad, codinive', 'numerical', 'integerOnly' => true),
array('descgrad', 'length', 'max' => 50),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('codigrad, codinive, descgrad', '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(
'nivelEscolaridad' => array(self::BELONGS_TO, 'NivelesEscolares', 'codinive')
);
}
public function scopes() {
parent::scopes();
return array(
'superiores' => array('condition' => 't.codigrad IN (0, 5, 9, 11)')
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels() {
return array(
'codigrad' => 'Codigrad',
'codinive' => 'Codinive',
'descgrad' => 'Descgrad',
);
}
/**
* 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('codigrad', $this->codigrad);
$criteria->compare('codinive', $this->codinive);
$criteria->compare('descgrad', $this->descgrad, true);
$criteria->with = array('nivelEscolaridad');
return new CActiveDataProvider($this, array(
'criteria' => $criteria, 'pagination' => array('pageSize' => 20)
));
}
}