]> git.mjollnir.org Git - moodle.git/commitdiff
migrated randomsamatch to formslib.
authorjamiesensei <jamiesensei>
Mon, 8 Jan 2007 13:58:42 +0000 (13:58 +0000)
committerjamiesensei <jamiesensei>
Mon, 8 Jan 2007 13:58:42 +0000 (13:58 +0000)
fixed small typo in quiz mod_form

lang/en_utf8/qtype_randomsamatch.php [new file with mode: 0644]
lib/form/questioncategory.php
mod/quiz/mod_form.php
question/type/randomsamatch/edit_randomsamatch_form.php [new file with mode: 0644]
question/type/randomsamatch/editquestion.html [deleted file]
question/type/randomsamatch/editquestion.php [deleted file]

diff --git a/lang/en_utf8/qtype_randomsamatch.php b/lang/en_utf8/qtype_randomsamatch.php
new file mode 100644 (file)
index 0000000..830f580
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+$string['notenoughsaincategory'] = 'There is/are only $a->nosaquestions short answer questions in the category that you chose \'$a->catname\'. Choose a different category, make some more questions in this category or reduce the amount of questions you\'ve selected.';
+$string['nosaincategory'] = 'There are no short answer questions in the category that you chose \'$a->catname\'. Choose a different category, make some questions in this category.';
+?>
\ No newline at end of file
index fc4b444a1d3a66a23184dbd95ad717d141271943..04a90596dd14d9f55baeaf88fe2caee335904f64 100644 (file)
@@ -28,7 +28,7 @@ class MoodleQuickForm_questioncategory extends MoodleQuickForm_select {
      * @access public
      * @return void
      */
-    function MoodleQuickForm_questioncategory($elementName = null, 
+    function MoodleQuickForm_questioncategory($elementName = null,
             $elementLabel = null, $attributes = null, $options = null) {
         HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes, null);
 
@@ -50,7 +50,7 @@ class MoodleQuickForm_questioncategory extends MoodleQuickForm_select {
             $this->_only_editable = false;
         }
     }
-    
+
     /**
      * Called by HTML_QuickForm whenever form event is made on this element
      *
index 7546d8b293da11e1d93ba03d8e99006532355b53..d0703b3ab178a57d915f149cba3323e95cd44f1b 100644 (file)
@@ -205,7 +205,7 @@ class mod_quiz_mod_form extends moodleform_mod {
 //-------------------------------------------------------------------------------
                $this->standard_coursemodule_elements();
 //-------------------------------------------------------------------------------
-        $mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz').' {no}');
+        $mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz'));
                $mform->setHelpButton('overallfeedbackhdr', array('overallfeedback', get_string('overallfeedback', 'quiz'), 'quiz'));
 
                $mform->addElement('static', 'gradeboundarystatic1', get_string('gradeboundary', 'quiz'), '100%');
diff --git a/question/type/randomsamatch/edit_randomsamatch_form.php b/question/type/randomsamatch/edit_randomsamatch_form.php
new file mode 100644 (file)
index 0000000..98a0255
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Defines the editing form for the randomsamatch question type.
+ *
+ * @copyright &copy; 2007 Jamie Pratt
+ * @author Jamie Pratt me@jamiep.org
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package questions
+ */
+
+/**
+ * randomsamatch editing form definition.
+ */
+class question_edit_randomsamatch_form extends question_edit_form {
+    /**
+     * Add question-type specific form fields.
+     *
+     * @param MoodleQuickForm $mform the form being built.
+     */
+    function definition_inner(&$mform) {
+        $mform->removeElement('image');
+
+        $questionstoselect = array();
+        for ($i=2; $i<=QUESTION_NUMANS; $i++){
+            $questionstoselect[$i] = $i;
+        }
+
+        $mform->addElement('select', 'choose', get_string("randomsamatchnumber", "quiz"), $questionstoselect);
+        $mform->setType('feedback', PARAM_RAW);
+
+        $mform->addElement('hidden', 'fraction', 0);
+    }
+
+    function set_defaults($question) {
+        if (empty($question->name)) {
+            $question->name =  get_string("randomsamatch", "quiz");
+        }
+
+        if (empty($question->questiontext)) {
+            $question->questiontext =  get_string("randomsamatchintro", "quiz");
+        }
+        parent::set_defaults($question);
+    }
+
+    function qtype() {
+        return 'randomsamatch';
+    }
+
+    function validation($data){
+        global $QTYPES;
+        $errors = array();
+        $saquestions = $QTYPES['randomsamatch']->get_sa_candidates($data['category']);
+        $numberavailable = count($saquestions);
+        if ($saquestions === false){
+            $a = new object();
+            $a->catname = get_field('question_categories', 'name', 'id', $data['category']);
+            $errors['choose'] = get_string('nosaincategory', 'qtype_randomsamatch', $a);
+
+        } elseif ($numberavailable < $data['choose']){
+            $a = new object();
+            $a->catname = get_field('question_categories', 'name', 'id', $data['category']);
+            $a->nosaquestions = $numberavailable;
+            $errors['choose'] = get_string('notenoughsaincategory', 'qtype_randomsamatch', $a);
+        }
+        return $errors;
+
+    }
+
+}
+?>
\ No newline at end of file
diff --git a/question/type/randomsamatch/editquestion.html b/question/type/randomsamatch/editquestion.html
deleted file mode 100644 (file)
index d6fa04d..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-$QTYPES[$question->qtype]->print_question_form_start($question, array(), $course, $usehtmleditor,
-        array('image'));
-?>
-<tr valign="top">
-    <td align="right"><b><?php  print_string("randomsamatchnumber", "quiz") ?>:</b></td>
-    <td align="left">
-    <?php
-        if ($numberavailable < 2) {
-            echo get_string('createfirst', 'quiz');
-            $maxrandom=2;
-        } else if ($numberavailable < 6) {
-            $maxrandom = $numberavailable;
-        } else {
-            $maxrandom = QUESTION_NUMANS;
-        }
-        for ($i=2;$i<=$maxrandom;$i++) {
-            $menu[$i] = $i;
-        }
-        choose_from_menu($menu, "choose", "$options->choose", "");
-        unset($menu);
-     ?>
-    </td>
-</tr>
-<?php
-$QTYPES[$question->qtype]->print_replacement_options($question, $course, $contextquiz);
-$QTYPES[$question->qtype]->print_question_form_end($question);
-?>
diff --git a/question/type/randomsamatch/editquestion.php b/question/type/randomsamatch/editquestion.php
deleted file mode 100644 (file)
index dca57b4..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php // $Id$
-    if (!empty($question->id)) {
-        $options = get_record("question_randomsamatch", "question", $question->id);
-    } else {
-        $options->choose = "";
-    }
-    $saquestions = $QTYPES['randomsamatch']->get_sa_candidates($category->id);
-    $numberavailable = count($saquestions);
-    unset($saquestions);
-
-    if (empty($question->name)) {
-        $question->name =  get_string("randomsamatch", "quiz");
-    }
-
-    if (empty($question->questiontext)) {
-        $question->questiontext =  get_string("randomsamatchintro", "quiz");
-    }
-
-    $yesnooptions = array();
-    $yesnooptions[0] = get_string("no");
-    $yesnooptions[1] = get_string("yes");
-
-    print_heading_with_help(get_string("editingrandomsamatch", "quiz"), "randomsamatch", "quiz");
-    require("$CFG->dirroot/question/type/randomsamatch/editquestion.html");
-
-?>