Skip to content

Commit

Permalink
MDL-11708 - Zero answers are not allowed in Matching questions - some…
Browse files Browse the repository at this point in the history
…times I hate PHP.
  • Loading branch information
tjhunt committed Oct 22, 2007
1 parent 32a6bb3 commit dc99997
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions question/type/match/edit_match_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ function validation($data){
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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions question/type/match/questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function save_question_options($question) {
// 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;
Expand All @@ -55,7 +55,7 @@ function save_question_options($question) {
}
$subquestions[] = $subquestion->id;
}
if (!empty($questiontext) && empty($answertext)) {
if ($questiontext != '' && $answertext == '') {
$result->notice = get_string('nomatchinganswer', 'quiz', $questiontext);
}
}
Expand Down Expand Up @@ -219,7 +219,7 @@ function get_correct_responses(&$question, &$state) {
$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;
}
}
Expand Down Expand Up @@ -268,7 +268,7 @@ function print_question_formulation_and_controls(&$question, &$state, $cmoptions

// 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,
Expand Down

0 comments on commit dc99997

Please sign in to comment.