[MDL-14771] Backend code to allow a "number" field to be displayed with a specified number of decimal digits. Merged from MOODLE_19_STABLE.

This commit is contained in:
robertall 2008-05-29 19:17:46 +00:00
parent ecc11af02f
commit a84f7fddec

View File

@ -40,7 +40,6 @@ class data_field_number extends data_field_base {
} else { } else {
$content->content = null; $content->content = null;
} }
if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) { if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
$content->id = $oldcontent->id; $content->id = $oldcontent->id;
return update_record('data_content', $content); return update_record('data_content', $content);
@ -49,6 +48,23 @@ class data_field_number extends data_field_base {
} }
} }
function display_browse_field($recordid, $template) {
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
if (strlen($content->content) < 1) {
return false;
}
$number = $content->content;
$decimals = intval($this->field->param1);
if (isset($decimals) && is_int($decimals) && $decimals >= 0) {
$str = number_format($number, $decimals, '.', '');
} else {
$str = $number;
}
return $str;
}
return false;
}
function display_search_field($value = '') { function display_search_field($value = '') {
return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />'; return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';
} }
@ -64,7 +80,6 @@ class data_field_number extends data_field_base {
function get_sort_sql($fieldname) { function get_sort_sql($fieldname) {
global $CFG; global $CFG;
switch ($CFG->dbfamily) { switch ($CFG->dbfamily) {
case 'mysql': // string in an arithmetic operation is converted to a floating-point number case 'mysql': // string in an arithmetic operation is converted to a floating-point number
return '('.$fieldname.'+0.0)'; return '('.$fieldname.'+0.0)';