public function validateAttr(Task $model) { if ($model->task_type == static::TYPE_CHOICE) { if (!$model['option_A']) { $model->addError('option_A', Yii::t('app', 'The option_A cannot be blank.')); } if (!$model['option_B']) { $model->addError('option_B', Yii::t('app', 'The option_B cannot be blank.')); } if (!$model['answer_choice']) { $model->addError('answer_choice', Yii::t('app', 'The answer_choice cannot be blank.')); } $optionArr = ['A' => $model['option_A'], 'B' => $model['option_B'], 'C' => $model['option_C'], 'D' => $model['option_D']]; $optionArr = array_filter($optionArr); $choiceArr = $model['answer_choice']; if (!$this->validateAnswer($optionArr, $choiceArr)) { $model->addError('answer_choice', Yii::t('app', 'The answer_choice is not correct.')); } unset($model['answer_choice']); $model->option_json = json_encode($optionArr); $model->answer_json = json_encode($choiceArr); if ($model->is_timing == static::IS_NOT_TIMING) { $model->complete_time = '00:00'; } } // if ($model->task_type == static::TYPE_SHORT_ANSWER || $model->task_type == static::TYPE_CALCULATION) { // if (empty($model->answer_json)) { // $model->addError('answer_json', Yii::t('app', 'The answer_json cannot be blank.')); // } // } if ($model->task_type == static::TYPE_CODING) { if (empty($model['code_test_one_input'])) { $model->addError('code_test_one_input', Yii::t('app', 'code_test_one_input cannot be blank.')); } if (empty($model['code_test_one_output'])) { $model->addError('code_test_one_output', Yii::t('app', 'code_test_one_output cannot be blank.')); } } $model->update_time = Common::getTime(); return $model; }