]> git.mjollnir.org Git - moodle.git/commitdiff
qtype match: MDL-16450 Change validation so it is possible to create matching questio...
authortjhunt <tjhunt>
Mon, 27 Oct 2008 02:33:34 +0000 (02:33 +0000)
committertjhunt <tjhunt>
Mon, 27 Oct 2008 02:33:34 +0000 (02:33 +0000)
Thanks to Oleg Sychev for implementing this.

lang/en_utf8/qtype_match.php
question/type/match/edit_match_form.php

index 203cb0fa54cbcb901e5302113f5b7232f4ebeb55..293cf290b5db2982fab31d97f7a08ae92733d410 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 $string['addmoreqblanks'] = '{no} More Sets of Blanks';
-$string['notenoughquestions'] = 'You must supply at least $a question and answer pairs.';
+$string['filloutthreeqsandtwoas'] = 'You must provide at least two questions and three answers. You can provide extra wrong answers by giving an answer with a blank question. Entries where both the question and the answer are blank will be ignored.';
 $string['nomatchinganswerforq'] = 'You must specify an answer for this question.';
+$string['notenoughquestions'] = 'You must supply at least $a question and answer pairs.';
+$string['notenoughqsandas'] = 'You must supply at least $a->q questions and $a->a answers.';
 ?>
\ No newline at end of file
index 4a550d551d4fabe843490ea337cd3b8906209dc5..629bd63234783ca86f2b01fe6a17d3e8554ffad5 100644 (file)
@@ -23,7 +23,7 @@ class question_edit_match_form extends question_edit_form {
         $mform->setHelpButton('shuffleanswers', array('matchshuffle', get_string('shuffle','quiz'), 'quiz'));
         $mform->setDefault('shuffleanswers', 1);
 
-        $mform->addElement('static', 'answersinstruct', get_string('choices', 'quiz'), get_string('filloutthreequestions', 'quiz'));
+        $mform->addElement('static', 'answersinstruct', get_string('choices', 'quiz'), get_string('filloutthreeqsandtwoas', 'qtype_match'));
         $mform->closeHeaderBefore('answersinstruct');
 
         $repeated = array();
@@ -75,26 +75,31 @@ class question_edit_match_form extends question_edit_form {
         $answers = $data['subanswers'];
         $questions = $data['subquestions'];
         $questioncount = 0;
+        $answercount = 0;
         foreach ($questions as $key => $question){
             $trimmedquestion = trim($question);
             $trimmedanswer = trim($answers[$key]);
-            if ($trimmedanswer != '' && $trimmedquestion != ''){
+            if ($trimmedquestion != ''){
                 $questioncount++;
             }
+            if ($trimmedanswer != '' || $trimmedquestion != ''){
+                $answercount++;
+            }
             if ($trimmedquestion != '' && $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);
+        $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;
     }