Skip to content

Commit

Permalink
MDL-30167 qtype_numerical: notice when required unit is not in the an…
Browse files Browse the repository at this point in the history
…swer.
  • Loading branch information
timhunt committed Nov 15, 2011
1 parent e25ecdf commit 4493fe9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions question/type/numerical/questiontype.php
Expand Up @@ -641,16 +641,17 @@ public function apply_units($response, $separateunit = null) {

$numberstring = $matches[0];
if ($this->unitsbefore) {
$unit = substr($response, 0, -strlen($numberstring));
// substr returns false when it means '', so cast back to string.
$unit = (string) substr($response, 0, -strlen($numberstring));
} else {
$unit = substr($response, strlen($numberstring));
$unit = (string) substr($response, strlen($numberstring));
}

if (!is_null($separateunit)) {
$unit = $separateunit;
}

if ($unit && $this->is_known_unit($unit)) {
if ($this->is_known_unit($unit)) {
$multiplier = 1 / $this->units[$unit];
} else {
$multiplier = null;
Expand Down

0 comments on commit 4493fe9

Please sign in to comment.