$string['tolerance'] = 'Tolerance ±';
$string['addmoreanswerblanks'] = 'Add another answer blank.';
$string['addmoreunitblanks'] = 'Blanks for $a More Units';
-$string['answerhdr'] = 'Answer $a';
+$string['answerhdr'] = 'Answer';
$string['atleastoneanswer'] = 'You need to provide at least one answer.';
$string['mustbenumeric'] = 'You must enter a number here.';
$string['mustnotbenumeric'] = 'This can\'t be a number.';
$string['youmustenteramultiplierhere'] = 'You must enter a multiplier here.';
+$string['nextpage'] = 'Next Page';
?>
\ No newline at end of file
$id = optional_param('id', 0, PARAM_INT); // question id
$qtype = optional_param('qtype', '', PARAM_FILE);
$categoryid = optional_param('category', 0, PARAM_INT);
+$wizard = optional_param('wizard', '', PARAM_ALPHA);
// Validate the URL parameters.
if ($id = optional_param('id', 0, PARAM_INT)) {
print_error('questiondoesnotexist', 'question', $returnurl);
}
get_question_options($question);
- $submiturl = "question2.php?id=$id&returnurl=" . urlencode($returnurl);
+ $submiturl = "question2.php?id=$id&returnurl=" . urlencode($returnurl).'&wizard='.$wizard;
} else if ($categoryid && $qtype) { // only for creating new questions
$question = new stdClass;
$question->category = $categoryid;
$question->qtype = $qtype;
- $submiturl = "question2.php?category=$categoryid&qtype=$qtype&returnurl=" . urlencode($returnurl);
+ $submiturl = "question2.php?category=$categoryid&qtype=$qtype&returnurl=" . urlencode($returnurl).'&wizard='.$wizard;
} else {
print_error('notenoughdatatoeditaquestion', 'question', $returnurl);
}
require_capability('moodle/question:manage', $coursecontext);
// Create the question editing form.
-$mform = $QTYPES[$question->qtype]->create_editing_form($submiturl, $question, $category->course);
+if ($wizard!==''){
+ if (!method_exists($QTYPES[$question->qtype], 'next_wizard_form')){
+ print_error('missingimportantcode', 'question', $returnurl, 'wizard form definition');
+ } else {
+ $mform = $QTYPES[$question->qtype]->next_wizard_form($submiturl, $question, $wizard);
+ }
+} else {
+ $mform = $QTYPES[$question->qtype]->create_editing_form($submiturl, $question, $category->course);
+}
+
if ($mform === null) {
print_error('missingimportantcode', 'question', $returnurl, 'question editing form definition');
}
+$mform->set_defaults($question);
if ($mform->is_cancelled()){
redirect($returnurl);
$question->hidden = 0; // Copies should not be hidden
}
$question = $QTYPES[$qtype]->save_question($question, $data, $COURSE);
-
- if (optional_param('inpopup', 0, PARAM_BOOL)) {
- notify(get_string('changessaved'), '');
- close_window(3);
+ if ($QTYPES[$qtype]->finished_edit_wizard($question)){
+ if (optional_param('inpopup', 0, PARAM_BOOL)) {
+ notify(get_string('changessaved'), '');
+ close_window(3);
+ } else {
+ redirect($SESSION->returnurl);
+ }
+ die;
} else {
- redirect($SESSION->returnurl);
+ redirect($submiturl.'&wizard='.$data->wizardpage);
}
} else {
// Display the question editing form
get_string("editquestions", "quiz").'</a> -> '.$streditingquestion;
}
print_header_simple($streditingquestion, '', $strediting);
-
- print_heading_with_help(get_string("editing".$question->qtype, "quiz"), $question->qtype, "quiz");
-
- $mform->set_defaults($question);
+ if (isset($mform->heading)){
+ print $mform->heading;
+ } else {
+ print_heading_with_help(get_string("editing".$question->qtype, "quiz"), $question->qtype, "quiz");
+ }
$mform->display();
print_footer($COURSE);
}
*/
function definition_inner(&$mform) {
global $QTYPES;
- $this->qtypeobj = $QTYPES['calculated'];
+ $this->qtypeobj =& $QTYPES[$this->qtype()];
//------------------------------------------------------------------------------------------
+/* //not working now datasetdependent code cannot handle multiple answer formulas and not needed ??
$repeated = array();
$repeated[] =& $mform->createElement('header', 'answerhdr', get_string('answerhdr', 'qtype_calculated', '{no}'));
$count = 0;
}
$repeatsatstart = $count + 1;
- $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', 1, get_string('addmoreanswerblanks', 'qtype_calculated'));
+ $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', 1, get_string('addmoreanswerblanks', 'qtype_calculated'));*/
+//------------------------------------------------------------------------------------------
+
+ $mform->addElement('header', 'answerhdr', get_string('answerhdr', 'qtype_calculated'));
+
+ $mform->addElement('text', 'answers[0]', get_string('correctanswerformula', 'quiz'));
+ $mform->setType('answers[0]', PARAM_NOTAGS);
+
+/* $creategrades = get_grade_options();
+ $gradeoptions = $creategrades->gradeoptions;
+ $mform->addElement('select', 'fraction[0]', get_string('grade'), $gradeoptions);
+ $mform->setDefault('fraction[0]', 0);*/
+ $mform->addElement('hidden', 'fraction[0]', 1);
+ $mform->setConstants(array('fraction[0]'=>PARAM_INT));
+
+ $tolgrp = array();
+ $tolgrp[] =& $mform->createElement('text', 'tolerance[0]', get_string('tolerance', 'qtype_calculated'));
+ $mform->setType('tolerance[0]', PARAM_NUMBER);
+ $mform->setDefault('tolerance[0]', 0.01);
+ $tolgrp[] =& $mform->createElement('select', 'tolerancetype[0]', get_string('tolerancetype', 'quiz'), $this->qtypeobj->tolerance_types());
+ $mform->addGroup($tolgrp, 'tolgrp', get_string('tolerance', 'qtype_calculated'), null, false);
+
+ $anslengrp = array();
+ $anslengrp[] =& $mform->createElement('select', 'correctanswerlength[0]', get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
+ $mform->setDefault('correctanswerlength[0]', 2);
+
+ $answerlengthformats = array('1' => get_string('decimalformat', 'quiz'), '2' => get_string('significantfiguresformat', 'quiz'));
+ $anslengrp[] =& $mform->createElement('select', 'correctanswerformat[0]', get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats);
+ $mform->addGroup($anslengrp, 'anslengrp', get_string('correctanswershows', 'qtype_calculated'), null, false);
+
+ $mform->addElement('htmleditor', 'feedback[0]', get_string('feedback', 'quiz'));
+ $mform->setType('feedback[0]', PARAM_RAW);
//------------------------------------------------------------------------------------------
$repeated = array();
//hidden elements
$mform->addElement('hidden', 'wizardpage', 'question');
+ $mform->setType('wizardpage', PARAM_ALPHA);
+
}
if (count($answers)) {
$key = 0;
foreach ($answers as $answer){
- $default_values['answers['.$key.']'] = $answers->answer;
- $default_values['fraction['.$key.']'] = $answers->fraction;
- $default_values['tolerance['.$key.']'] = $answers->tolerance;
- $default_values['correctanswerlength['.$key.']'] = $answers->correctanswerlength;
+ $default_values['answers['.$key.']'] = $answer->answer;
+ $default_values['fraction['.$key.']'] = $answer->fraction;
+ $default_values['tolerance['.$key.']'] = $answer->tolerance;
+ $default_values['correctanswerlength['.$key.']'] = $answer->correctanswerlength;
$default_values['correctanswerformat['.$key.']'] = $answer->correctanswerformat;
$default_values['feedback['.$key.']'] = $answer->feedback;
$key++;
$key++;
}
}
- $question = (object)((array)$question + $default_values); }
+ $default_values['submitbutton'] = get_string('nextpage', 'qtype_calculated');
+ $question = (object)((array)$question + $default_values);
+ }
+
parent::set_defaults($question);
}
$answer->answer = $correctanswer->answer;
}
$numericalquestion->questiontext = parent::substitute_variables(
- $numericalquestion->questiontext, $state->options->dataset);
+ $numericalquestion->questiontext, $state->options->dataset);
$virtualqtype->print_question_formulation_and_controls($numericalquestion,
$state, $cmoptions, $options);
}
}
return $str;
}
-
+
/// BACKUP FUNCTIONS ////////////////////////////
/*
}
}
+ // This gets called by question2.php after the standard question is saved
+ function &next_wizard_form($submiturl, $question, $wizard){
+ global $CFG, $SESSION;
+
+ // Catch invalid navigation & reloads
+ if (empty($question->id) && empty($SESSION->datasetdependent)) {
+ redirect('edit.php', 'The page you are loading has expired.', 3);
+ }
+ if (!isset($question->id)){
+ $question =& $SESSION->datasetdependent->questionform;
+ }
+
+ // See where we're coming from
+ switch($wizard) {
+ case 'question':
+ require("$CFG->dirroot/question/type/datasetdependent/datasetdefinitions_form.php");
+ $mform =& new question_dataset_dependent_definitions_form($submiturl, $question);
+ $mform->heading = print_heading_with_help(get_string("choosedatasetproperties", "quiz"), "questiondatasets", "quiz", '', true);
+ break;
+ case 'datasetdefinitions':
+ case 'datasetitems':
+ require("$CFG->dirroot/question/type/datasetdependent/datasetitems_form.php");
+ $mform =& new question_dataset_dependent_items_form($submiturl, $question);
+ $streditdatasets = get_string("editdatasets", "quiz");
+ $mform->heading = print_heading_with_help($streditdatasets, 'questiondatasets', "quiz", '', true);
+ break;
+ default:
+ error('Incorrect or no wizard page specified!');
+ break;
+ }
+
+ return $mform;
+ }
function save_question($question, &$form, $course) {
// For dataset dependent questions a wizard is used for editing
// questions. Therefore saving the question is delayed until
* @var object
*/
var $question;
- /**
- * Course id
- *
- * @var integer
- */
- var $courseid;
+
function question_edit_form($submiturl, $question){
$this->question = $question;
parent::moodleform($submiturl);
// Standard fields at the start of the form.
$mform->addElement('header', 'generalheader', get_string("general", 'form'));
- $mform->addElement('questioncategory', 'category', get_string('category', 'quiz'),
+ $mform->addElement('questioncategory', 'category', get_string('category', 'quiz'), null,
array('courseid' => $COURSE->id, 'published' => true, 'only_editable' => true));
$mform->addElement('text', 'name', get_string('questionname', 'quiz'),
$mform->addElement('text', 'defaultgrade', get_string('defaultgrade', 'quiz'),
array('size' => 3));
$mform->setType('defaultgrade', PARAM_INT);
+ $mform->setDefault('defaultgrade', 1);
$mform->addRule('defaultgrade', null, 'required', null, 'client');
$mform->addElement('text', 'penalty', get_string('penaltyfactor', 'quiz'),
$mform->setType('penalty', PARAM_NUMBER);
$mform->addRule('penalty', null, 'required', null, 'client');
$mform->setHelpButton('penalty', array('penalty', get_string('penalty', 'quiz'), 'quiz'));
+ $mform->setDefault('penalty', 0.1);
$mform->addElement('htmleditor', 'generalfeedback', get_string('generalfeedback', 'quiz'),
array('rows' => 10, 'course' => $COURSE->id));
function set_defaults($question) {
global $QTYPES;
- if (!isset($question->id)){
- $QTYPES[$question->qtype]->set_default_options($question);
- }
+ $QTYPES[$question->qtype]->set_default_options($question);
if (empty($question->image)){
unset($question->image);
}
* @param $question
*/
function set_default_options(&$question) {
- $question->penalty = 0.1;
- $question->defaultgrade = 1;
}
/**