MDL-20296 creating common functions to handle units in numerical, calculated and calculatedsimple edit forms
This commit is contained in:
@@ -143,33 +143,7 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
}
|
||||
}
|
||||
$default_values['synchronize'] = $question->options->synchronize ;
|
||||
$default_values['unitgradingtype'] = $question->options->unitgradingtype ;
|
||||
$default_values['unitpenalty'] = $question->options->unitpenalty ;
|
||||
switch ($question->options->showunits){
|
||||
case 'O' :
|
||||
case '1' :
|
||||
$default_values['showunits0'] = $question->options->showunits ;
|
||||
$default_values['unitrole'] = 0 ;
|
||||
break;
|
||||
case '2' :
|
||||
case '3' :
|
||||
$default_values['showunits1'] = $question->options->showunits ;
|
||||
$default_values['unitrole'] = 1 ;
|
||||
break;
|
||||
}
|
||||
$default_values['unitsleft'] = $question->options->unitsleft ;
|
||||
$default_values['instructions'] = $question->options->instructions ;
|
||||
|
||||
if (isset($question->options->units)){
|
||||
$units = array_values($question->options->units);
|
||||
if (!empty($units)) {
|
||||
foreach ($units as $key => $unit){
|
||||
$default_values['unit['.$key.']'] = $unit->unit;
|
||||
$default_values['multiplier['.$key.']'] = $unit->multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$QTYPES['numerical']->set_numerical_unit_data($question,$default_values);
|
||||
if (isset($question->options->single)){
|
||||
$default_values['single'] = $question->options->single;
|
||||
$default_values['answernumbering'] = $question->options->answernumbering;
|
||||
@@ -324,26 +298,6 @@ class question_edit_calculated_form extends question_edit_form {
|
||||
}
|
||||
}*/
|
||||
$QTYPES['numerical']->validate_numerical_options($data, $errors) ;
|
||||
/* if ($data['unitrole'] == 0 ){
|
||||
$showunits = $data['showunits0'];
|
||||
}else {
|
||||
$showunits = $data['showunits1'];
|
||||
}
|
||||
|
||||
if (($showunits == 0) || ($showunits == 1) || ($showunits == 2)){
|
||||
if (trim($units[0]) == ''){
|
||||
$errors['unit[0]'] = 'You must set a valid unit name' ;
|
||||
}
|
||||
}
|
||||
if ($showunits == 3 ){
|
||||
if (count($units)) {
|
||||
foreach ($units as $key => $unit){
|
||||
if ($units[$key] != ''){
|
||||
$errors["unit[$key]"] = 'You must erase this unit name' ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if ($answercount==0){
|
||||
$errors['answer[0]'] = get_string('atleastoneanswer', 'qtype_calculated');
|
||||
}
|
||||
|
||||
@@ -130,6 +130,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
|
||||
if ('' != optional_param('datasetdef', '', PARAM_RAW) || '' != optional_param('analyzequestion', '', PARAM_RAW)){
|
||||
|
||||
if ( $dummyform->answer = optional_param('answer', '', PARAM_NOTAGS)) { // there is always at least one answer...
|
||||
$tolerance = optional_param('tolerance', '', PARAM_NUMBER);
|
||||
$tolerance = optional_param('tolerance', '', PARAM_NUMBER);
|
||||
$tolerancetype = optional_param('tolerancetype', '', PARAM_NUMBER);
|
||||
$correctanswerlength = optional_param('correctanswerlength', '', PARAM_INT);
|
||||
@@ -139,7 +140,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
|
||||
if(trim($answer) != ''){ // just look for non-empty
|
||||
$this->answer[$key]=new stdClass();
|
||||
$this->answer[$key]->answer = $answer;
|
||||
$this->answer[$key]->fraction = $fraction[$key];
|
||||
// $this->answer[$key]->fraction = $fraction[$key];
|
||||
$this->answer[$key]->tolerance = $tolerance[$key];
|
||||
$this->answer[$key]->tolerancetype = $tolerancetype[$key];
|
||||
$this->answer[$key]->correctanswerlength = $correctanswerlength[$key];
|
||||
@@ -551,18 +552,17 @@ class question_edit_calculatedsimple_form extends question_edit_form {
|
||||
if (count($answer)) {
|
||||
$key = 0;
|
||||
foreach ($answer as $answer){
|
||||
$default_values['answer['.$key.']'] = $answer->answer;
|
||||
$default_values['fraction['.$key.']'] = $answer->fraction;
|
||||
$default_values['answer['.$key.']'] = $answer->answer; // is necessary ? to-do test it
|
||||
$default_values['tolerance['.$key.']'] = $answer->tolerance;
|
||||
$default_values['tolerancetype['.$key.']'] = $answer->tolerancetype;
|
||||
$default_values['correctanswerlength['.$key.']'] = $answer->correctanswerlength;
|
||||
$default_values['correctanswerformat['.$key.']'] = $answer->correctanswerformat;
|
||||
$default_values['feedback['.$key.']'] = $answer->feedback;
|
||||
$key++;
|
||||
}
|
||||
}
|
||||
$default_values['synchronize'] = 0 ;
|
||||
if (isset($question->options)){
|
||||
$QTYPES['numerical']->set_numerical_unit_data($question,$default_values);
|
||||
/* if (isset($question->options)){
|
||||
$default_values['unitgradingtype'] = $question->options->unitgradingtype ;
|
||||
$default_values['unitpenalty'] = $question->options->unitpenalty ;
|
||||
switch ($question->options->showunits){
|
||||
@@ -590,6 +590,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
$key = 0 ;
|
||||
|
||||
$formdata = array();
|
||||
|
||||
Reference in New Issue
Block a user