category_id = (int) $this->category_id ?: 1; $this->time_limit = (int) $this->time_limit; $this->points = (int) $this->points; if (!in_array($this->time_limit, [30, 45, 60, 90], true) || $this->points < 1 || $this->points > 9) { $this->setError('COM_TESTQUESTIONS_ERROR_META'); return false; } $this->question_type = $this->question_type ?: 'closed'; if (!in_array($this->question_type, ['closed', 'open'], true)) { $this->setError('COM_TESTQUESTIONS_ERROR_QUESTION_TYPE'); return false; } if ($this->question_type === 'open') { if (trim((string) $this->answer_open) === '') { $this->setError('COM_TESTQUESTIONS_ERROR_OPEN_PATTERN'); return false; } $this->correct_answer = 0; } else { foreach (['answer_a', 'answer_b', 'answer_c', 'answer_d'] as $answer) { if (trim((string) $this->$answer) === '') { $this->setError('COM_TESTQUESTIONS_ERROR_ALL_ANSWERS'); return false; } } } $this->correct_answer = (int) $this->correct_answer; if ($this->question_type === 'closed' && ($this->correct_answer < 1 || $this->correct_answer > 4)) { $this->setError('COM_TESTQUESTIONS_ERROR_CORRECT_ANSWER'); return false; } return parent::check($updateNulls); } }