Skip to content

Commit

Permalink
fixed bug with empty or zero values for length and col variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Feb 22, 2013
1 parent d441327 commit 77c775e
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/MadeYourDay/Contao/ThemeAssistant.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,22 @@ public function onloadCallback(\DataContainer $dc)
'mm' => 'mm',
);
if ($field['value']) {
preg_match('(^([.0-9]+)([^.0-9]*))i', $field['value'], $matches);
$field['value'] = array(
'value' => $matches[1],
'unit' => $matches[2],
);
if (preg_match('(^([.0-9]+)([^.0-9]*))i', $field['value'], $matches) && isset($field['options'][$matches[2]])) {
$field['value'] = array(
'value' => $matches[1],
'unit' => $matches[2],
);
}
else {
$field['value'] = array(
'value' => $field['value'],
'unit' => '',
);
}
}
else {
$field['value'] = array(
'value' => '',
'value' => '0',
'unit' => '',
);
}
Expand Down Expand Up @@ -431,10 +438,10 @@ public function onsubmitCallback(\DataContainer $dc)
}
elseif ($data['templateVars'][$key]['type'] === 'length') {
if ($value && isset($value['value']) && isset($value['unit'])) {
$value = $value['value'] . $value['unit'];
$value = (trim($value['value']) ? trim($value['value']) : '0') . trim($value['unit']);
}
else {
$value = '';
if (! $value) {
$value = '0';
}
}
elseif ($data['templateVars'][$key]['type'] === 'set') {
Expand Down Expand Up @@ -651,7 +658,7 @@ protected function executeColorFunction($function, $data)
}
elseif ($function['function'] === 'col') {

return trim(trim(number_format($function['params'][0]/$function['params'][1]*100, 3, '.', ''), '0'), '.') . '%';
return rtrim(rtrim(number_format($function['params'][0] / $function['params'][1] * 100, 5, '.', ''), '0'), '.') . '%';

}
}
Expand Down

0 comments on commit 77c775e

Please sign in to comment.