mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
MDL-27418 add validation to stop students intering a thosands sep.
If it might be confused by a decimal point from another locale.
This commit is contained in:
parent
1a1353a5ce
commit
f040d4b046
3 changed files with 23 additions and 0 deletions
|
@ -64,6 +64,7 @@ $string['nominal'] = 'Nominal';
|
|||
$string['onlynumerical'] = 'Units are not used at all. Only the numerical value is graded.';
|
||||
$string['oneunitshown'] = 'Unit 1 is automatically displayed beside the answer box.';
|
||||
$string['pleaseenterananswer'] = 'Please enter an answer.';
|
||||
$string['pleaseenteranswerwithoutthousandssep'] = 'Please enter your answer without using the thousand separator ({$a}).';
|
||||
$string['relative'] = 'Relative';
|
||||
$string['rightexample'] = 'on the right, for example 1.00cm or 1.00km';
|
||||
$string['selectunits'] = 'Select units';
|
||||
|
|
|
@ -109,6 +109,10 @@ class qtype_numerical_question extends question_graded_automatically {
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($this->ap->contains_thousands_seaparator($response['answer'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -130,6 +134,11 @@ class qtype_numerical_question extends question_graded_automatically {
|
|||
return get_string('unitnotselected', 'qtype_numerical');
|
||||
}
|
||||
|
||||
if ($this->ap->contains_thousands_seaparator($response['answer'])) {
|
||||
return get_string('pleaseenteranswerwithoutthousandssep', 'qtype_numerical',
|
||||
$this->ap->get_separator());
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
|
@ -524,6 +524,19 @@ class qtype_numerical_answer_processor {
|
|||
return $this->thousandssep;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return book If the student's response contains a '.' or a ',' that
|
||||
* matches the thousands separator in the current locale. In this case, the
|
||||
* parsing in apply_unit can give a result that the student did not expect.
|
||||
*/
|
||||
public function contains_thousands_seaparator($value) {
|
||||
if (!in_array($this->thousandssep, array('.', ','))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strpos($value, $this->thousandssep) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the regular expression that {@link parse_response()} requires.
|
||||
* @return string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue