本文整理汇总了PHP中question_edit_form::validation方法的典型用法代码示例。如果您正苦于以下问题:PHP question_edit_form::validation方法的具体用法?PHP question_edit_form::validation怎么用?PHP question_edit_form::validation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类question_edit_form
的用法示例。
在下文中一共展示了question_edit_form::validation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validation
function validation($data, $files)
{
$errors = parent::validation($data, $files);
$answers = $data['subanswers'];
$questions = $data['subquestions'];
$questioncount = 0;
$answercount = 0;
foreach ($questions as $key => $question) {
$trimmedquestion = trim($question);
$trimmedanswer = trim($answers[$key]);
if ($trimmedquestion != '') {
$questioncount++;
}
if ($trimmedanswer != '' || $trimmedquestion != '') {
$answercount++;
}
if ($trimmedquestion != '' && $trimmedanswer == '') {
$errors['subanswers[' . $key . ']'] = get_string('nomatchinganswerforq', 'qtype_match', $trimmedquestion);
}
}
$numberqanda = new stdClass();
$numberqanda->q = 2;
$numberqanda->a = 3;
if ($questioncount < 1) {
$errors['subquestions[0]'] = get_string('notenoughqsandas', 'qtype_match', $numberqanda);
}
if ($questioncount < 2) {
$errors['subquestions[1]'] = get_string('notenoughqsandas', 'qtype_match', $numberqanda);
}
if ($answercount < 3) {
$errors['subanswers[2]'] = get_string('notenoughqsandas', 'qtype_match', $numberqanda);
}
return $errors;
}
示例2: validation
function validation($data, $files)
{
global $QTYPES;
$errors = parent::validation($data, $files);
// Check the answers.
$answercount = 0;
$maxgrade = false;
$answers = $data['answer'];
foreach ($answers as $key => $answer) {
$trimmedanswer = trim($answer);
if ($trimmedanswer != '') {
$answercount++;
if (!(is_numeric($trimmedanswer) || $trimmedanswer == '*')) {
$errors["answer[{$key}]"] = get_string('answermustbenumberorstar', 'qtype_numerical');
}
if ($data['fraction'][$key] == 1) {
$maxgrade = true;
}
} else {
if ($data['fraction'][$key] != 0 || !html_is_blank($data['feedback'][$key]['text'])) {
$errors["answer[{$key}]"] = get_string('answermustbenumberorstar', 'qtype_numerical');
$answercount++;
}
}
}
if ($answercount == 0) {
$errors['answer[0]'] = get_string('notenoughanswers', 'qtype_numerical');
}
if ($maxgrade == false) {
$errors['fraction[0]'] = get_string('fractionsnomax', 'question');
}
$QTYPES['numerical']->validate_numerical_options($data, $errors);
return $errors;
}
示例3: validation
function validation($data, $files)
{
$errors = parent::validation($data, $files);
$answers = $data['answer'];
$answercount = 0;
$totalfraction = 0;
$maxfraction = -1;
foreach ($answers as $key => $answer) {
//check no of choices
$trimmedanswer = trim($answer);
if (!empty($trimmedanswer)) {
$answercount++;
}
//check grades
if ($answer != '') {
if ($data['fraction'][$key] > 0) {
$totalfraction += $data['fraction'][$key];
}
if ($data['fraction'][$key] > $maxfraction) {
$maxfraction = $data['fraction'][$key];
}
}
}
if ($answercount == 0) {
$errors['answer[0]'] = get_string('notenoughanswers', 'qtype_multichoice', 1);
}
$totalfraction = round($totalfraction, 2);
if ($totalfraction != 1) {
$totalfraction = $totalfraction * 100;
$errors['fraction[0]'] = get_string('errfractionsaddwrong', 'qtype_multichoice', $totalfraction);
}
return $errors;
}
示例4: validation
public function validation($data, $files)
{
$errors = parent::validation($data, $files);
$answers = $data['answer'];
$answercount = 0;
$maxgrade = false;
foreach ($answers as $key => $answer) {
$trimmedanswer = trim($answer);
if ($trimmedanswer !== '') {
$answercount++;
if ($data['fraction'][$key] == 1) {
$maxgrade = true;
}
} else {
if ($data['fraction'][$key] != 0 || !html_is_blank($data['feedback'][$key]['text'])) {
$errors["answer[{$key}]"] = get_string('answermustbegiven', 'qtype_shortanswer');
$answercount++;
}
}
}
if ($answercount == 0) {
$errors['answer[0]'] = get_string('notenoughanswers', 'qtype_shortanswer', 1);
}
if ($maxgrade == false) {
$errors['fraction[0]'] = get_string('fractionsnomax', 'question');
}
return $errors;
}
示例5: validation
function validation($data)
{
$errors = parent::validation($data);
$answers = $data['subanswers'];
$questions = $data['subquestions'];
$questioncount = 0;
foreach ($questions as $key => $question) {
$trimmedquestion = trim($question);
$trimmedanswer = trim($answers[$key]);
if (!empty($trimmedanswer) && !empty($trimmedquestion)) {
$questioncount++;
}
if (!empty($trimmedquestion) && empty($trimmedanswer)) {
$errors['subanswers[' . $key . ']'] = get_string('nomatchinganswerforq', 'qtype_match', $trimmedquestion);
}
}
if ($questioncount == 0) {
$errors['subquestions[0]'] = get_string('notenoughquestions', 'qtype_match', 3);
$errors['subquestions[1]'] = get_string('notenoughquestions', 'qtype_match', 3);
$errors['subquestions[2]'] = get_string('notenoughquestions', 'qtype_match', 3);
} elseif ($questioncount == 1) {
$errors['subquestions[1]'] = get_string('notenoughquestions', 'qtype_match', 3);
$errors['subquestions[2]'] = get_string('notenoughquestions', 'qtype_match', 3);
} elseif ($questioncount == 2) {
$errors['subquestions[2]'] = get_string('notenoughquestions', 'qtype_match', 3);
}
return $errors;
}
示例6: validation
public function validation($data, $files)
{
global $DB;
$errors = parent::validation($data, $files);
if (isset($data->categorymoveto)) {
list($category) = explode(',', $data['categorymoveto']);
} else {
list($category) = explode(',', $data['category']);
}
$saquestions = question_bank::get_qtype('randomsamatch')->get_sa_candidates($category);
$numberavailable = count($saquestions);
if ($saquestions === false) {
$a = new stdClass();
$a->catname = $DB->get_field('question_categories', 'name', array('id' => $category));
$errors['choose'] = get_string('nosaincategory', 'qtype_randomsamatch', $a);
} else {
if ($numberavailable < $data['choose']) {
$a = new stdClass();
$a->catname = $DB->get_field('question_categories', 'name', array('id' => $category));
$a->nosaquestions = $numberavailable;
$errors['choose'] = get_string('notenoughsaincategory', 'qtype_randomsamatch', $a);
}
}
return $errors;
}
示例7: validation
public function validation($data, $files)
{
$errors = parent::validation($data, $files);
$answers = $data['answer'];
$answercount = 0;
$totalfraction = 0;
$maxfraction = -1;
foreach ($answers as $key => $answer) {
//check no of choices
$trimmedanswer = trim($answer['text']);
$fraction = (double) $data['fraction'][$key];
if ($trimmedanswer === '' && empty($fraction)) {
continue;
}
if ($trimmedanswer === '') {
$errors['fraction[' . $key . ']'] = get_string('errgradesetanswerblank', 'qtype_turmultiplechoice');
}
$answercount++;
//check grades
if ($data['fraction'][$key] > 0) {
$totalfraction += $data['fraction'][$key];
}
if ($data['fraction'][$key] > $maxfraction) {
$maxfraction = $data['fraction'][$key];
}
}
if ($answercount == 0) {
$errors['answer[0]'] = get_string('notenoughanswers', 'qtype_turmultiplechoice', 2);
$errors['answer[1]'] = get_string('notenoughanswers', 'qtype_turmultiplechoice', 2);
} else {
if ($answercount == 1) {
$errors['answer[1]'] = get_string('notenoughanswers', 'qtype_turmultiplechoice', 2);
}
}
/// Perform sanity checks on fractional grades
if ($data['single']) {
if ($maxfraction != 1) {
$errors['fraction[0]'] = get_string('errfractionsnomax', 'qtype_turmultiplechoice', $maxfraction * 100);
}
} else {
$totalfraction = round($totalfraction, 2);
if ($totalfraction != 1) {
$errors['fraction[0]'] = get_string('errfractionsaddwrong', 'qtype_turmultiplechoice', $totalfraction * 100);
}
}
return $errors;
}
示例8: validation
public function validation($data, $files)
{
$errors = parent::validation($data, $files);
// cleanup :
$data['conditions'] = rtrim(str_replace("\r\n", "\n", $data['conditions']), "\n");
$data['feedbackperconditions'] = rtrim(str_replace("\r\n", "\n", $data['feedbackperconditions']), "\n");
$conditions = explode("\n", $data['conditions']);
$feedbackperconditions = explode("\n", $data['feedbackperconditions']);
if (count($feedbackperconditions) > count($conditions)) {
$errors['conditions'] = get_string('badnumfeedbackperconditions', 'qtype_multinumerical');
$errors['feedbackperconditions'] = get_string('badnumfeedbackperconditions', 'qtype_multinumerical');
}
foreach ($feedbackperconditions as $feedbackpercondition) {
if (trim($feedbackpercondition) && strpos($feedbackpercondition, '|') === false) {
$errors['feedbackperconditions'] = get_string('badfeedbackperconditionsyntax', 'qtype_multinumerical');
}
}
return $errors;
}
示例9: validation
public function validation($fromform, $files)
{
$errors = parent::validation($fromform, $files);
// Don't allow both 'no inline response' and 'no attachments' to be selected,
// as these options would result in there being no input requested from the user.
if ($fromform['responseformat'] == 'noinline' && !$fromform['attachments']) {
$errors['attachments'] = get_string('mustattach', 'qtype_essay');
}
// If 'no inline response' is set, force the teacher to require attachments;
// otherwise there will be nothing to grade.
if ($fromform['responseformat'] == 'noinline' && !$fromform['attachmentsrequired']) {
$errors['attachmentsrequired'] = get_string('mustrequire', 'qtype_essay');
}
// Don't allow the teacher to require more attachments than they allow; as this would
// create a condition that it's impossible for the student to meet.
if ($fromform['attachments'] != -1 && $fromform['attachments'] < $fromform['attachmentsrequired']) {
$errors['attachmentsrequired'] = get_string('mustrequirefewer', 'qtype_essay');
}
return $errors;
}
示例10: validation
function validation($data)
{
$errors = parent::validation($data);
$answers = $data['answer'];
$answercount = 0;
$maxgrade = false;
foreach ($answers as $key => $answer) {
$trimmedanswer = trim($answer);
if ($trimmedanswer !== '') {
$answercount++;
if ($data['fraction'][$key] == 1) {
$maxgrade = true;
}
}
}
if ($answercount == 0) {
$errors['answer[0]'] = get_string('notenoughanswers', 'quiz', 1);
}
if ($maxgrade == false) {
$errors['fraction[0]'] = get_string('fractionsnomax', 'question');
}
return $errors;
}
示例11: validation
function validation($data)
{
$errors = parent::validation($data, null);
$colcount = matrix_qtype::count_form_rows_or_cols($data, false);
$rowcount = matrix_qtype::count_form_rows_or_cols($data);
if ($rowcount == 0) {
$errors['rowshort[0]'] = get_string('mustdefine1by1', 'qtype_matrix');
}
if ($colcount == 0) {
$errors['colshort[0]'] = get_string('mustdefine1by1', 'qtype_matrix');
}
if (array_key_exists('grademethod', $data)) {
$grademethod = $data['grademethod'];
} else {
$grademethod = matrix_qtype::single_default_grademethod();
}
if ($grademethod == QTYPE_MATRIX_GRADING_WEIGHTED && empty($data['multiple'])) {
$errors['multiple'] = get_string('weightednomultiple', 'qtype_matrix');
}
$gradeclass = matrix_qtype::grade_class($grademethod, $data['multiple']);
$matrixerrors = $gradeclass->validate_defining_form_matrix($data);
$errors = array_merge($errors, $matrixerrors);
return $errors ? $errors : true;
}
示例12: validation
public function validation($fromform, $files)
{
$errors = parent::validation($fromform, $files);
$inputs = $this->get_input_names_from_question_text();
$prts = $this->get_prt_names_from_question();
$fixingdollars = array_key_exists('fixdollars', $fromform);
$this->options = new stack_options();
$this->options->set_option('multiplicationsign', $fromform['multiplicationsign']);
$this->options->set_option('complexno', $fromform['complexno']);
$this->options->set_option('inversetrig', $fromform['inversetrig']);
$this->options->set_option('matrixparens', $fromform['matrixparens']);
$this->options->set_option('sqrtsign', (bool) $fromform['sqrtsign']);
$this->options->set_option('simplify', (bool) $fromform['questionsimplify']);
$this->options->set_option('assumepos', (bool) $fromform['assumepositive']);
// We slightly break the usual conventions of validation, in that rather
// than building up $errors as an array of strings, we initially build it
// up as an array of arrays, then at the end remove any empty arrays,
// and implod (' ', ...) any arrays that are non-empty. This makes our
// rather complex validation easier to implement.
// 1) Validate all the fixed question fields.
// Question variables.
$errors = $this->validate_cas_keyval($errors, $fromform['questionvariables'], 'questionvariables');
// Question text.
$errors['questiontext'] = array();
$errors = $this->validate_cas_text($errors, $fromform['questiontext']['text'], 'questiontext', $fixingdollars);
// Check for whitespace following placeholders.
$sloppytags = $this->get_sloppy_tags($fromform['questiontext']['text']);
foreach ($sloppytags as $sloppytag) {
$errors['questiontext'][] = stack_string('questiontextplaceholderswhitespace', $sloppytag);
}
foreach ($inputs as $inputname => $counts) {
list($numinputs, $numvalidations) = $counts;
if ($numinputs == 0 && $numvalidations == 0) {
if (!$fromform[$inputname . 'deleteconfirm']) {
$errors['questiontext'][] = stack_string('inputremovedconfirmbelow', $inputname);
}
continue;
}
if ($numinputs == 0) {
$errors['questiontext'][] = stack_string('questiontextmustcontain', '[[input:' . $inputname . ']]');
} else {
if ($numinputs > 1) {
$errors['questiontext'][] = stack_string('questiontextonlycontain', '[[input:' . $inputname . ']]');
}
}
if ($numvalidations == 0) {
$errors['questiontext'][] = stack_string('questiontextmustcontain', '[[validation:' . $inputname . ']]');
} else {
if ($numvalidations > 1) {
$errors['questiontext'][] = stack_string('questiontextonlycontain', '[[validation:' . $inputname . ']]');
}
}
}
if (empty($inputs) && !empty($prts)) {
$errors['questiontext'][] = stack_string('noprtsifnoinputs');
}
// Default mark.
if (empty($inputs) && $fromform['defaultmark'] != 0) {
$errors['defaultmark'][] = stack_string('defaultmarkzeroifnoprts');
}
// Penalty.
$penalty = $fromform['penalty'];
if (!is_numeric($penalty) || $penalty < 0 || $penalty > 1) {
$errors['penalty'][] = stack_string('penaltyerror');
}
// Specific feedback.
$errors['specificfeedback'] = array();
$errors = $this->validate_cas_text($errors, $fromform['specificfeedback']['text'], 'specificfeedback', $fixingdollars);
$errors['specificfeedback'] += $this->check_no_placeholders(stack_string('specificfeedback'), $fromform['specificfeedback']['text'], array('input', 'validation'));
// General feedback.
$errors['generalfeedback'] = array();
$errors = $this->validate_cas_text($errors, $fromform['generalfeedback']['text'], 'generalfeedback', $fixingdollars);
$errors['generalfeedback'] += $this->check_no_placeholders(get_string('generalfeedback', 'question'), $fromform['generalfeedback']['text']);
// Question note.
$errors['questionnote'] = array();
if ('' == $fromform['questionnote']) {
if (!(false === strpos($fromform['questionvariables'], 'rand'))) {
$errors['questionnote'][] = stack_string('questionnotempty');
}
} else {
// Note, the 'questionnote' does not have an editor field and hence no 'text' sub-clause.
$errors = $this->validate_cas_text($errors, $fromform['questionnote'], 'questionnote', $fixingdollars);
}
$errors['questionnote'] += $this->check_no_placeholders(stack_string('questionnote'), $fromform['questionnote']);
// 2) Validate all inputs.
foreach ($inputs as $inputname => $counts) {
list($numinputs, $numvalidations) = $counts;
if ($numinputs == 0 && $numvalidations == 0 && !$fromform[$inputname . 'deleteconfirm']) {
$errors[$inputname . 'deleteconfirm'][] = stack_string('youmustconfirm');
}
if (strlen($inputname) > 18 && !isset($fromform[$inputname . 'deleteconfirm'])) {
$errors['questiontext'][] = stack_string('inputnamelength', $inputname);
}
if (array_key_exists($inputname . 'modelans', $fromform)) {
$errors = $this->validate_cas_string($errors, $fromform[$inputname . 'modelans'], $inputname . 'modelans', $inputname . 'modelans');
// TODO: find out if this input type acutally requires options, rather than
// the hard-coded check here.
if (false) {
$errors = $this->validate_cas_string($errors, $fromform[$inputname . 'options'], $inputname . 'options', $inputname . 'options', false);
} else {
//.........这里部分代码省略.........
示例13: validation
function validation($data, $files)
{
$errors = parent::validation($data, $files);
if ($this->col_count($data) == 0) {
$errors['colshort[0]'] = qtype_matrix::get_string('mustdefine1by1');
}
if ($this->row_count($data) == 0) {
$errors['rowshort[0]'] = qtype_matrix::get_string('mustdefine1by1');
}
$grading = qtype_matrix::grading($data['grademethod']);
$grading_errors = $grading->validation($data);
$errors = array_merge($errors, $grading_errors);
return $errors ? $errors : true;
}
示例14: validation
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']);
$errors = $this->validate_text($errors, 'correctfeedback', $data['correctfeedback']['text']);
$errors = $this->validate_text($errors, 'partiallycorrectfeedback', $data['partiallycorrectfeedback']['text']);
$errors = $this->validate_text($errors, 'incorrectfeedback', $data['incorrectfeedback']['text']);
$answers = $data['answer'];
$answercount = 0;
$maxgrade = false;
$possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']['text']);
$mandatorydatasets = array();
foreach ($answers as $key => $answer) {
$mandatorydatasets += $this->qtypeobj->find_dataset_names($answer);
}
if (count($mandatorydatasets) == 0) {
foreach ($answers as $key => $answer) {
$errors['answeroptions[' . $key . ']'] = get_string('atleastonewildcard', 'qtype_calculated');
}
}
$totalfraction = 0;
$maxfraction = -1;
foreach ($answers as $key => $answer) {
$trimmedanswer = trim($answer);
$fraction = (double) $data['fraction'][$key];
if (empty($trimmedanswer) && $trimmedanswer != '0' && empty($fraction)) {
continue;
}
if (empty($trimmedanswer)) {
$errors['answeroptions[' . $key . ']'] = get_string('errgradesetanswerblank', 'qtype_multichoice');
}
if ($trimmedanswer != '' || $answercount == 0) {
// Verifying for errors in {=...} in answer text.
$errors = $this->validate_text($errors, 'answeroptions[' . $key . ']', $answer);
$errors = $this->validate_text($errors, 'feedback[' . $key . ']', $data['feedback'][$key]['text']);
}
if ($trimmedanswer != '') {
if ('2' == $data['correctanswerformat'][$key] && '0' == $data['correctanswerlength'][$key]) {
$errors['correctanswerlength[' . $key . ']'] = get_string('zerosignificantfiguresnotallowed', 'qtype_calculated');
}
if (!is_numeric($data['tolerance'][$key])) {
$errors['tolerance[' . $key . ']'] = get_string('xmustbenumeric', 'qtype_numerical', get_string('acceptederror', 'qtype_numerical'));
}
if ($data['fraction'][$key] > 0) {
$totalfraction += $data['fraction'][$key];
}
if ($data['fraction'][$key] > $maxfraction) {
$maxfraction = $data['fraction'][$key];
}
$answercount++;
}
}
if ($answercount == 0) {
$errors['answeroptions[0]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
$errors['answeroptions[1]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
} else {
if ($answercount == 1) {
$errors['answeroptions[1]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
}
}
// Perform sanity checks on fractional grades.
if ($data['single'] == 1) {
if ($maxfraction != 1) {
$errors['answeroptions[0]'] = get_string('errfractionsnomax', 'qtype_multichoice', $maxfraction * 100);
}
} else {
$totalfraction = round($totalfraction, 2);
if ($totalfraction != 1) {
$totalfraction = $totalfraction * 100;
$errors['answeroptions[0]'] = get_string('errfractionsaddwrong', 'qtype_multichoice', $totalfraction);
}
}
return $errors;
}
示例15: validation
function validation($data, $files)
{
// echo code left for testing period
// echo "<p>question <pre>";print_r($this->question);echo "</pre></p>";
// echo "<p>data <pre>";print_r($data);echo "</pre></p>";
$errors = parent::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);
}
// echo "numericalquestion qtextremaining <pre>";print_r($possibledatasets);
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];
}
}
}
$answers = $data['answer'];
$answercount = 0;
$maxgrade = false;
$possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']['text']);
$mandatorydatasets = array();
foreach ($answers as $key => $answer) {
$mandatorydatasets += $this->qtypeobj->find_dataset_names($answer);
}
if (count($mandatorydatasets) == 0) {
// $errors['questiontext']=get_string('atleastonewildcard', 'qtype_datasetdependent');
foreach ($answers as $key => $answer) {
$errors['answer[' . $key . ']'] = get_string('atleastonewildcard', 'qtype_datasetdependent');
}
}
if ($data['multichoice'] == 1) {
foreach ($answers as $key => $answer) {
$trimmedanswer = trim($answer);
if ($trimmedanswer != '' || $answercount == 0) {
//verifying for errors in {=...} in answer text;
$qanswer = "";
$qanswerremaining = $trimmedanswer;
$possibledatasets = $this->qtypeobj->find_dataset_names($trimmedanswer);
foreach ($possibledatasets as $name => $value) {
$qanswerremaining = str_replace('{' . $name . '}', '1', $qanswerremaining);
}
// echo "numericalquestion qanswerremaining <pre>";print_r($possibledatasets);
while (preg_match('~\\{=([^[:space:]}]*)}~', $qanswerremaining, $regs1)) {
$qanswersplits = explode($regs1[0], $qanswerremaining, 2);
$qanswer = $qanswer . $qanswersplits[0];
$qanswerremaining = $qanswersplits[1];
if (!empty($regs1[1]) && ($formulaerrors = qtype_calculated_find_formula_errors($regs1[1]))) {
if (!isset($errors['answer[' . $key . ']'])) {
$errors['answer[' . $key . ']'] = $formulaerrors . ':' . $regs1[1];
} else {
$errors['answer[' . $key . ']'] .= '<br/>' . $formulaerrors . ':' . $regs1[1];
}
}
}
}
if ($trimmedanswer != '') {
if ('2' == $data['correctanswerformat'][$key] && '0' == $data['correctanswerlength'][$key]) {
$errors['correctanswerlength[' . $key . ']'] = get_string('zerosignificantfiguresnotallowed', 'quiz');
}
if (!is_numeric($data['tolerance'][$key])) {
$errors['tolerance[' . $key . ']'] = get_string('mustbenumeric', 'qtype_calculated');
}
if ($data['fraction'][$key] == 1) {
$maxgrade = true;
}
$answercount++;
}
//check grades
$totalfraction = 0;
$maxfraction = 0;
if ($answer != '') {
if ($data['fraction'][$key] > 0) {
$totalfraction += $data['fraction'][$key];
}
if ($data['fraction'][$key] > $maxfraction) {
$maxfraction = $data['fraction'][$key];
}
}
}
if ($answercount == 0) {
$errors['answer[0]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
$errors['answer[1]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
} elseif ($answercount == 1) {
$errors['answer[1]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
}
/// Perform sanity checks on fractional grades
if ($data['single']) {
if ($maxfraction > 0.999) {
$maxfraction = $maxfraction * 100;
$errors['fraction[0]'] = get_string('errfractionsnomax', 'qtype_multichoice', $maxfraction);
//.........这里部分代码省略.........