<commit_before><?php

/**
 * This is the model class for table "questions".
 *
 * The followings are the available columns in table 'questions':
 * @property integer $id
 * @property string $type
 * @property integer $question_group_id
 * @property string $title
 * @property integer $position
 * @property string $settings
 *
 * The followings are the available model relations:
 * @property Answers[] $answers
 * @property Propositions[] $propositions
 * @property QuestionGroups $questionGroup
 */
class Question extends MortimerActiveRecord
{
    
    /**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'questions';
	}

	/**
	 * @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('question_group_id, position', 'required'),
			array('question_group_id, position', 'numerical', 'integerOnly'=>true),
			array('type', 'length', 'max'=>63),
			array('title', 'length', 'max'=>255),
			array('settings', 'length', 'max'=>1023),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, type, question_group_id, title, position, settings', '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(
			'answers' => array(self::HAS_MANY, 'Answer', 'question_id'),
			'propositions' => array(self::HAS_MANY, 'Proposition', 'question_id'),
			'questionGroup' => array(self::BELONGS_TO, 'QuestionGroup', 'question_group_id'),
			'survey' => array(self::HAS_ONE, 'Survey', array('survey_id'=>'id'), 'through'=>'questionGroup'),
			'maxProposition' => array(self::STAT, 'Proposition', 'question_id', 'select'=>'MAX(position)')
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'type' => 'Type',
			'question_group_id' => 'Question Group',
			'title' => 'Title',
			'position' => 'Position',
			'settings' => 'Settings',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.<commit_msg>The "delete a question from my survey" functionnality works now !<commit_after><?php

/**
 * This is the model class for table "questions".
 *
 * The followings are the available columns in table 'questions':
 * @property integer $id
 * @property string $type
 * @property integer $question_group_id
 * @property string $title
 * @property integer $position
 * @property string $settings
 *
 * The followings are the available model relations:
 * @property Answers[] $answers
 * @property Propositions[] $propositions
 * @property QuestionGroups $questionGroup
 */
class Question extends MortimerActiveRecord
{
    
    /**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'questions';
	}

	/**
	 * @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('question_group_id, position', 'required'),
			array('question_group_id, position', 'numerical', 'integerOnly'=>true),
			array('type', 'length', 'max'=>63),
			array('title', 'length', 'max'=>255),
			array('settings', 'length', 'max'=>1023),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, type, question_group_id, title, position, settings', '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(
			'answers' => array(self::HAS_MANY, 'Answer', 'question_id'),
            'propositions' => array(self::HAS_MANY, 'Proposition', 'question_id', 'dependant' => 'delete'),
			'questionGroup' => array(self::BELONGS_TO, 'QuestionGroup', 'question_group_id'),
			'survey' => array(self::HAS_ONE, 'Survey', array('survey_id'=>'id'), 'through'=>'questionGroup'),
			'maxProposition' => array(self::STAT, 'Proposition', 'question_id', 'select'=>'MAX(position)')
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'type' => 'Type',
			'question_group_id' => 'Question Group',
			'title' => 'Title',
			'position' => 'Position',
			'settings' => 'Settings',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
{'fraction_non_alphanumeric': 0.14194517461509576, 'fraction_numerical': 0.003379647014645137, 'mean_word_length': 4.186952288218111, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '640699', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1507, 'n_words': 509}