public function validation($data, $files) { $errors = parent::validation($data, $files); // Verifying for errors in {=...} in question text. $errors = $this->validate_text($errors, 'questiontext', $data['questiontext']['text']); $errors = $this->validate_text($errors, 'generalfeedback', $data['generalfeedback']['text']); // Check that the answers use datasets. $answers = $data['answer']; $mandatorydatasets = array(); foreach ($answers as $key => $answer) { $problems = qtype_calculated_find_formula_errors($answer); if ($problems) { $errors['answeroptions[' . $key . ']'] = $problems; } $mandatorydatasets += $this->qtypeobj->find_dataset_names($answer); $errors = $this->validate_text($errors, 'feedback[' . $key . ']', $data['feedback'][$key]['text']); } if (empty($mandatorydatasets)) { foreach ($answers as $key => $answer) { $errors['answeroptions[' . $key . ']'] = get_string('atleastonewildcard', 'qtype_calculated'); } } // Validate the answer format. foreach ($answers as $key => $answer) { $trimmedanswer = trim($answer); if (trim($answer)) { if ($data['correctanswerformat'][$key] == 2 && $data['correctanswerlength'][$key] == '0') { $errors['answerdisplay[' . $key . ']'] = get_string('zerosignificantfiguresnotallowed', 'qtype_calculated'); } } } return $errors; }
public function validation($data, $files) { // verifying for errors in {=...} in question text; $qtext = ""; $qtextremaining = $data['questiontext']['text']; $possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']['text']); foreach ($possibledatasets as $name => $value) { $qtextremaining = str_replace('{'.$name.'}', '1', $qtextremaining); } while (preg_match('~\{=([^[:space:]}]*)}~', $qtextremaining, $regs1)) { $qtextsplits = explode($regs1[0], $qtextremaining, 2); $qtext = $qtext.$qtextsplits[0]; $qtextremaining = $qtextsplits[1]; if (!empty($regs1[1]) && $formulaerrors = qtype_calculated_find_formula_errors($regs1[1])) { if (!isset($errors['questiontext'])) { $errors['questiontext'] = $formulaerrors.':'.$regs1[1]; } else { $errors['questiontext'] .= '<br/>'.$formulaerrors.':'.$regs1[1]; } } } $errors = parent::validation($data, $files); // Check that the answers use datasets. $answers = $data['answer']; $mandatorydatasets = array(); foreach ($answers as $key => $answer) { $mandatorydatasets += $this->qtypeobj->find_dataset_names($answer); } if (empty($mandatorydatasets)) { foreach ($answers as $key => $answer) { $errors['answer['.$key.']'] = get_string('atleastonewildcard', 'qtype_calculated'); } } // Validate the answer format. foreach ($answers as $key => $answer) { $trimmedanswer = trim($answer); if (trim($answer)) { if ($data['correctanswerformat'][$key] == 2 && $data['correctanswerlength'][$key] == '0') { $errors['correctanswerlength['.$key.']'] = get_string('zerosignificantfiguresnotallowed', 'qtype_calculated'); } } } return $errors; }
protected function delete_files($questionid, $contextid) { $fs = get_file_storage(); parent::delete_files($questionid, $contextid); $this->delete_files_in_answers($questionid, $contextid, true); $this->delete_files_in_hints($questionid, $contextid); $fs->delete_area_files($contextid, 'qtype_calculatedmulti', 'correctfeedback', $questionid); $fs->delete_area_files($contextid, 'qtype_calculatedmulti', 'partiallycorrectfeedback', $questionid); $fs->delete_area_files($contextid, 'qtype_calculatedmulti', 'incorrectfeedback', $questionid); }