]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19214 Adding category hidden element
authorpichetp <pichetp>
Sun, 24 May 2009 02:33:42 +0000 (02:33 +0000)
committerpichetp <pichetp>
Sun, 24 May 2009 02:33:42 +0000 (02:33 +0000)
question/type/calculated/datasetdefinitions_form.php
question/type/calculated/datasetitems_form.php

index 806d2561d5d9ed2fc5e238315a00e2280053299a..8960e8a936b1e7fedfcb01923c28e3eeb7e07e07 100644 (file)
@@ -25,9 +25,15 @@ class question_dataset_dependent_definitions_form extends moodleform {
      * @param MoodleQuickForm $mform the form being built.
      */
     function question_dataset_dependent_definitions_form($submiturl, $question){
-        global $QTYPES;
+        global $QTYPES, $DB;
         $this->question = $question;
         $this->qtypeobj =& $QTYPES[$this->question->qtype];
+                               // Validate the question category.
+                               if (!$category = $DB->get_record('question_categories', array('id' => $question->category))) {
+                                   print_error('categorydoesnotexist', 'question', $returnurl);
+                               }
+        $this->category = $category;
+        $this->categorycontext = get_context_instance_by_id($category->contextid);
         parent::moodleform($submiturl);
     }
     function definition() {
@@ -99,6 +105,10 @@ class question_dataset_dependent_definitions_form extends moodleform {
         $mform->addElement('hidden', 'id');
         $mform->setType('id', PARAM_INT);
 
+        $mform->addElement('hidden', 'category');
+        $mform->setType('category', PARAM_RAW);
+        $mform->setDefault('category', array('contexts' => array($this->categorycontext)));
+                  
         $mform->addElement('hidden', 'courseid');
         $mform->setType('courseid', PARAM_INT);
         $mform->setDefault('courseid', 0);
index 84e65c4abc5ab8c814fa3565fc68840370fae9e7..a23bdde76b9cf2ca26fe41c08917fabfbc6fa187 100644 (file)
@@ -36,6 +36,12 @@ class question_dataset_dependent_items_form extends moodleform {
         $this->regenerate = $regenerate;
         $this->question = $question;
         $this->qtypeobj =& $QTYPES[$this->question->qtype];
+                               // Validate the question category.
+                               if (!$category = $DB->get_record('question_categories', array('id' => $question->category))) {
+                                   print_error('categorydoesnotexist', 'question', $returnurl);
+                               }
+        $this->category = $category;
+        $this->categorycontext = get_context_instance_by_id($category->contextid);
         //get the dataset defintions for this question
         if (empty($question->id)) {
             $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->calculated->definitionform->dataset);
@@ -195,6 +201,10 @@ class question_dataset_dependent_items_form extends moodleform {
         $mform->setType('courseid', PARAM_INT);
         $mform->setDefault('courseid', 0);
 
+        $mform->addElement('hidden', 'category');
+        $mform->setType('category', PARAM_RAW);
+        $mform->setDefault('category', array('contexts' => array($this->categorycontext)));
+              
         $mform->addElement('hidden', 'cmid');
         $mform->setType('cmid', PARAM_INT);
         $mform->setDefault('cmid', 0);