function definition() { global $SESSION; $mform =& $this->_form; $stringfile = 'qtype_' . $this->question->qtype; $possibledatasets = $this->qtypeobj->find_dataset_names($this->question->questiontext); $mandatorydatasets = array(); if (isset($this->question->options->answers)) { foreach ($this->question->options->answers as $answer) { $mandatorydatasets += $this->qtypeobj->find_dataset_names($answer->answer); } } else { foreach ($SESSION->datasetdependent->questionform->answers as $answer) { $mandatorydatasets += $this->qtypeobj->find_dataset_names($answer); } } $key = 0; $datadefscat = array(); $datadefscat = $this->qtypeobj->get_dataset_definitions_category($this->question); $datasetmenus = array(); $label = "<div class='mdl-align'>" . get_string('datasetrole', 'qtype_datasetdependent', 'numerical') . "</div>"; $mform->addElement('html', $label); // explaining the role of datasets so other strings can be shortened $mform->addElement('header', 'mandatoryhdr', get_string('mandatoryhdr', $stringfile)); $labelsharedwildcard = get_string("sharedwildcard", "qtype_datasetdependent"); foreach ($mandatorydatasets as $datasetname) { if (!isset($datasetmenus[$datasetname])) { list($options, $selected) = $this->qtypeobj->dataset_options($this->question, $datasetname); unset($options['0']); // Mandatory... $label = get_string("wildcard", "quiz") . " <strong>{$datasetname}</strong> "; $mform->addElement('select', "dataset[{$key}]", $label, $options); if (isset($datadefscat[$datasetname])) { $mform->addElement('static', "there is a category", $labelsharedwildcard . " <strong>{$datasetname} </strong>", get_string('dataitemdefined', "qtype_datasetdependent", $datadefscat[$datasetname])); } $mform->setDefault("dataset[{$key}]", $selected); $datasetmenus[$datasetname] = ''; $key++; } } $mform->addElement('header', 'possiblehdr', get_string('possiblehdr', $stringfile)); foreach ($possibledatasets as $datasetname) { if (!isset($datasetmenus[$datasetname])) { list($options, $selected) = $this->qtypeobj->dataset_options($this->question, $datasetname, false); $label = get_string("wildcard", "quiz") . " <strong>{$datasetname}</strong> "; $mform->addElement('select', "dataset[{$key}]", $label, $options); // $mform->addRule("dataset[$key]", null, 'required', null, 'client'); if (isset($datadefscat[$datasetname])) { $mform->addElement('static', "there is a category", $labelsharedwildcard . " <strong>{$datasetname} </strong>", get_string('dataitemdefined', "qtype_datasetdependent", $datadefscat[$datasetname])); } // $selected ="0"; $mform->setDefault("dataset[{$key}]", $selected); $datasetmenus[$datasetname] = ''; $key++; } } $this->add_action_buttons(false, get_string('nextpage', 'qtype_calculated')); //hidden elements $mform->addElement('hidden', 'returnurl'); $mform->setType('returnurl', PARAM_URL); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $mform->setDefault('courseid', 0); $mform->addElement('hidden', 'cmid'); $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); }
protected function definition() { global $SESSION; $mform = $this->_form; $possibledatasets = $this->qtypeobj->find_dataset_names($this->question->questiontext); $mandatorydatasets = array(); if (isset($this->question->options->answers)) { foreach ($this->question->options->answers as $answer) { $mandatorydatasets += $this->qtypeobj->find_dataset_names($answer->answer); } } else { foreach ($SESSION->calculated->questionform->answers as $answer) { $mandatorydatasets += $this->qtypeobj->find_dataset_names($answer); } } $key = 0; $datadefscat= array(); $datadefscat = $this->qtypeobj->get_dataset_definitions_category($this->question); $datasetmenus = array(); $label = "<div class='mdl-align'>".get_string('datasetrole', 'qtype_calculated')."</div>"; // explaining the role of datasets so other strings can be shortened $mform->addElement('html', $label); $mform->addElement('header', 'mandatoryhdr', get_string('mandatoryhdr', 'qtype_calculated')); $labelsharedwildcard = get_string('sharedwildcard', 'qtype_calculated'); foreach ($mandatorydatasets as $datasetname) { if (!isset($datasetmenus[$datasetname])) { list($options, $selected) = $this->qtypeobj->dataset_options($this->question, $datasetname); unset($options['0']); // Mandatory... $label = get_string('wildcard', 'qtype_calculated', $datasetname); $mform->addElement('select', "dataset[$key]", $label, $options); if (isset($datadefscat[$datasetname])) { $mform->addElement('static', "there is a category", get_string('sharedwildcard', 'qtype_calculated', $datasetname), get_string('dataitemdefined', 'qtype_calculated', $datadefscat[$datasetname])); } $mform->setDefault("dataset[$key]", $selected); $datasetmenus[$datasetname] = ''; $key++; } } $mform->addElement('header', 'possiblehdr', get_string('possiblehdr', 'qtype_calculated')); foreach ($possibledatasets as $datasetname) { if (!isset($datasetmenus[$datasetname])) { list($options, $selected) = $this->qtypeobj->dataset_options( $this->question, $datasetname, false); $label = get_string('wildcard', 'qtype_calculated', $datasetname); $mform->addElement('select', "dataset[$key]", $label, $options); if (isset($datadefscat[$datasetname])) { $mform->addElement('static', "there is a category", get_string('sharedwildcard', 'qtype_calculated', $datasetname), get_string('dataitemdefined', 'qtype_calculated', $datadefscat[$datasetname])); } $mform->setDefault("dataset[$key]", $selected); $datasetmenus[$datasetname] = ''; $key++; } } // temporary strings $mform->addElement('header', 'synchronizehdr', get_string('synchronize', 'qtype_calculated')); $mform->addElement('radio', 'synchronize', '', get_string('synchronizeno', 'qtype_calculated'), 0); $mform->addElement('radio', 'synchronize', '', get_string('synchronizeyes', 'qtype_calculated'), 1); $mform->addElement('radio', 'synchronize', '', get_string('synchronizeyesdisplay', 'qtype_calculated'), 2); if (isset($this->question->options) && isset($this->question->options->synchronize)) { $mform->setDefault('synchronize', $this->question->options->synchronize); } else { $mform->setDefault('synchronize', 0); } $this->add_action_buttons(false, get_string('nextpage', 'qtype_calculated')); $this->add_hidden_fields(); $mform->addElement('hidden', 'category'); $mform->setType('category', PARAM_SEQUENCE); $mform->addElement('hidden', 'wizard', 'datasetitems'); $mform->setType('wizard', PARAM_ALPHA); }