Fixed MDL-10855 'Calculated question error: undefined stdClass::$nextpageparam' and some other calculated question bugs.
This commit is contained in:
+14
-11
@@ -25,6 +25,8 @@ $movecontext = optional_param('movecontext', 0, PARAM_BOOL);//switch to make qu
|
||||
//uneditable - form is displayed to edit category only
|
||||
$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
|
||||
|
||||
$inpopup = optional_param('inpopup', 0, PARAM_BOOL);
|
||||
|
||||
if ($movecontext && !$id){
|
||||
print_error('questiondoesnotexist', 'question', $returnurl);
|
||||
}
|
||||
@@ -174,26 +176,27 @@ if ($mform->is_cancelled()){
|
||||
}
|
||||
|
||||
$question = $QTYPES[$question->qtype]->save_question($question, $fromform, $COURSE, $wizardnow);
|
||||
if ($QTYPES[$qtype]->finished_edit_wizard($fromform) || $movecontext){
|
||||
|
||||
if (optional_param('inpopup', 0, PARAM_BOOL)) {
|
||||
if (($QTYPES[$question->qtype]->finished_edit_wizard($fromform)) || $movecontext){
|
||||
if ($inpopup) {
|
||||
notify(get_string('changessaved'), '');
|
||||
close_window(3);
|
||||
} else {
|
||||
redirect($returnurl);
|
||||
}
|
||||
} else {
|
||||
$nexturlparams = array('returnurl'=>$returnurl)
|
||||
+ $fromform->nextpageparam;//useful for passing data to the next page which is not saved in the database
|
||||
if ($question->id) {
|
||||
$nexturlparams['id'] = $question->id;
|
||||
} else { // only for creating new questions
|
||||
$nexturlparams['category'] = $question->category;
|
||||
$nexturlparams['qtype'] =$question->qtype;
|
||||
$nexturlparams = array('returnurl'=>$returnurl);
|
||||
if (isset($fromform->nextpageparam) && is_array($fromform->nextpageparam)){
|
||||
$nexturlparams += $fromform->nextpageparam;//useful for passing data to the next page which is not saved in the database
|
||||
}
|
||||
$nexturlparams['id'] = $question->id;
|
||||
$nexturlparams['wizardnow'] = $fromform->wizard;
|
||||
$nexturl = new moodle_url('question.php', $nexturlparams);
|
||||
redirect($nexturl);
|
||||
if ($cmid){
|
||||
$nexturl->param('cmid', $cmid);
|
||||
} else {
|
||||
$nexturl->param('courseid', $COURSE->id);
|
||||
}
|
||||
redirect($nexturl->out());
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
@@ -96,11 +96,12 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
}
|
||||
$this->repeat_elements($repeated, $repeatsatstart, array(), 'nounits', 'addunits', 2, get_string('addmoreunitblanks', 'qtype_calculated', '{no}'));
|
||||
|
||||
$firstunit =& $mform->getElement('multiplier[0]');
|
||||
$firstunit->freeze();
|
||||
$firstunit->setValue('1.0');
|
||||
$firstunit->setPersistantFreeze(true);
|
||||
|
||||
if ($mform->elementExists('multiplier[0]')){
|
||||
$firstunit =& $mform->getElement('multiplier[0]');
|
||||
$firstunit->freeze();
|
||||
$firstunit->setValue('1.0');
|
||||
$firstunit->setPersistantFreeze(true);
|
||||
}
|
||||
//hidden elements
|
||||
$mform->addElement('hidden', 'wizard', 'datasetdefinitions');
|
||||
$mform->setType('wizard', PARAM_ALPHA);
|
||||
@@ -149,15 +150,19 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
$qu = new stdClass;
|
||||
$el = new stdClass;
|
||||
/* no need to call elementExists() here */
|
||||
$el=$this->_form->getElement('category');
|
||||
if ($this->_form->elementExists('category')){
|
||||
$el=$this->_form->getElement('category');
|
||||
} else {
|
||||
$el=$this->_form->getElement('categorymoveto');
|
||||
}
|
||||
if($value =$el->getSelected()) {
|
||||
$qu->category =$value[0];
|
||||
}else {
|
||||
$qu->category=$question->category;// on load $question->category is set by question.php
|
||||
}
|
||||
$html2 = $this->qtypeobj->print_dataset_definitions_category($qu);
|
||||
$this->_form->_elements[$this->_form->_elementIndex['listcategory']]->_text = $html2 ;
|
||||
$question = (object)((array)$question + $default_values);
|
||||
$this->_form->_elements[$this->_form->_elementIndex['listcategory']]->_text = $html2 ;
|
||||
$question = (object)((array)$question + $default_values);
|
||||
|
||||
parent::set_data($question);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class question_dataset_dependent_definitions_form extends moodleform {
|
||||
$datadefscat = $this->qtypeobj->get_dataset_definitions_category($this->question);
|
||||
$datasetmenus = array();
|
||||
$label = "<div align=\"center\">".get_string('datasetrole', 'qtype_datasetdependent','numerical')."</div>";
|
||||
$mform->addElement('html', $label);// explaining the role of datasets so other strings can be shortened
|
||||
$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");
|
||||
|
||||
@@ -71,7 +71,7 @@ class question_dataset_dependent_definitions_form extends moodleform {
|
||||
}
|
||||
}
|
||||
$mform->addElement('header', 'possiblehdr', get_string('possiblehdr', $stringfile));
|
||||
|
||||
|
||||
|
||||
foreach ($possibledatasets as $datasetname) {
|
||||
if (!isset($datasetmenus[$datasetname])) {
|
||||
@@ -83,8 +83,8 @@ class question_dataset_dependent_definitions_form extends moodleform {
|
||||
if (isset($datadefscat[$datasetname])){
|
||||
$mform->addElement('static', "there is a category", $labelsharedwildcard." <strong>$datasetname </strong>", get_string('dataitemdefined',"qtype_datasetdependent", $datadefscat[$datasetname]));
|
||||
}
|
||||
|
||||
// $selected ="0";
|
||||
|
||||
// $selected ="0";
|
||||
$mform->setDefault("dataset[$key]", $selected);
|
||||
$datasetmenus[$datasetname]='';
|
||||
$key++;
|
||||
@@ -96,20 +96,17 @@ class question_dataset_dependent_definitions_form extends moodleform {
|
||||
//hidden elements
|
||||
$mform->addElement('hidden', 'returnurl');
|
||||
$mform->setType('returnurl', PARAM_URL);
|
||||
$mform->addElement('hidden', 'qtype');
|
||||
$mform->setType('qtype', PARAM_ALPHA);
|
||||
$mform->addElement('hidden', 'category');
|
||||
$mform->setType('category', PARAM_INT);
|
||||
$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->setType('id', PARAM_INT);
|
||||
$mform->addElement('hidden', 'wizard', 'datasetitems');
|
||||
$mform->setType('wizard', PARAM_ALPHA);
|
||||
|
||||
@@ -87,7 +87,7 @@ class question_dataset_dependent_items_form extends moodleform {
|
||||
}
|
||||
$addremoveoptions = Array();
|
||||
$addremoveoptions['1']='1';
|
||||
for ($i=10; $i<=100 ; $i+=10){
|
||||
for ($i=10; $i<=100 ; $i+=10){
|
||||
$addremoveoptions["$i"]="$i";
|
||||
}
|
||||
$mform->addElement('header', 'additemhdr', get_string('add', 'moodle'));
|
||||
@@ -150,23 +150,17 @@ class question_dataset_dependent_items_form extends moodleform {
|
||||
$mform->closeHeaderBefore('backtoquiz');
|
||||
|
||||
//hidden elements
|
||||
$mform->addElement('hidden', 'returnurl');
|
||||
$mform->setType('returnurl', PARAM_URL);
|
||||
$mform->addElement('hidden', 'qtype');
|
||||
$mform->setType('qtype', PARAM_ALPHA);
|
||||
$mform->addElement('hidden', 'category');
|
||||
$mform->setType('category', PARAM_INT);
|
||||
|
||||
$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', 'id');
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'wizard', 'datasetitems');
|
||||
$mform->setType('wizard', PARAM_ALPHA);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user