diff --git a/lang/en_utf8/qtype_calculatedsimple.php b/lang/en_utf8/qtype_calculatedsimple.php index 4fd496f080c..50ff9173f13 100644 --- a/lang/en_utf8/qtype_calculatedsimple.php +++ b/lang/en_utf8/qtype_calculatedsimple.php @@ -1,5 +1,6 @@ {x..} present in the correct answer formulas'; $string['calculatedsimple'] = 'Calculated Simple '; $string['calculatedsimplesummary'] = 'A simpler version of calculated questions which are like numerical questions but with the numbers used selected randomly from a set when the quiz is taken.'; $string['converttocalculated'] = 'Save as a new regular calculated question'; @@ -8,8 +9,14 @@ $string['findwildcards']='Find the wild cards {x..} present in the correct answe $string['generatenewitemsset'] = 'Generate a new set of '; $string['mustbenumeric'] = 'You must enter a number here.'; $string['mustnotbenumeric'] = 'This can\'t be a number.'; -$string['wildcarditems']= 'Items generated'; +$string['showitems'] = 'Display '; +$string['updatewildcardvalues'] = 'Update the wild card(s) values'; +$string['useadvance'] = 'Use the advance button to see the errors' ; +$string['wildcard'] = 'Wild card {$a}'; +$string['wildcardvalues']= 'Wild card(s) values '; +$string['wildcardvaluesgenerated']= 'Wild card(s) values generated'; $string['wildcardrole']= ' The wild cards {x..} will be substituted by a numerical value from the generated values'; -$string['wildcardparam']= 'Wild cards parameters used to generate the items '; +$string['wildcardparam']= 'Wild cards parameters used to generate the values '; $string['willconverttocalculated']= 'If set, the Save as new question will save as a new calculated question'; +$string['youmustaddatleastonevalue'] = 'You must add at least one set of wild card(s) values before you can save this question.'; ?> \ No newline at end of file diff --git a/question/type/calculatedsimple/edit_calculatedsimple_form.php b/question/type/calculatedsimple/edit_calculatedsimple_form.php index c2be49a483d..5cc016a6879 100644 --- a/question/type/calculatedsimple/edit_calculatedsimple_form.php +++ b/question/type/calculatedsimple/edit_calculatedsimple_form.php @@ -41,13 +41,15 @@ class question_edit_calculatedsimple_form extends question_edit_form { public $answer = array(); public $nonemptyanswer = array(); + + public $numbererrors = array(); + + public $formdata = array(); + function question_edit_calculatedsimple_form(&$submiturl, &$question, &$category, &$contexts, $formeditable = true){ global $QTYPES, $SESSION, $CFG, $DB; - // echo "
QTYPES
";print_r($QTYPES);echo""; - // echo "
session
";print_r($SESSION);echo""; - // echo "
question
";print_r($question);echo""; $this->regenerate = true; $this->question = $question; $this->qtypeobj =& $QTYPES[$this->question->qtype]; @@ -60,7 +62,6 @@ class question_edit_calculatedsimple_form extends question_edit_form { // question->id == 0 so no stored datasets // else get datasets if ( "1" == optional_param('reload','', PARAM_INT )) { - // echo "
optional reload exist
"; $this->reload = true ; }else { $this->reload = false ; @@ -138,8 +139,6 @@ class question_edit_calculatedsimple_form extends question_edit_form { } } } - // echo "this->answer
";print_r($this->answer);echo""; - // echo "
this->answer
";print_r($this->nonemptyanswer);echo""; $this->datasetdefs = array(); // rebuild datasetdefs from old values $olddef = optional_param('datasetdef'); @@ -147,11 +146,7 @@ class question_edit_calculatedsimple_form extends question_edit_form { $calcmin = optional_param('calcmin') ; $calclength = optional_param('calclength') ; $calcmax = optional_param('calcmax') ; - /* echo "
calcmin
";print_r(optional_param('calcmin'));echo"";
- echo "calcmax
";print_r(optional_param('calcmax'));echo"";
- echo "calclength
";print_r(optional_param('calclength'));echo"";*/
$newdatasetvalues = false ;
- // echo "olddef
";print_r(optional_param('datasetdef'));echo"";
for($key = 1 ; $key <= sizeof($olddef) ; $key++) {
$def = $olddef[$key] ;
@@ -169,14 +164,12 @@ class question_edit_calculatedsimple_form extends question_edit_form {
$this->datasetdefs[$def]->calcmax != $regs[3] ||
$this->datasetdefs[$def]->calclength != $regs[4]){
$newdatasetvalues = true ;
- // echo "new datasetdefs values ".$regs[2]."xx". $regs[3]."xx".$regs[4]."
"; } } $this->datasetdefs[$def]->options="uniform:".$this->datasetdefs[$def]->calcmin.":".$this->datasetdefs[$def]->calcmax.":".$this->datasetdefs[$def]->calclength; } - // echo "this datasetdefs
";print_r($this->datasetdefs);echo""; // detect new datasets $newdataset = false ; foreach ($mandatorydatasets as $datasetname) { @@ -190,7 +183,6 @@ class question_edit_calculatedsimple_form extends question_edit_form { $this->datasetdefs[$key]->name = $datasetname; $this->datasetdefs[$key]->options = "uniform:1.0:10.0:1"; $newdataset = true ; - // echo "
new datasetdefs $datasetname
"; // $form->dataset[$key]=$selected ; //$key++; }else { @@ -201,7 +193,6 @@ class question_edit_calculatedsimple_form extends question_edit_form { $datasettoremove = false; foreach ($this->datasetdefs as $defkey => $datasetdef){ if(!isset($datasetdef->name )){ - // echo "dataset $defkey to remove
"; $datasettoremove = true; unset($this->datasetdefs[$defkey]); } @@ -237,18 +228,14 @@ class question_edit_calculatedsimple_form extends question_edit_form { }//for number added }// datasetsdefs end $this->maxnumber = $maxnumber ; - // echo"using create new items $this->maxnumber
"; }else { // Handle reload dataset items - // echo"using optional to build
"; if ( "" !=optional_param('definition')&& !($datasettoremove ||$newdataset ||$newdatasetvalues )){ $i = 1; $fromformdefinition = optional_param('definition'); $fromformnumber = optional_param('number'); $fromformitemid = optional_param('itemid'); ksort($fromformdefinition); - // echo "fromformdefinition
";print_r($fromformdefinition);echo""; - // echo "
fromformnumber
";print_r($fromformnumber);echo""; foreach($fromformdefinition as $key => $defid) { $addeditem = new stdClass(); @@ -270,12 +257,6 @@ class question_edit_calculatedsimple_form extends question_edit_form { } } - // echo "
line 443 datasetdefs
";print_r($this->datasetdefs);echo""; - //$key = 0 ; - // if ( "" !=optional_param('answer')) echo "
optional answer exist
"; - // if ( "" !=optional_param('answer['.$key.']','', PARAM_NOTAGS)) echo "optional $key exist
"; - // if ( "" !=optional_param('noanswer','', PARAM_INT )) echo "optional noanswer exist
"; - parent::question_edit_form($submiturl, $question, $category, $contexts, $formeditable); } @@ -307,14 +288,14 @@ class question_edit_calculatedsimple_form extends question_edit_form { global $QTYPES; $this->qtypeobj =& $QTYPES[$this->qtype()]; $strquestionlabel = $this->qtypeobj->comment_header($this->nonemptyanswer); - $label = get_string("sharedwildcards", "qtype_datasetdependent"); + $label = get_string("sharedwildcards", "qtype_datasetdependent"); $mform->addElement('hidden', 'initialcategory', 1); $mform->addElement('hidden', 'reload', 1); // $html2 = $this->qtypeobj->print_dataset_definitions_category($this->question); // $mform->insertElementBefore($mform->createElement('static','listcategory',$label,$html2),'name'); - $addfieldsname='updatecategory'; + $addfieldsname='updatequestion value'; $addstring=get_string("updatecategory", "qtype_calculated"); - $mform->registerNoSubmitButton($addfieldsname); + $mform->registerNoSubmitButton($addfieldsname); // $mform->insertElementBefore( $mform->createElement('submit', $addfieldsname, $addstring),'listcategory'); @@ -363,9 +344,6 @@ class question_edit_calculatedsimple_form extends question_edit_form { if ( "" != optional_param('analyzequestion','', PARAM_RAW)) { $this->wizarddisplay = true; - // echo "session answer
";print_r($SESSION);echo""; - // echo "
session answer
";print_r($SESSION->calculated->questionform->answers);echo""; - }else { $this->wizwarddisplay = false; @@ -375,55 +353,169 @@ class question_edit_calculatedsimple_form extends question_edit_form { } else { $this->noofitems = 0; } - if(!empty($this->datasetdefs)){ + if(!empty($this->datasetdefs)){//So there are some datadefs + // we put them on the page + $key = 0; + $mform->addElement('header', 'additemhdr', get_string('wildcardparam', 'qtype_calculatedsimple')); + $idx = 1; + if(!empty($this->datasetdefs)){// unnecessary test + $j = (($this->noofitems) * count($this->datasetdefs))+1;// + foreach ($this->datasetdefs as $defkey => $datasetdef){ + $mform->addElement('static', "na[$j]", get_string('param', 'qtype_datasetdependent', $datasetdef->name)); + $this->qtypeobj->custom_generator_tools_part($mform, $idx, $j); + $mform->addElement('hidden', "datasetdef[$idx]"); + $mform->setType("datasetdef[$idx]", PARAM_RAW); + $idx++; + $mform->addElement('static', "divider[$j]", '', '
mandatorydatasets $key xx".optional_param("answer[0]",'', PARAM_NOTAGS)."YY".$this->_form->getElementValue('answer['.$key.']')."xx
"; $formdata = array(); $fromform = new stdClass(); + //this should be done before the elements are created and stored as $this->formdata ; //fill out all data sets and also the fields for the next item to add. - if(!empty($this->datasetdefs)){ + /* if(!empty($this->datasetdefs)){ $j = $this->noofitems * count($this->datasetdefs); for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--){ $data = array(); @@ -562,9 +659,8 @@ class question_edit_calculatedsimple_form extends question_edit_form { $idx++; } $formdata = $this->qtypeobj->custom_generator_set_data($this->datasetdefs, $formdata); - } - $question = (object)((array)$question + $default_values+$formdata ); - // echo "
question data
";print_r($question);echo""; + }*/ + $question = (object)((array)$question + $default_values+$this->formdata ); parent::set_data($question); } @@ -582,7 +678,6 @@ class question_edit_calculatedsimple_form extends question_edit_form { foreach ($possibledatasets as $name => $value) { $qtextremaining = str_replace('{'.$name.'}', '1', $qtextremaining); } - // echo "numericalquestion qtextremaining
";print_r($possibledatasets);
while (ereg('\{=([^[:space:]}]*)}', $qtextremaining, $regs1)) {
$qtextsplits = explode($regs1[0], $qtextremaining, 2);
$qtext =$qtext.$qtextsplits[0];
@@ -604,8 +699,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
$mandatorydatasets += $this->qtypeobj->find_dataset_names($answer);
}
if ( count($mandatorydatasets )==0){
- // $errors['questiontext']=get_string('atleastonewildcard', 'qtype_datasetdependent');
- foreach ($answers as $key => $answer){
+ foreach ($answers as $key => $answer){
$errors['answer['.$key.']'] = get_string('atleastonewildcard', 'qtype_datasetdependent');
}
}
@@ -691,20 +785,24 @@ class question_edit_calculatedsimple_form extends question_edit_form {
// if(!isset($errors['warning'])) $errors['warning']=' ';
$errors['outsidelimits'] = get_string('oneanswertrueansweroutsidelimits','qtype_calculated');
}
+ /*Here we use the already done the error analysis so that
+ * we could force all wild cards values display if there is an error in values.
+ * as using a , in a number */
$numbers = $data['number'];
foreach ($numbers as $key => $number){
if(! is_numeric($number)){
if (stristr($number,',')){
- $errors['number['.$key.']'] = get_string('The , cannot be used, use . as in 0.013 or 1.3e-2', 'qtype_datasetdependent');
+ $errors['number['.$key.']'] = get_string('notvalidnumber', 'qtype_datasetdependent');
}else {
- $errors['number['.$key.']'] = get_string('This is not a valid number', 'qtype_datasetdependent');
+ $errors['number['.$key.']'] = get_string('notvalidnumber', 'qtype_datasetdependent');
}
}else if( stristr($number,'x')){
- $errors['number['.$key.']'] = get_string('Hexadecimal format (i.e. 0X12d) is not allowed', 'qtype_datasetdependent');
+ $errors['number['.$key.']'] = get_string('notvalidnumber', 'qtype_datasetdependent');
} else if( is_nan($number)){
- $errors['number['.$key.']'] = get_string('is a NAN number', 'qtype_datasetdependent');
+ $errors['number['.$key.']'] = get_string('notvalidnumber', 'qtype_datasetdependent');
}
}
+
if ( $this->noofitems==0 ){
$errors['warning'] = get_string('warning', 'mnet');
}