Permalink
Browse files

[MDL-14771] Backend code to allow a "number" field to be displayed wi…

…th a specified number of decimal digits. Merged from MOODLE_19_STABLE.
  • Loading branch information...
1 parent ecc11af commit a84f7fddec856fe22cb0ef65030eb0a3b7fbed38 robertall committed May 29, 2008
Showing with 18 additions and 3 deletions.
  1. +18 −3 mod/data/field/number/field.class.php
@@ -40,15 +40,31 @@ function update_content($recordid, $value, $name='') {
} else {
$content->content = null;
}
-
if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
$content->id = $oldcontent->id;
return update_record('data_content', $content);
} else {
return insert_record('data_content', $content);
}
}
-
+
+ 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 = '') {
return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';
}
@@ -64,7 +80,6 @@ function generate_sql($tablealias, $value) {
function get_sort_sql($fieldname) {
global $CFG;
-
switch ($CFG->dbfamily) {
case 'mysql': // string in an arithmetic operation is converted to a floating-point number
return '('.$fieldname.'+0.0)';

0 comments on commit a84f7fd

Please sign in to comment.