|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* @package sitemaker |
|
5
|
|
|
* @copyright (c) 2013 Daniel A. (blitze) |
|
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace blitze\content\services\form\field; |
|
11
|
|
|
|
|
12
|
|
|
class number extends base |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @inheritdoc |
|
16
|
|
|
*/ |
|
17
|
3 |
|
public function get_name() |
|
18
|
|
|
{ |
|
19
|
3 |
|
return 'number'; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @inheritdoc |
|
24
|
|
|
*/ |
|
25
|
4 |
|
public function get_default_props() |
|
26
|
|
|
{ |
|
27
|
|
|
return array( |
|
28
|
4 |
|
'min' => 0, |
|
29
|
4 |
|
'max' => 0, |
|
30
|
4 |
|
'step' => 1, |
|
31
|
4 |
|
'size' => 10, |
|
32
|
4 |
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritdoc |
|
37
|
|
|
*/ |
|
38
|
10 |
|
public function get_validation_rules(array $data) |
|
39
|
|
|
{ |
|
40
|
10 |
|
$filter = FILTER_VALIDATE_INT; |
|
41
|
|
|
$sanitize = FILTER_SANITIZE_NUMBER_INT; |
|
42
|
|
|
|
|
43
|
|
|
if (is_float($data['field_props']['step'])) |
|
44
|
|
|
{ |
|
45
|
|
|
$filter = FILTER_VALIDATE_FLOAT; |
|
46
|
|
|
$sanitize = FILTER_SANITIZE_NUMBER_FLOAT; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return array( |
|
50
|
|
|
'filter' => $filter, |
|
51
|
|
|
'sanitize' => $sanitize, |
|
52
|
|
|
'options' => array( |
|
53
|
|
|
'options' => array_filter(array( |
|
54
|
|
|
'min_range' => $data['field_props']['min'], |
|
55
|
|
|
'max_range' => $data['field_props']['max'], |
|
56
|
|
|
'decimal' => '.', |
|
57
|
|
|
)), |
|
58
|
|
|
'flags' => FILTER_FLAG_ALLOW_THOUSAND, |
|
59
|
|
|
), |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @inheritdoc |
|
65
|
|
|
*/ |
|
66
|
|
|
public function get_error_message(array $data) |
|
67
|
|
|
{ |
|
68
|
|
|
$props = $data['field_props']; |
|
69
|
|
|
$lang_keys = array('FIELD_INVALID'); |
|
70
|
|
|
|
|
71
|
|
|
$lang_keys[] = ($props['min']) ? 'MIN' : ''; |
|
72
|
|
|
$lang_keys[] = ($props['max']) ? 'MAX' : ''; |
|
73
|
|
|
|
|
74
|
|
|
return $this->language->lang(join('_', array_filter($lang_keys)), $data['field_label'], $props['min'], $props['max']); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @inheritdoc |
|
79
|
|
|
* @return int |
|
80
|
|
|
*/ |
|
81
|
|
|
public function get_field_value(array $data) |
|
82
|
|
|
{ |
|
83
|
|
|
return $data['field_value'] ? (int) $data['field_value'] : ''; |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @inheritdoc |
|
88
|
|
|
* @return int |
|
89
|
|
|
*/ |
|
90
|
|
|
public function get_submitted_value(array $data) |
|
91
|
|
|
{ |
|
92
|
|
|
$value = $this->get_field_value($data); |
|
93
|
|
|
return $this->request->variable($data['field_name'], $value); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|