TimestampBehavior::class, 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at', 'value' => new Expression('NOW()'), ], ]; } /** * {@inheritdoc} */ public function rules() { return [ [['status', 'question_type_id', 'questionnaire_id', 'question_body', 'score'], 'required'], [['question_type_id', 'questionnaire_id', 'question_priority', 'next_question', 'status', 'score', 'time_limit'], 'integer'], [['created_at', 'updated_at'], 'safe'], [['question_body'], 'string', 'max' => 255], [['questionnaire_id'], 'exist', 'skipOnError' => true, 'targetClass' => Questionnaire::className(), 'targetAttribute' => ['questionnaire_id' => 'id']], [['question_type_id'], 'exist', 'skipOnError' => true, 'targetClass' => QuestionType::className(), 'targetAttribute' => ['question_type_id' => 'id']], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'question_type_id' => 'Тип вопроса', 'questionnaire_id' => 'Анкета', 'question_body' => 'Вопрос', 'question_priority' => 'Приоритет вопроса', 'next_question' => 'Следующий вопрос', 'status' => 'Статус', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'time_limit' => 'Время на ответ', 'score' => 'Балы за вопрос', ]; } /** * @return \yii\db\ActiveQuery */ public function getAnswers() { return $this->hasMany(Answer::className(), ['question_id' => 'id']); } /** * @return \yii\db\ActiveQuery */ public function getQuestionnaire() { return $this->hasOne(Questionnaire::className(), ['id' => 'questionnaire_id']); } /** * @return \yii\db\ActiveQuery */ public function getQuestionType() { return $this->hasOne(QuestionType::className(), ['id' => 'question_type_id']); } /** * @return \yii\db\ActiveQuery */ public function getUserResponses() { return $this->hasMany(UserResponse::className(), ['question_id' => 'id']); } public function getStatuses() { return [ self::STATUS_ACTIVE => 'Активен', self::STATUS_PASSIVE => 'Не используется' ]; } public function getStatusText() { return $this->statuses[$this->status]; } public function getQuestionnaireTitle() { return $this->getQuestionnaire()->one()->title; } public function getQuestionTitle() { return $this->getQuestionType()->one()->question_type; } public function getLimitTime() { if ($this->time_limit === null) { return 'Не ограничено'; } return date("i:s", mktime(null, null, $this->time_limit)); } public static function getActiveQuestions($questionnaire_id) { return self::find()->where(['questionnaire_id' => $questionnaire_id]) ->andWhere(['status' => '1']) ->AsArray() ->all(); } }