-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathNumber.php
More file actions
107 lines (93 loc) · 2.41 KB
/
Copy pathNumber.php
File metadata and controls
107 lines (93 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace ModStart\Field;
use ModStart\Core\Exception\BizException;
class Number extends AbstractField
{
protected function setup()
{
$this->addVariables([
// 自动着色,正数绿色,负数红色
'autoColor' => false,
// 是否显示符号
'signShow' => false,
// 单位
'unit' => null,
// 最小值
'min' => null,
// 最大值
'max' => null,
// stepping interval
'step' => null,
]);
}
public function min($value)
{
$this->setVariable('min', $value);
return $this;
}
public function max($value)
{
$this->setVariable('max', $value);
return $this;
}
public function step($value)
{
$this->setVariable('step', $value);
return $this;
}
public function autoColor($enable)
{
$this->setVariable('autoColor', $enable);
return $this;
}
public function signShow($enable)
{
$this->setVariable('signShow', $enable);
return $this;
}
public function unit($value)
{
$this->setVariable('unit', $value);
return $this;
}
public function unserializeValue($value, AbstractField $field)
{
if ('' === $value || null === $value) {
return null;
}
return intval($value);
}
public function serializeValue($value, $model)
{
if ('' === $value || null === $value) {
return null;
}
return intval($value);
}
public function prepareInput($value, $model)
{
if ('' === $value || null === $value) {
return null;
}
$value = intval($value);
if (null !== ($v = $this->getVariable('min'))) {
if ($value < $v) {
BizException::throws(str_replace([
':attribute', ':min'
], [
$this->label, $v
], L('validation.min.numeric')));
}
}
if (null !== ($v = $this->getVariable('max'))) {
if ($value > $v) {
BizException::throws(str_replace([
':attribute', ':max'
], [
$this->label, $v
], L('validation.max.numeric')));
}
}
return $value;
}
}