1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Represents a signed 32 bit integer field. |
4
|
|
|
* |
5
|
|
|
* @package framework |
6
|
|
|
* @subpackage model |
7
|
|
|
*/ |
8
|
|
|
class Int extends DBField { |
9
|
|
|
|
10
|
|
|
public function __construct($name = null, $defaultVal = 0) { |
11
|
|
|
$this->defaultVal = is_int($defaultVal) ? $defaultVal : 0; |
12
|
|
|
|
13
|
|
|
parent::__construct($name); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Returns the number, with commas added as appropriate, eg “1,000”. |
18
|
|
|
*/ |
19
|
|
|
public function Formatted() { |
20
|
|
|
return number_format($this->value); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function requireField() { |
24
|
|
|
$parts=Array( |
25
|
|
|
'datatype'=>'int', |
26
|
|
|
'precision'=>11, |
27
|
|
|
'null'=>'not null', |
28
|
|
|
'default'=>$this->defaultVal, |
29
|
|
|
'arrayValue'=>$this->arrayValue); |
30
|
|
|
|
31
|
|
|
$values=Array('type'=>'int', 'parts'=>$parts); |
32
|
|
|
DB::require_field($this->tableName, $this->name, $values); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function Times() { |
36
|
|
|
$output = new ArrayList(); |
37
|
|
|
for( $i = 0; $i < $this->value; $i++ ) |
38
|
|
|
$output->push( new ArrayData( array( 'Number' => $i + 1 ) ) ); |
39
|
|
|
|
40
|
|
|
return $output; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function Nice() { |
44
|
|
|
return sprintf( '%d', $this->value ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function scaffoldFormField($title = null, $params = null) { |
|
|
|
|
48
|
|
|
return new NumericField($this->name, $title); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function nullValue() { |
52
|
|
|
return 0; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function prepValueForDB($value) { |
56
|
|
|
if($value === true) { |
57
|
|
|
return 1; |
58
|
|
|
} elseif(empty($value) || !is_numeric($value)) { |
59
|
|
|
return 0; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $value; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.