From 315efce701d94c003674f27f0ff26aeead2f6f96 Mon Sep 17 00:00:00 2001 From: pichetp Date: Sun, 24 May 2009 02:33:42 +0000 Subject: [PATCH] MDL-19214 Adding category hidden element --- question/type/calculated/datasetdefinitions_form.php | 12 +++++++++++- question/type/calculated/datasetitems_form.php | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/question/type/calculated/datasetdefinitions_form.php b/question/type/calculated/datasetdefinitions_form.php index 806d2561d5..8960e8a936 100644 --- a/question/type/calculated/datasetdefinitions_form.php +++ b/question/type/calculated/datasetdefinitions_form.php @@ -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); diff --git a/question/type/calculated/datasetitems_form.php b/question/type/calculated/datasetitems_form.php index 84e65c4abc..a23bdde76b 100644 --- a/question/type/calculated/datasetitems_form.php +++ b/question/type/calculated/datasetitems_form.php @@ -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); -- 2.39.5