mirror of
https://github.com/moodle/moodle.git
synced 2025-03-07 01:10:02 +01:00
MDL-20636 qtype_numerical Fix a bunch of minor issues found by Pierre.
This commit is contained in:
parent
5d2465c3f4
commit
ae3e2e6e7f
@ -120,7 +120,7 @@ function xmldb_qtype_numerical_upgrade($oldversion) {
|
||||
qnu.unit AS defaultunit
|
||||
|
||||
FROM {question} q
|
||||
FROM {question_categories} qc ON qc.id = q.category
|
||||
JOIN {question_categories} qc ON qc.id = q.category
|
||||
JOIN {question_numerical_options} qno ON qno.question = q.id
|
||||
JOIN {question_numerical_units} qnu ON qnu.id = (
|
||||
SELECT min(id)
|
||||
|
@ -76,6 +76,7 @@ $string['unitchoice'] = 'a multiple choice selection';
|
||||
$string['unitedit'] = 'Edit unit';
|
||||
$string['unitgraded'] = 'The unit must be given, and will be graded.';
|
||||
$string['unithdr'] = 'Unit {$a}';
|
||||
$string['unitincorrect'] = 'You did not give the correct unit.';
|
||||
$string['unitmandatory'] = 'Mandatory';
|
||||
$string['unitmandatory_help'] = '
|
||||
|
||||
@ -92,7 +93,6 @@ $string['unitoptional_help'] = '
|
||||
* If the unit is badly written or unknown, the response will be considered as non valid.
|
||||
';
|
||||
$string['unitnotvalid'] = ' Unit not valid with this numerical value';
|
||||
$string['unitunknown'] = ' Undefined unit ';
|
||||
$string['unitpenalty'] = 'Unit penalty';
|
||||
$string['unitpenalty_help'] = 'The penalty is applied if
|
||||
|
||||
|
@ -155,7 +155,7 @@ class qtype_numerical_question extends question_graded_automatically {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function apply_unit_penalty($fraction, $unit) {
|
||||
public function apply_unit_penalty($fraction, $unit) {
|
||||
if (!empty($unit) && $this->ap->is_known_unit($unit)) {
|
||||
return $fraction;
|
||||
}
|
||||
|
@ -363,16 +363,16 @@ class qtype_numerical extends question_type {
|
||||
}
|
||||
|
||||
protected function make_answer_processor($units, $unitsleft) {
|
||||
if (empty($questiondata->options->units)) {
|
||||
if (empty($units)) {
|
||||
return new qtype_numerical_answer_processor(array());
|
||||
}
|
||||
|
||||
$units = array();
|
||||
foreach ($questiondata->options->units as $unit) {
|
||||
$units[$unit->unit] = $unit->multiplier;
|
||||
$cleanedunits = array();
|
||||
foreach ($units as $unit) {
|
||||
$cleanedunits[$unit->unit] = $unit->multiplier;
|
||||
}
|
||||
|
||||
return new qtype_numerical_answer_processor($units, $questiondata->options->unitsleft);
|
||||
return new qtype_numerical_answer_processor($cleanedunits, $unitsleft);
|
||||
}
|
||||
|
||||
function delete_question($questionid, $contextid) {
|
||||
|
@ -56,7 +56,7 @@ class qtype_numerical_renderer extends qtype_renderer {
|
||||
list($value, $unit) = $question->ap->apply_units($currentanswer);
|
||||
$answer = $question->get_matching_answer($value);
|
||||
if ($answer) {
|
||||
$fraction = $answer->fraction;
|
||||
$fraction = $question->apply_unit_penalty($answer->fraction, $unit);
|
||||
} else {
|
||||
$fraction = 0;
|
||||
}
|
||||
@ -101,12 +101,19 @@ class qtype_numerical_renderer extends qtype_renderer {
|
||||
|
||||
list($value, $unit) = $question->ap->apply_units($qa->get_last_qt_var('answer'));
|
||||
$answer = $question->get_matching_answer($value);
|
||||
if (!$answer || !$answer->feedback) {
|
||||
return '';
|
||||
|
||||
if ($answer && $answer->feedback) {
|
||||
$feedback = $question->format_text($answer->feedback, $answer->feedbackformat,
|
||||
$qa, 'question', 'answerfeedback', $answer->id);
|
||||
} else {
|
||||
$feedback = '';
|
||||
}
|
||||
|
||||
return $question->format_text($answer->feedback, $answer->feedbackformat,
|
||||
$qa, 'question', 'answerfeedback', $answer->id);
|
||||
if ($question->unitgradingtype && !$question->ap->is_known_unit($unit)) {
|
||||
$feedback .= html_writer::tag('p', get_string('unitincorrect', 'qtype_numerical'));
|
||||
}
|
||||
|
||||
return $feedback;
|
||||
}
|
||||
|
||||
public function correct_response(question_attempt $qa) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user