<?php

/**
 * This is the model base class for the table "questionario_perguntas_respostas".
 * DO NOT MODIFY THIS FILE! It is automatically generated by giix.
 * If any changes are necessary, you must set or override the required
 * property or method in class "QuestionarioPerguntasRespostas".
 *
 * Columns in table "questionario_perguntas_respostas" available as properties of the model,
 * followed by relations of table "questionario_perguntas_respostas" available as properties of the model.
 *
 * @property integer $QPR_IDQPR
 * @property integer $QPR_IDQUESTIONARIOETAPAS
 * @property integer $QPR_IDPERGUNTA
 * @property integer $QPR_IDRESPOSTA
 *
 * @property QuestionarioEtapas $QuestionarioEtapas
 * @property Perguntas $Perguntas
 */
class QuestionarioPerguntasRespostas extends GxActiveRecord {

	public static function model($className=__CLASS__) {
		return parent::model($className);
	}

	public function tableName() {
		return 'questionario_perguntas_respostas';
	}

	public static function label($n = 1) {
		return Yii::t('app', 'QuestionarioPerguntasRespostas|QuestionarioPerguntasRespostas', $n);
	}

	public static function representingColumn() {
		return 'QPR_IDQPR';
	}

	public function rules() {
		return array(
			array('QPR_IDQPR, QPR_IDQUESTIONARIOETAPAS, QPR_IDPERGUNTA, QPR_IDRESPOSTA', 'numerical', 'integerOnly'=>true),
			array('QPR_IDQUESTIONARIOETAPAS, QPR_IDPERGUNTA, QPR_IDRESPOSTA', 'default', 'setOnEmpty' => true, 'value' => null),
			array('QPR_IDQPR, QPR_IDQUESTIONARIOETAPAS, QPR_IDPERGUNTA, QPR_IDRESPOSTA', 'safe', 'on'=>'search'),
			);
	}

	public function relations() {
		return array(
            'QuestionariosFluxoEtapas' => array(self::BELONGS_TO,
                                               'QuestionariosFluxoEtapas',
                                               'QPR_IDQUESTIONARIOETAPAS',
                                               'joinType'=>'LEFT JOIN'),

            'QuestionarioPerguntas' => array(self::BELONGS_TO,
                                             'QuestionarioPerguntas',
                                             'QPR_IDPERGUNTA',
                                             'joinType'=>'LEFT JOIN'),

            'QuestionarioRespostas' => array(self::BELONGS_TO,
                                             'QuestionarioRespostas',
                                             'QPR_IDRESPOSTA',
                                             'joinType'=>'LEFT JOIN'),
			);
	}

	public function pivotModels() {
		return array(
			);
	}

	public function attributeLabels() {
		return array(
			'QPR_IDQPR' 	           => 'Código',
            'QPR_IDQUESTIONARIOETAPAS' => 'Questionario',
            'QPR_IDPERGUNTA'           => 'Pergunta',
            'QPR_IDRESPOSTA'           => 'Resposta',
			);
	}

	public function search() {
		$criteria = new CDbCriteria;

		$criteria->compare('QPR_IDQPR', $this->QPR_IDQPR);
        $criteria->compare('QPR_IDQUESTIONARIOETAPAS', $this->QPR_IDQUESTIONARIOETAPAS, true);
        $criteria->compare('QPR_IDPERGUNTA', $this->QPR_IDPERGUNTA, true);
        $criteria->compare('QPR_IDRESPOSTA', $this->QPR_IDRESPOSTA, true);

		return new CActiveDataProvider($this, array(
			'criteria' => $criteria,
			'sort' => array(
				'defaultOrder'=> 'QPR_IDQUESTIONARIOETAPAS ASC',
				),
			'pagination' => array(
				'pageSize' => 20,
				)
			)
		);
	}
}