MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / mod / data / field / number / field.class.php
blob073a091ad6b68579af3e487d8d69da941eb4b493
1 <?php // $Id$
2 ///////////////////////////////////////////////////////////////////////////
3 // //
4 // NOTICE OF COPYRIGHT //
5 // //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.org //
8 // //
9 // Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
10 // //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation; either version 2 of the License, or //
14 // (at your option) any later version. //
15 // //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License for more details: //
20 // //
21 // http://www.gnu.org/copyleft/gpl.html //
22 // //
23 ///////////////////////////////////////////////////////////////////////////
25 class data_field_number extends data_field_base {
27 var $type = 'number';
29 function data_field_number($field=0, $data=0) {
30 parent::data_field_base($field, $data);
33 function update_content($recordid, $value, $name='') {
34 $content = new object;
35 $content->fieldid = $this->field->id;
36 $content->recordid = $recordid;
37 $content->content = (float)$value;
39 if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
40 $content->id = $oldcontent->id;
41 return update_record('data_content', $content);
42 } else {
43 return insert_record('data_content', $content);
47 function display_search_field($value = '') {
48 return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';
51 function parse_search_field() {
52 return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
55 // need to cast?
56 function generate_sql($tablealias, $value) {
57 return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$value') ";
60 function get_sort_sql($fieldname) {
61 global $CFG;
63 switch ($CFG->dbfamily) {
64 case 'mysql': // string in an arithmetic operation is converted to a floating-point number
65 return '('.$fieldname.'+0.0)';
66 case 'postgres': // cast for PG
67 return 'CAST('.$fieldname.' AS REAL)';
68 default: // the rest, just the field name. TODO: Analyse behaviour under MSSQL and Oracle
69 return $fieldname;