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 range extends base |
13
|
|
|
{ |
14
|
|
|
/** @var \blitze\sitemaker\services\util */ |
15
|
|
|
protected $util; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Constructor |
19
|
|
|
* |
20
|
|
|
* @param \phpbb\language\language $language Language object |
21
|
|
|
* @param \phpbb\request\request_interface $request Request object |
22
|
|
|
* @param \blitze\sitemaker\services\template $ptemplate Sitemaker template object |
23
|
|
|
* @param \blitze\sitemaker\services\util $util Sitemaker utility object |
24
|
|
|
*/ |
25
|
11 |
|
public function __construct(\phpbb\language\language $language, \phpbb\request\request_interface $request, \blitze\sitemaker\services\template $ptemplate, \blitze\sitemaker\services\util $util) |
26
|
|
|
{ |
27
|
11 |
|
parent::__construct($language, $request, $ptemplate); |
28
|
|
|
|
29
|
11 |
|
$this->util = $util; |
30
|
11 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc |
34
|
|
|
*/ |
35
|
5 |
|
public function get_name() |
36
|
|
|
{ |
37
|
5 |
|
return 'range'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritdoc |
42
|
|
|
*/ |
43
|
9 |
|
public function get_default_props() |
44
|
|
|
{ |
45
|
|
|
return array( |
46
|
9 |
|
'type' => 'double', |
47
|
9 |
|
'theme' => 'skinFlat', |
48
|
9 |
|
'size' => 100, |
49
|
9 |
|
'values' => '', |
50
|
9 |
|
'prefix' => '', |
51
|
9 |
|
'postfix' => '', |
52
|
9 |
|
'min' => '', |
53
|
9 |
|
'max' => '', |
54
|
9 |
|
'step' => 1, |
55
|
9 |
|
'grid' => false, |
56
|
9 |
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritdoc |
61
|
|
|
*/ |
62
|
3 |
|
public function show_form_field($name, array &$data) |
63
|
|
|
{ |
64
|
3 |
|
$this->util->add_assets(array( |
65
|
|
|
'js' => array( |
66
|
3 |
|
'@blitze_content/vendor/ion.rangeSlider/js/ion.rangeSlider.min.js', |
67
|
3 |
|
'@blitze_content/assets/form/fields.min.js', |
68
|
3 |
|
), |
69
|
|
|
'css' => array( |
70
|
3 |
|
'@blitze_content/vendor/ion.rangeSlider/css/ion.rangeSlider.min.css', |
71
|
3 |
|
'@blitze_content/vendor/ion.rangeSlider/css/ion.rangeSlider.' . $data['field_props']['theme'] . '.min.css', |
72
|
|
|
) |
73
|
3 |
|
)); |
74
|
|
|
|
75
|
3 |
|
$this->set_range($data); |
76
|
|
|
|
77
|
3 |
|
return parent::show_form_field($name, $data); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @inheritdoc |
82
|
|
|
*/ |
83
|
5 |
|
public function display_field(array $data) |
84
|
|
|
{ |
85
|
5 |
|
$range = $this->get_range($data['field_value']); |
86
|
|
|
|
87
|
5 |
|
if (sizeof($range)) |
88
|
5 |
|
{ |
89
|
5 |
|
array_walk($range, array($this, 'set_prefix'), $data['field_props']['prefix']); |
90
|
5 |
|
} |
91
|
|
|
|
92
|
5 |
|
return join($range, ' - ') . $data['field_props']['postfix']; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $values |
|
|
|
|
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
8 |
|
protected function get_range($value) |
100
|
|
|
{ |
101
|
8 |
|
return explode(';', preg_replace('/;\s+/', ';', $value)); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param array $data |
106
|
|
|
* @return void |
107
|
|
|
*/ |
108
|
3 |
|
protected function set_range(array &$data) |
109
|
|
|
{ |
110
|
3 |
|
list($from, $to) = $this->get_range($data['field_value']); |
111
|
|
|
|
112
|
3 |
|
if ($data['field_props']['values']) |
113
|
3 |
|
{ |
114
|
1 |
|
$values = explode(',', preg_replace('/,\s+/', ',', $data['field_props']['values'])); |
115
|
|
|
|
116
|
1 |
|
$from = array_search($from, $values); |
117
|
1 |
|
$to = array_search($to, $values); |
118
|
|
|
|
119
|
1 |
|
$data['field_props']['from'] = $from; |
120
|
1 |
|
$data['field_props']['to'] = $to; |
121
|
1 |
|
} |
122
|
3 |
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param string $item |
126
|
|
|
* @param int $key |
127
|
|
|
* @param string $prefix |
128
|
|
|
* @return void |
129
|
|
|
*/ |
130
|
5 |
|
protected function set_prefix(&$item, $key, $prefix) |
131
|
|
|
{ |
132
|
5 |
|
$item = $prefix . $item; |
133
|
5 |
|
} |
134
|
|
|
} |
135
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.