From dc99997eac63b9976f0b9f008a8537ca2e2f7ab0 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Mon, 22 Oct 2007 16:56:24 +0000 Subject: [PATCH] MDL-11708 - Zero answers are not allowed in Matching questions - sometimes I hate PHP. --- question/type/match/edit_match_form.php | 4 ++-- question/type/match/questiontype.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/question/type/match/edit_match_form.php b/question/type/match/edit_match_form.php index 9e72f5dd54b..747087ae285 100644 --- a/question/type/match/edit_match_form.php +++ b/question/type/match/edit_match_form.php @@ -73,10 +73,10 @@ class question_edit_match_form extends question_edit_form { foreach ($questions as $key => $question){ $trimmedquestion = trim($question); $trimmedanswer = trim($answers[$key]); - if (!empty($trimmedanswer) && !empty($trimmedquestion)){ + if ($trimmedanswer != '' && $trimmedquestion != ''){ $questioncount++; } - if (!empty($trimmedquestion) && empty($trimmedanswer)){ + if ($trimmedquestion != '' && $trimmedanswer == ''){ $errors['subanswers['.$key.']'] = get_string('nomatchinganswerforq', 'qtype_match', $trimmedquestion); } } diff --git a/question/type/match/questiontype.php b/question/type/match/questiontype.php index 4b7820123cf..cd8b85617d4 100644 --- a/question/type/match/questiontype.php +++ b/question/type/match/questiontype.php @@ -30,7 +30,7 @@ class question_match_qtype extends default_questiontype { // Insert all the new question+answer pairs foreach ($question->subquestions as $key => $questiontext) { $answertext = $question->subanswers[$key]; - if (!empty($questiontext) or !empty($answertext)) { + if ($questiontext != '' || $answertext != '') { if ($subquestion = array_shift($oldsubquestions)) { // Existing answer, so reuse it $subquestion->questiontext = $questiontext; $subquestion->answertext = $answertext; @@ -55,7 +55,7 @@ class question_match_qtype extends default_questiontype { } $subquestions[] = $subquestion->id; } - if (!empty($questiontext) && empty($answertext)) { + if ($questiontext != '' && $answertext == '') { $result->notice = get_string('nomatchinganswer', 'quiz', $questiontext); } } @@ -219,7 +219,7 @@ class question_match_qtype extends default_questiontype { $responses = array(); foreach ($state->options->subquestions as $sub) { foreach ($sub->options->answers as $answer) { - if (1 == $answer->fraction && $sub->questiontext) { + if (1 == $answer->fraction && $sub->questiontext != '') { $responses[$sub->id] = $answer->id; } } @@ -268,7 +268,7 @@ class question_match_qtype extends default_questiontype { // Print the input controls foreach ($subquestions as $key => $subquestion) { - if ($subquestion->questiontext) { + if ($subquestion->questiontext != '') { // Subquestion text: $a = new stdClass; $a->text = $this->format_text($subquestion->questiontext,