more work on the calculated and datasetdependent qtype

This commit is contained in:
jamiesensei
2007-01-13 08:59:00 +00:00
parent 73d716dea0
commit 8fc3e643ae
6 changed files with 189 additions and 7 deletions
+1
View File
@@ -10,4 +10,5 @@ $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';
$string['makecopynextpage'] = 'Next Page (new question)';
?>
+14
View File
@@ -0,0 +1,14 @@
<?php
$string['itemno'] = 'Item $a';
$string['param'] = 'Param {<strong>$a</strong>}';
$string['additem'] = 'Add Item';
$string['itemtoadd'] = 'Item To Add';
$string['calclength'] = 'Significant Figures';
$string['calcdistribution'] = 'Distribution';
$string['uniform'] = 'Uniform';
$string['loguniform'] = 'Loguniform';
$string['generate'] = 'Generate';
$string['calcmin'] = 'Minimum';
$string['calcmax'] = 'Maximum';
$string['minmax'] = 'Range of Values';
?>
@@ -152,9 +152,11 @@ class question_edit_calculated_form extends question_edit_form {
$key++;
}
}
$default_values['submitbutton'] = get_string('nextpage', 'qtype_calculated');
$question = (object)((array)$question + $default_values);
}
$default_values['submitbutton'] = get_string('nextpage', 'qtype_calculated');
$default_values['makecopy'] = get_string('makecopynextpage', 'qtype_calculated');
$question = (object)((array)$question + $default_values);
parent::set_data($question);
}
@@ -174,11 +176,13 @@ class question_edit_calculated_form extends question_edit_form {
foreach ($answers as $key => $answer){
//check no of choices
$trimmedanswer = trim($answer);
if (!empty($trimmedanswer)){
if (!empty($trimmedanswer)||$answercount==0){
$eqerror = qtype_calculated_find_formula_errors($trimmedanswer);
if (FALSE !== $eqerror){
$errors['answers['.$key.']'] = $eqerror;
}
}
if (!empty($trimmedanswer)){
if ('2' == $data['correctanswerformat'][$key]
&& '0' == $data['correctanswerlength'][$key]) {
$errors['correctanswerlength['.$key.']'] = get_string('zerosignificantfiguresnotallowed','quiz');
@@ -228,8 +228,7 @@ class question_dataset_dependent_questiontype extends default_questiontype {
$SESSION->datasetdependent->definitionform = $form;
} else {
// Something went wrong, go back to the first page
redirect("question.php?category={$question->category}" .
"&qtype={$question->qtype}");
redirect("question.php?category={$question->category}" ."&qtype={$question->qtype}");
}
} else {
$this->save_dataset_definitions($form);
@@ -237,8 +236,7 @@ class question_dataset_dependent_questiontype extends default_questiontype {
break;
case 'datasetitems':
if (empty($form->id) && isset($form->addbutton)) {
$question = parent::save_question($question,
$SESSION->datasetdependent->questionform, $course);
$question = parent::save_question($question, $SESSION->datasetdependent->questionform, $course);
$SESSION->datasetdependent->definitionform->id = $form->id = $question->id;
$this->save_dataset_definitions($SESSION->datasetdependent->definitionform);
unset($SESSION->datasetdependent);
@@ -0,0 +1,68 @@
<?php
class question_dataset_dependent_definitions_form extends moodleform {
/**
* Question object with options and answers already loaded by get_question_options
* Be careful how you use this it is needed sometimes to set up the structure of the
* form in definition_inner but data is always loaded into the form with set_defaults.
*
* @var object
*/
var $question;
/**
* Reference to question type object
*
* @var question_dataset_dependent_questiontype
*/
var $qtypeobj;
/**
* Add question-type specific form fields.
*
* @param MoodleQuickForm $mform the form being built.
*/
function question_dataset_dependent_definitions_form($submiturl, $question){
global $QTYPES;
$this->question = $question;
$this->qtypeobj =& $QTYPES[$this->question->qtype];
parent::moodleform($submiturl);
}
function definition() {
$mform =& $this->_form;
$possibledatasets = $this->qtypeobj->find_dataset_names($this->question->questiontext);
$mandatorydatasets = array();
foreach ($this->question->answers as $answer) {
$mandatorydatasets += $this->qtypeobj->find_dataset_names($answer);
}
$key = 0;
$datasetmenus = array();
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> ". get_string("substitutedby", "quiz");
$mform->addElement('select', "dataset[$key]", $label, $options);
$mform->setDefault("dataset[$key]", $selected);
$datasetmenus[$datasetname]='';
$key++;
}
}
foreach ($possibledatasets as $datasetname) {
if (!isset($datasetmenus[$datasetname])) {
list($options, $selected) =
$this->qtypeobj->dataset_options($this->question, $datasetname);
$label = get_string("wildcard", "quiz"). " <strong>$datasetname</strong> ". get_string("substitutedby", "quiz");
$mform->addElement('select', "dataset[$key]", $label, $options);
$mform->setDefault("dataset[$key]", $selected);
$datasetmenus[$datasetname]='';
$key++;
}
}
//hidden elements
$mform->addElement('hidden', 'wizardpage', 'datasetdefinitions');
$mform->setType('wizardpage', PARAM_ALPHA);
$this->add_action_buttons(true, get_string('nextpage', 'qtype_calculated'));
}
}
?>
@@ -0,0 +1,97 @@
<?php
class question_dataset_dependent_items_form extends moodleform {
/**
* Question object with options and answers already loaded by get_question_options
* Be careful how you use this it is needed sometimes to set up the structure of the
* form in definition_inner but data is always loaded into the form with set_defaults.
*
* @var object
*/
var $question;
/**
* Reference to question type object
*
* @var question_dataset_dependent_questiontype
*/
var $qtypeobj;
/**
* Add question-type specific form fields.
*
* @param MoodleQuickForm $mform the form being built.
*/
function question_dataset_dependent_items_form($submiturl, $question){
global $QTYPES;
$this->question = $question;
$this->qtypeobj =& $QTYPES[$this->question->qtype];
parent::moodleform($submiturl);
}
function definition() {
$mform =& $this->_form;
$repeated = array();
$repeatedoptions = array();
$repeated[] =& $mform->createElement('header', 'itemhdr', get_string('itemno', 'qtype_datasetdependent', '{no}'));
$params = array('a', 'b', 'c');
foreach ($params as $paramno => $param){
$idx = $paramno +1;
$repeated[] =& $mform->createElement('text', "number[$idx]", get_string('param', 'qtype_datasetdependent', $param));
$repeated[] =& $mform->createElement('hidden', "itemid[$idx]");
$repeated[] =& $mform->createElement('hidden', "definition[$idx]");
$repeatedoptions["number[$idx]"]['type'] = PARAM_NUMBER;
//$repeatedoptions["number[$idx]"]['rule'] = 'numeric';
$repeatedoptions["itemid[$idx]"]['type'] = PARAM_INT;
$repeatedoptions["definition[$idx]"]['type'] = PARAM_NOTAGS;
}
/*if (isset($this->question->options)){
$countanswers = count($this->question->options->answers);
} else {
$countanswers = 0;
}
$repeatsatstart = (QUESTION_NUMANS_START > ($countanswers + QUESTION_NUMANS_ADD))?
QUESTION_NUMANS_START : ($countanswers + QUESTION_NUMANS_ADD);
*/
$repeatsatstart = 3;
$this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'itemsno', 'itemsadd', 1, get_string('additem', 'qtype_datasetdependent'));
if ($this->qtypeobj->supports_dataset_item_generation()){
$radiogrp = array();
$radiogrp[] =& $mform->createElement('radio', "forceregeneration", 0, get_string('reuseifpossible', 'quiz'));
$radiogrp[] =& $mform->createElement('radio', "forceregeneration", 1, get_string('forceregeneration', 'quiz'));
$mform->addGroup($radiogrp, 'forceregenerationgrp', '', null, false);
}
$mform->addElement('header', 'additemhdr', get_string('itemtoadd', 'qtype_datasetdependent'));
foreach ($params as $paramno => $param){
$idx = $paramno +1;
$mform->addElement('text', "numbertoadd[$idx]", get_string('param', 'qtype_datasetdependent', $param));
$minmaxgrp = array();
$minmaxgrp[] =& $mform->createElement('text', "calcmin[$idx]", get_string('calcmin', 'qtype_datasetdependent'), 'size="3"');
$minmaxgrp[] =& $mform->createElement('text', "calcmax[$idx]", get_string('calcmax', 'qtype_datasetdependent'), 'size="3"');
$mform->addGroup($minmaxgrp, 'minmaxgrp', get_string('minmax', 'qtype_datasetdependent'), ' - ', false);
$precisionoptions = range(0, 10);
$mform->addElement('select', "calclength[$idx]", get_string('calclength', 'qtype_datasetdependent'), $precisionoptions);
$distriboptions = array('uniform' => get_string('uniform', 'qtype_datasetdependent'), 'loguniform' => get_string('loguniform', 'qtype_datasetdependent'));
$mform->addElement('select', "calcdistribution[$idx]", get_string('calcdistribution', 'qtype_datasetdependent'), $distriboptions);
$mform->addElement('submit', "generate[$idx]", get_string('generate', 'qtype_datasetdependent'));
$mform->addElement('hidden', "definition[$idx]");
$repeatedoptions["number[$idx]"]['type'] = PARAM_NUMBER;
//$repeatedoptions["number[$idx]"]['rule'] = 'numeric';
$repeatedoptions["itemid[$idx]"]['type'] = PARAM_INT;
$repeatedoptions["definition[$idx]"]['type'] = PARAM_NOTAGS;
}
$mform->addElement('hidden', 'wizardpage', 'datasetitems');
$mform->setType('wizardpage', PARAM_ALPHA);
$this->add_action_buttons(true);
}
}
?>