MDL-20176 Eliminate all PARAM_CLEAN, MDL-17366 cleaning code

This commit is contained in:
pichetp 2009-09-06 19:06:23 +00:00
parent 4aa9147a5e
commit 06f80c6ce7

View file

@ -104,7 +104,8 @@ class question_edit_calculatedsimple_form extends question_edit_form {
}else { }else {
// handle reload to get values from the form-elements // handle reload to get values from the form-elements
// answers, datasetdefs and data_items // answers, datasetdefs and data_items
// verify for the specific dataset values as the other parameters // In any case the validation step will warn the user of any error in settings the values.
// Verification for the specific dataset values as the other parameters
// unints, feeedback etc are handled elsewhere // unints, feeedback etc are handled elsewhere
// handle request buttons : // handle request buttons :
// 'analyzequestion' (Identify the wild cards {x..} present in answers) // 'analyzequestion' (Identify the wild cards {x..} present in answers)
@ -115,63 +116,64 @@ class question_edit_calculatedsimple_form extends question_edit_form {
// the mandatory (i.e. in answers) datasets // the mandatory (i.e. in answers) datasets
// to implement : don't do any changes if the question is used in a quiz. // to implement : don't do any changes if the question is used in a quiz.
// If new datadef, new properties should erase items. // If new datadef, new properties should erase items.
// Most of the data
$datasettoremove = false;
$newdatasetvalues = false ;
$newdataset = false ;
$dummyform = new stdClass(); $dummyform = new stdClass();
$mandatorydatasets = array(); $mandatorydatasets = array();
// should not test on adding a new answer
// should test if there are already olddatasets or if the 'analyzequestion' submit button has been clicked
if ('' != optional_param('datasetdef', '', PARAM_RAW) || '' != optional_param('analyzequestion', '', PARAM_RAW)){
if ( $dummyform->answer =optional_param('answer', '', PARAM_CLEAN)) { // there is always at least one answer... FIXME: sloppy coding if ( $dummyform->answer = optional_param('answer', '', PARAM_NOTAGS)) { // there is always at least one answer...
$fraction = optional_param('fraction', '', PARAM_CLEAN); //FIXME: sloppy coding $tolerance = optional_param('tolerance', '', PARAM_NUMBER);
$feedback = optional_param('feedback', '', PARAM_CLEAN); //FIXME: sloppy coding $tolerancetype = optional_param('tolerancetype', '', PARAM_NUMBER);
$tolerance = optional_param('tolerance', '', PARAM_CLEAN); //FIXME: sloppy coding $correctanswerlength = optional_param('correctanswerlength', '', PARAM_INT);
$tolerancetype = optional_param('tolerancetype', '', PARAM_CLEAN); //FIXME: sloppy coding $correctanswerformat = optional_param('correctanswerformat', '', PARAM_INT);
$correctanswerlength = optional_param('correctanswerlength', '', PARAM_CLEAN); //FIXME: sloppy coding
$correctanswerformat = optional_param('correctanswerformat', '', PARAM_CLEAN); //FIXME: sloppy coding foreach( $dummyform->answer as $key => $answer ) {
if(trim($answer) != ''){ // just look for non-empty
foreach( $dummyform->answer as $key => $answer ) { $this->answer[$key]=new stdClass();
if(trim($answer) != ''){ // just look for non-empty $this->answer[$key]->answer = $answer;
$this->answer[$key]=new stdClass(); $this->answer[$key]->tolerance = $tolerance[$key];
$this->answer[$key]->answer = $answer; $this->answer[$key]->tolerancetype = $tolerancetype[$key];
$this->answer[$key]->fraction = $fraction[$key]; $this->answer[$key]->correctanswerlength = $correctanswerlength[$key];
$this->answer[$key]->feedback = $feedback[$key]; $this->answer[$key]->correctanswerformat = $correctanswerformat[$key];
$this->answer[$key]->tolerance = $tolerance[$key]; $this->nonemptyanswer[]= $this->answer[$key];
$this->answer[$key]->tolerancetype = $tolerancetype[$key]; $mandatorydatasets +=$this->qtypeobj->find_dataset_names($answer);
$this->answer[$key]->correctanswerlength = $correctanswerlength[$key]; }
$this->answer[$key]->correctanswerformat = $correctanswerformat[$key];
$this->nonemptyanswer[]= $this->answer[$key];
$mandatorydatasets +=$this->qtypeobj->find_dataset_names($answer);
} }
} }
} $this->datasetdefs = array();
$this->datasetdefs = array(); // rebuild datasetdefs from old values
// rebuild datasetdefs from old values if ($olddef = optional_param('datasetdef', '', PARAM_RAW)){
$olddef = optional_param('datasetdef', '', PARAM_CLEAN); //FIXME: sloppy coding $calcmin = optional_param('calcmin', '', PARAM_NUMBER);
$oldoptions = optional_param('defoptions', '', PARAM_CLEAN); //FIXME: sloppy coding $calclength = optional_param('calclength', '', PARAM_INT);
$calcmin = optional_param('calcmin', '', PARAM_CLEAN); //FIXME: sloppy coding $calcmax = optional_param('calcmax', '', PARAM_NUMBER);
$calclength = optional_param('calclength', '', PARAM_CLEAN); //FIXME: sloppy coding $newdatasetvalues = false ;
$calcmax = optional_param('calcmax', '', PARAM_CLEAN); //FIXME: sloppy coding for($key = 1 ; $key <= sizeof($olddef) ; $key++) {
$newdatasetvalues = false ; $def = $olddef[$key] ;
$this->datasetdefs[$def]= new stdClass ;
for($key = 1 ; $key <= sizeof($olddef) ; $key++) { $this->datasetdefs[$def]->type = 1;
$def = $olddef[$key] ; $this->datasetdefs[$def]->category = 0;
$this->datasetdefs[$def]= new stdClass ; // $this->datasets[$key]->name = $datasetname;
$this->datasetdefs[$def]->type = 1; // $this->datasetdefs[$def]->options = $oldoptions[$key] ;
$this->datasetdefs[$def]->category = 0; $this->datasetdefs[$def]->calcmin = $calcmin[$key] ;
// $this->datasets[$key]->name = $datasetname; $this->datasetdefs[$def]->calcmax = $calcmax[$key] ;
$this->datasetdefs[$def]->options = $oldoptions[$key] ; $this->datasetdefs[$def]->calclength = $calclength[$key] ;
$this->datasetdefs[$def]->calcmin = $calcmin[$key] ; //then compare with new values
$this->datasetdefs[$def]->calcmax = $calcmax[$key] ; if (preg_match('~^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$~', $this->datasetdefs[$def]->options, $regs)) {
$this->datasetdefs[$def]->calclength = $calclength[$key] ; if( $this->datasetdefs[$def]->calcmin != $regs[2]||
//then compare with new values $this->datasetdefs[$def]->calcmax != $regs[3] ||
if (preg_match('~^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$~', $this->datasetdefs[$def]->options, $regs)) { $this->datasetdefs[$def]->calclength != $regs[4]){
if( $this->datasetdefs[$def]->calcmin != $regs[2]|| $newdatasetvalues = true ;
$this->datasetdefs[$def]->calcmax != $regs[3] || }
$this->datasetdefs[$def]->calclength != $regs[4]){ }
$newdatasetvalues = true ; $this->datasetdefs[$def]->options="uniform:".$this->datasetdefs[$def]->calcmin.":".$this->datasetdefs[$def]->calcmax.":".$this->datasetdefs[$def]->calclength;
} }
} }// if (olddef...
$this->datasetdefs[$def]->options="uniform:".$this->datasetdefs[$def]->calcmin.":".$this->datasetdefs[$def]->calcmax.":".$this->datasetdefs[$def]->calclength; // detect new datasets
}
// detect new datasets
$newdataset = false ; $newdataset = false ;
foreach ($mandatorydatasets as $datasetname) { foreach ($mandatorydatasets as $datasetname) {
if (!isset($this->datasetdefs["1-0-$datasetname"])) { if (!isset($this->datasetdefs["1-0-$datasetname"])) {
@ -193,7 +195,8 @@ class question_edit_calculatedsimple_form extends question_edit_form {
$datasettoremove = true; $datasettoremove = true;
unset($this->datasetdefs[$defkey]); unset($this->datasetdefs[$defkey]);
} }
} }
}
} // handle reload } // handle reload
// create items if $newdataset and noofitems > 0 and !$newdatasetvalues // create items if $newdataset and noofitems > 0 and !$newdatasetvalues
// eliminate any items if $newdatasetvalues // eliminate any items if $newdatasetvalues
@ -206,7 +209,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
} }
$maxnumber = -1 ; $maxnumber = -1 ;
if ( "" !=optional_param('addbutton')){ if ( "" !=optional_param('addbutton')){
$maxnumber = optional_param('selectadd', '', PARAM_CLEAN); //FIXME: sloppy coding $maxnumber = optional_param('selectadd', '', PARAM_INT); //FIXME: sloppy coding
foreach ($this->datasetdefs as $defid => $datasetdef) { foreach ($this->datasetdefs as $defid => $datasetdef) {
$datasetdef->itemcount = $maxnumber; $datasetdef->itemcount = $maxnumber;
unset($datasetdef->items); unset($datasetdef->items);
@ -223,9 +226,9 @@ class question_edit_calculatedsimple_form extends question_edit_form {
// Handle reload dataset items // Handle reload dataset items
if ( "" !=optional_param('definition')&& !($datasettoremove ||$newdataset ||$newdatasetvalues )){ if ( "" !=optional_param('definition')&& !($datasettoremove ||$newdataset ||$newdatasetvalues )){
$i = 1; $i = 1;
$fromformdefinition = optional_param('definition', '', PARAM_CLEAN); //FIXME: sloppy coding $fromformdefinition = optional_param('definition', '', PARAM_NOTAGS);
$fromformnumber = optional_param('number', '', PARAM_CLEAN); //FIXME: sloppy coding $fromformnumber = optional_param('number', '', PARAM_INT);
$fromformitemid = optional_param('itemid', '', PARAM_CLEAN); //FIXME: sloppy coding $fromformitemid = optional_param('itemid', '', PARAM_INT);
ksort($fromformdefinition); ksort($fromformdefinition);
foreach($fromformdefinition as $key => $defid) { foreach($fromformdefinition as $key => $defid) {
@ -488,7 +491,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
$j = $this->noofitems * count($this->datasetdefs); $j = $this->noofitems * count($this->datasetdefs);
$k = 1 ; $k = 1 ;
if ("" != optional_param('selectshow')){ if ("" != optional_param('selectshow')){
$k = optional_param('selectshow', '', PARAM_CLEAN); //FIXME: sloppy coding $k = optional_param('selectshow', '', PARAM_INT);
} }
for ($i = $this->noofitems; $i >= 1 ; $i--){ for ($i = $this->noofitems; $i >= 1 ; $i--){
@ -570,7 +573,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
function set_data($question) { function set_data($question) {
$answer = $this->answer; $answer = $this->answer;
$default_values = array(); $default_values = array();
if (count($answer)) { /* if (count($answer)) {
$key = 0; $key = 0;
foreach ($answer as $answer){ foreach ($answer as $answer){
$default_values['answer['.$key.']'] = $answer->answer; $default_values['answer['.$key.']'] = $answer->answer;
@ -582,7 +585,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
$default_values['feedback['.$key.']'] = $answer->feedback; $default_values['feedback['.$key.']'] = $answer->feedback;
$key++; $key++;
} }
} }*/
if (isset($question->options)){ if (isset($question->options)){
$units = array_values($question->options->units); $units = array_values($question->options->units);
// make sure the default unit is at index 0 // make sure the default unit is at index 0
@ -664,7 +667,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
$qtext = ""; $qtext = "";
$qtextremaining = $data['questiontext'] ; $qtextremaining = $data['questiontext'] ;
$possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']); $possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']);
foreach ($possibledatasets as $name => $value) { foreach ($possibledatasets as $name => $value) {
$qtextremaining = str_replace('{'.$name.'}', '1', $qtextremaining); $qtextremaining = str_replace('{'.$name.'}', '1', $qtextremaining);
} }
while (preg_match('~\{=([^[:space:]}]*)}~', $qtextremaining, $regs1)) { while (preg_match('~\{=([^[:space:]}]*)}~', $qtextremaining, $regs1)) {