1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @company MTE Telecom, Ltd. |
4
|
|
|
* @author Ushkov Nikolai <[email protected]> |
5
|
|
|
* Date: 18.04.16 |
6
|
|
|
* Time: 17:16 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Nnx\DataGrid\Button; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class AbstractButton |
13
|
|
|
* @package Nnx\DataGrid\Button |
14
|
|
|
*/ |
15
|
|
|
abstract class AbstractButton implements ButtonInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Наименование кнопки. |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $name; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* url кнопки |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $url; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Заголовок кнопки |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $title; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* JS код кнопки |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $js; |
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* JS библиотеки кнопки |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
protected $libJs = []; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Опции кнопки |
49
|
|
|
* @var array | \Traversable |
50
|
|
|
*/ |
51
|
|
|
protected $options = []; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Атрибуты кнопки |
55
|
|
|
* @var array | \Traversable |
56
|
|
|
*/ |
57
|
|
|
protected $attributes = []; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* По данному полю осуществляется сортировка кнопок при выводе |
61
|
|
|
* @var int |
62
|
|
|
*/ |
63
|
|
|
protected $order = 0; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Устанавливает свойства класса |
67
|
|
|
* @param string $key |
68
|
|
|
* @param array $options |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
protected function setProperty($key, &$options) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
if (array_key_exists($key, $options)) { |
73
|
|
|
$setter = 'set' . ucfirst($key); |
74
|
|
|
if (method_exists($this, $setter)) { |
75
|
|
|
$this->$setter($options[$key]); |
76
|
|
|
unset($options[$key]); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param $options |
83
|
|
|
*/ |
84
|
|
|
public function __construct($options) |
85
|
|
|
{ |
86
|
|
|
unset($options['type']); |
87
|
|
|
if (!empty($options['attributes']) && $this->getAttributes()) { |
88
|
|
|
$this->setAttributes(array_merge($this->getAttributes(), $options['attributes'])); |
89
|
|
|
unset($options['attributes']); |
90
|
|
|
} |
91
|
|
|
foreach ($options as $key => $option) { |
92
|
|
|
$this->setProperty($key, $options); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Получить Наименование кнопки |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function getName() |
102
|
|
|
{ |
103
|
|
|
return $this->name; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Установить Наименование кнопки |
108
|
|
|
* @param string $name |
109
|
|
|
* @return $this |
110
|
|
|
*/ |
111
|
|
|
public function setName($name) |
112
|
|
|
{ |
113
|
|
|
$this->name = $name; |
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Получить url кнопки |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
|
|
public function getUrl() |
122
|
|
|
{ |
123
|
|
|
return $this->url; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Установить url кнопки |
128
|
|
|
* @param string $url |
129
|
|
|
* @return $this |
130
|
|
|
*/ |
131
|
|
|
public function setUrl($url) |
132
|
|
|
{ |
133
|
|
|
$this->url = $url; |
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Получить Заголовок кнопки |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
|
|
public function getTitle() |
142
|
|
|
{ |
143
|
|
|
return $this->title; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Установить Заголовок кнопки |
148
|
|
|
* @param string $title |
149
|
|
|
* @return $this |
150
|
|
|
*/ |
151
|
|
|
public function setTitle($title) |
152
|
|
|
{ |
153
|
|
|
$this->title = $title; |
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Получить JS код кнопки |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
|
|
public function getJs() |
162
|
|
|
{ |
163
|
|
|
return $this->js; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Установить JS код кнопки |
168
|
|
|
* @param string $js |
169
|
|
|
* @return $this |
170
|
|
|
*/ |
171
|
|
|
public function setJs($js) |
|
|
|
|
172
|
|
|
{ |
173
|
|
|
$this->js = $js; |
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Получить JS библитеки кнопки |
179
|
|
|
* @return array |
180
|
|
|
*/ |
181
|
|
|
public function getLibJs() |
182
|
|
|
{ |
183
|
|
|
return $this->libJs; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Установить JS библитеки кнопки |
188
|
|
|
* @param array $libJs |
189
|
|
|
* @return $this |
190
|
|
|
*/ |
191
|
|
|
public function setLibJs($libJs) |
192
|
|
|
{ |
193
|
|
|
$this->libJs = $libJs; |
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Получить Опции кнопки |
201
|
|
|
* @return array|\Traversable |
202
|
|
|
*/ |
203
|
|
|
public function getOptions() |
204
|
|
|
{ |
205
|
|
|
return $this->options; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Установить Опции кнопки |
210
|
|
|
* @param array|\Traversable $options |
211
|
|
|
* @return $this |
212
|
|
|
*/ |
213
|
|
|
public function setOptions($options) |
214
|
|
|
{ |
215
|
|
|
$this->options = $options; |
|
|
|
|
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Возвращает атрибут кнопки |
221
|
|
|
* @param $name |
222
|
|
|
* @return mixed|null |
223
|
|
|
*/ |
224
|
|
|
public function getAttribute($name) |
225
|
|
|
{ |
226
|
|
|
if (isset($this->attributes[$name])) { |
227
|
|
|
return $this->attributes[$name]; |
228
|
|
|
} |
229
|
|
|
return null; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Получить Атрибуты кнопки |
234
|
|
|
* @return array|\Traversable |
235
|
|
|
*/ |
236
|
|
|
public function getAttributes() |
237
|
|
|
{ |
238
|
|
|
return $this->attributes; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Установить Аттрибут кнопки |
243
|
|
|
* @param string $name |
244
|
|
|
* @param mixed $value |
245
|
|
|
* @return $this |
246
|
|
|
*/ |
247
|
|
|
public function setAttribute($name, $value) |
248
|
|
|
{ |
249
|
|
|
$this->attributes[$name] = $value; |
250
|
|
|
return $this; |
251
|
|
|
} |
252
|
|
|
/** |
253
|
|
|
* Установить Атрибуты кнопки |
254
|
|
|
* @param array|\Traversable $attributes |
255
|
|
|
* @return $this |
256
|
|
|
*/ |
257
|
|
|
public function setAttributes($attributes) |
258
|
|
|
{ |
259
|
|
|
$this->attributes = $attributes; |
|
|
|
|
260
|
|
|
return $this; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Получить Значение сортировки |
265
|
|
|
* @return int |
266
|
|
|
*/ |
267
|
|
|
public function getOrder() |
268
|
|
|
{ |
269
|
|
|
return $this->order; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Установить Значение сортировки |
274
|
|
|
* @param int $order |
275
|
|
|
* @return $this |
276
|
|
|
*/ |
277
|
|
|
public function setOrder($order) |
278
|
|
|
{ |
279
|
|
|
$this->order = $order; |
280
|
|
|
return $this; |
281
|
|
|
} |
282
|
|
|
} |
|
|
|
|
283
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.