From: tjhunt Date: Mon, 22 Oct 2007 16:57:19 +0000 (+0000) Subject: MDL-11708 - Zero answers are not allowed in Matching questions - sometimes I hate... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ebf83e2c6f30294590eb378b78f133e23c68bf80;p=moodle.git MDL-11708 - Zero answers are not allowed in Matching questions - sometimes I hate PHP. Merged from MOODLE_18_STABLE. --- diff --git a/question/type/match/edit_match_form.php b/question/type/match/edit_match_form.php index c05302993b..e60e10cafd 100644 --- a/question/type/match/edit_match_form.php +++ b/question/type/match/edit_match_form.php @@ -78,10 +78,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 f4d9996dee..8e90af878f 100644 --- a/question/type/match/questiontype.php +++ b/question/type/match/questiontype.php @@ -34,7 +34,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; @@ -59,7 +59,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); } } @@ -223,7 +223,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; } } @@ -272,7 +272,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,