From 3978521f564d0dd4b81b5f2e8ebec786ee28e8aa Mon Sep 17 00:00:00 2001 From: pichetp Date: Sun, 24 May 2009 21:06:34 +0000 Subject: [PATCH] MDL-19214 Adding category hidden element Merging from HEAD --- .../type/datasetdependent/datasetdefinitions_form.php | 11 +++++++++++ question/type/datasetdependent/datasetitems_form.php | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/question/type/datasetdependent/datasetdefinitions_form.php b/question/type/datasetdependent/datasetdefinitions_form.php index abe7a236c7e41..65c41684016b6 100644 --- a/question/type/datasetdependent/datasetdefinitions_form.php +++ b/question/type/datasetdependent/datasetdefinitions_form.php @@ -28,6 +28,13 @@ function question_dataset_dependent_definitions_form($submiturl, $question){ global $QTYPES; $this->question = $question; $this->qtypeobj =& $QTYPES[$this->question->qtype]; + // Validate the question category. + if (!$category = get_record('question_categories', '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() { @@ -107,6 +114,10 @@ function definition() { $mform->setType('cmid', PARAM_INT); $mform->setDefault('cmid', 0); + $mform->addElement('hidden', 'category'); + $mform->setType('category', PARAM_RAW); + $mform->setDefault('category', array('contexts' => array($this->categorycontext))); + $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'wizard', 'datasetitems'); $mform->setType('wizard', PARAM_ALPHA); diff --git a/question/type/datasetdependent/datasetitems_form.php b/question/type/datasetdependent/datasetitems_form.php index 46493da6a2997..4846092805218 100644 --- a/question/type/datasetdependent/datasetitems_form.php +++ b/question/type/datasetdependent/datasetitems_form.php @@ -32,6 +32,12 @@ function question_dataset_dependent_items_form($submiturl, $question, $regenerat $this->regenerate = $regenerate; $this->question = $question; $this->qtypeobj =& $QTYPES[$this->question->qtype]; + // Validate the question category. + if (!$category = get_record('question_categories', '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->datasetdependent->definitionform->dataset); @@ -161,6 +167,10 @@ function definition() { $mform->setType('cmid', PARAM_INT); $mform->setDefault('cmid', 0); + $mform->addElement('hidden', 'category'); + $mform->setType('category', PARAM_RAW); + $mform->setDefault('category', array('contexts' => array($this->categorycontext))); + $mform->addElement('hidden', 'wizard', 'datasetitems'); $mform->setType('wizard', PARAM_ALPHA);