From bbfda34377f32ef7e20f274b0df408fe305d7129 Mon Sep 17 00:00:00 2001 From: Pierre Pichet Date: Fri, 21 May 2010 01:18:35 +0000 Subject: [PATCH] MDL-20296 creating common functions to handle units in numerical, calculated and calculatedsimple edit forms --- .../type/calculated/edit_calculated_form.php | 48 +------------------ .../edit_calculatedsimple_form.php | 11 +++-- 2 files changed, 7 insertions(+), 52 deletions(-) diff --git a/question/type/calculated/edit_calculated_form.php b/question/type/calculated/edit_calculated_form.php index a83eab84330..16abb4a580c 100644 --- a/question/type/calculated/edit_calculated_form.php +++ b/question/type/calculated/edit_calculated_form.php @@ -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'); } diff --git a/question/type/calculatedsimple/edit_calculatedsimple_form.php b/question/type/calculatedsimple/edit_calculatedsimple_form.php index 59e8248a32a..5e2307f13f9 100644 --- a/question/type/calculatedsimple/edit_calculatedsimple_form.php +++ b/question/type/calculatedsimple/edit_calculatedsimple_form.php @@ -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();