Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
field.php
1<?php
2namespace Bitrix\Main\Filter;
3
4class Field
5{
7 protected $dataProvider = null;
9 protected $id = '';
11 protected $name = '';
13 protected $type = '';
15 protected $isDefault = false;
17 protected $data = null;
19 protected $isPartial = false;
21 protected $sectionId = '';
22 protected $iconParams = [];
23
24 public function __construct(DataProvider $dataProvider, $id, array $params = null)
25 {
26 $this->dataProvider = $dataProvider;
27 $this->id = $id;
28
29 if(!is_array($params))
30 {
31 $params = [];
32 }
33
34 $this->name = $params['name'] ?? $id;
35 $this->type = $params['type'] ?? '';
36 $this->isDefault = $params['default'] ?? false;
37
38 $this->isPartial = $params['partial'] ?? false;
39 $this->data = $params['data'] ?? null;
40 }
41
46 public function getDataProvider()
47 {
49 }
50
56 {
57 $this->dataProvider = $dataProvider;
58 }
63 protected function prepareData()
64 {
65 return $this->dataProvider->prepareFieldData($this->id);
66 }
71 public function prepareHtml()
72 {
73 return $this->dataProvider->prepareFieldHtml($this);
74 }
79 public function getId()
80 {
81 return $this->id;
82 }
87 public function setID($id)
88 {
89 $this->id = $id;
90 }
95 public function getName()
96 {
97 return $this->name;
98 }
103 public function setName($name)
104 {
105 $this->name = $name;
106 }
111 public function getType()
112 {
113 return $this->type;
114 }
119 public function setType($type)
120 {
121 $this->type = $type;
122 }
127 public function isDefault()
128 {
129 return $this->isDefault;
130 }
135 public function markAsDefault($isDefault)
136 {
137 $this->isDefault = $isDefault;
138 }
145 public function isPartial()
146 {
147 return $this->isPartial;
148 }
153 public function getData()
154 {
155 return $this->data;
156 }
162 public function getDataItem($key)
163 {
164 return $this->data !== null && isset($this->data[$key]) ? $this->data[$key] : null;
165 }
166
171 public function getSectionId(): string
172 {
173 return $this->sectionId;
174 }
175
180 public function setSectionId(string $sectionId): void
181 {
182 $this->sectionId = $sectionId;
183 }
188 public function getIconParams(): array
189 {
190 return $this->iconParams;
191 }
192
197 public function setIconParams(array $iconParams): void
198 {
199 $this->iconParams = $iconParams;
200 }
201
207 public function assemble()
208 {
209 if(!$this->isPartial)
210 {
211 return;
212 }
213
214 $this->data = $this->prepareData();
215 $this->isPartial = false;
216
217 if(is_array($this->data))
218 {
219 $html = $this->prepareHtml();
220 if($html !== '')
221 {
222 $this->data['html'] = $html;
223 }
224 }
225 }
231 public function toArray(array $options = null)
232 {
233 if(!is_array($options))
234 {
235 $options = [];
236 }
237
238 $result = [ 'id' => $this->id, 'name' => $this->name ];
239 if($this->type !== '')
240 {
241 $result['type'] = $this->type;
242 }
243
244 if($this->isDefault)
245 {
246 $result['default'] = true;
247 }
248
249 if ($this->sectionId !== '')
250 {
251 $result['sectionId'] = $this->sectionId;
252 }
253 if (!empty($this->iconParams))
254 {
255 $result['icon'] = $this->iconParams;
256 }
257
258 if(isset($options['lightweight']) && $options['lightweight'])
259 {
260 $result['lightweight'] = true;
261 return $result;
262 }
263
264 if($this->isPartial())
265 {
266 $this->assemble();
267 }
268
269 if(is_array($this->data))
270 {
271 foreach($this->data as $key => $data)
272 {
273 $result[$key] = $data;
274 }
275 }
276
277 return $result;
278 }
279}
setDataProvider(DataProvider $dataProvider)
Definition field.php:55
__construct(DataProvider $dataProvider, $id, array $params=null)
Definition field.php:24
markAsDefault($isDefault)
Definition field.php:135
setIconParams(array $iconParams)
Definition field.php:197
setSectionId(string $sectionId)
Definition field.php:180
toArray(array $options=null)
Definition field.php:231