1 <?php
2 3 4 5 6
7 class Int extends DBField {
8
9 public static $thousand_sep = ' ';
10 public static $decimal_sep = '';
11
12 function __construct($name, $defaultVal = 0) {
13 $this->defaultVal = is_int($defaultVal) ? $defaultVal : 0;
14
15 parent::__construct($name);
16 }
17
18 function Formatted() {
19 return number_format($this->value);
20 }
21
22 function nullValue() {
23 return "0";
24 }
25
26 function requireField() {
27 $parts=Array('datatype'=>'int', 'precision'=>11, 'null'=>'not null', 'default'=>$this->defaultVal, 'arrayValue'=>$this->arrayValue);
28 $values=Array('type'=>'int', 'parts'=>$parts);
29 DB::requireField($this->tableName, $this->name, $values);
30 }
31
32 function Times() {
33 $output = new DataObjectSet();
34 for( $i = 0; $i < $this->value; $i++ )
35 $output->push( new ArrayData( array( 'Number' => $i + 1 ) ) );
36
37 return $output;
38 }
39
40 function Nice() {
41 return number_format($this->value, 0, self::$decimal_sep, self::$thousand_sep);
42 }
43
44 public function scaffoldFormField($title = null, $params = null) {
45 return new NumericField($this->name, $title);
46 }
47
48 49 50 51
52 function prepValueForDB($value) {
53 if($value === true) {
54 return 1;
55 } if(!$value || !is_numeric($value)) {
56 if(strpos($value, '[')===false)
57 return '0';
58 else
59 return addslashes($value);
60 } else {
61 return addslashes($value);
62 }
63 }
64
65 }
66
67 ?>
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-