Skip to content

Commit

Permalink
[MDL-14771] Backend code to allow a "number" field to be displayed wi…
Browse files Browse the repository at this point in the history
…th a specified number of decimal digits. Merged from MOODLE_19_STABLE.
  • Loading branch information
robertall committed May 29, 2008
1 parent ecc11af commit a84f7fd
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions mod/data/field/number/field.class.php
Expand Up @@ -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.'" />';
}
Expand All @@ -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)';
Expand Down

0 comments on commit a84f7fd

Please sign in to comment.