Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
base.php
1<?php
3
4use Bitrix\Main\Page\Asset;
6
11abstract class Base
12{
13 const FIELDS_COMPONENT_NAME = 'bitrix:report.visualconstructor.config.fields';
14
15 private $key;
16 private $classList = array();
17 private $dataAttributes = array();
18 private $id;
19 private $label = '';
20 private $isDisplayLabel = true;
21 private $prefix;
22 private $postfix;
23 private $weight = 0;
24 private $assets = array();
25 private $js = array();
26 private $css = array();
27 private $inline = array();
28 private $jsEvents = array();
29 private $jsEventListeners = array();
30 private $form;
31 private $compatibleViewTypes;
32 private $inlineStyle;
33 private $display = true;
34
38 public static function getClassName()
39 {
40 return get_called_class();
41 }
42
46 public function getPrefix()
47 {
48 return $this->prefix;
49 }
50
57 public function setPrefix($prefix)
58 {
59 if (is_string($prefix))
60 {
61 $prefix = new Html($prefix);
62 }
63 $this->prefix = $prefix;
64 }
65
69 public function getPostfix()
70 {
71 return $this->postfix;
72 }
73
80 public function setPostfix($postfix)
81 {
82 if (is_string($postfix))
83 {
84 $postfix = new Html($postfix);
85 }
86 $this->postfix = $postfix;
87 }
88
92 public function getAssets()
93 {
94 return $this->assets;
95 }
96
103 public function addAssets($assets)
104 {
105 foreach ($assets as $key => $assetList)
106 {
107 switch ($key)
108 {
109 case 'js':
110 $this->js = array_merge($this->js, $assetList);
111 break;
112 case 'css':
113 $this->css = array_merge($this->css, $assetList);
114 break;
115 case 'inline':
116 $this->inline = array_merge($this->inline, $assetList);
117 }
118 }
119 $this->assets = $assets;
120 }
121
125 public function getForm()
126 {
127 return $this->form;
128 }
129
136 public function setForm($form)
137 {
138 $this->form = $form;
139 }
140
147 public function render()
148 {
149 if (!$this->isDisplay())
150 {
151 return;
152 }
153
154 foreach ($this->js as $jsPath)
155 {
156 Asset::getInstance()->addJs($jsPath);
157 }
158
159 foreach ($this->css as $cssPath)
160 {
161 Asset::getInstance()->addCss($cssPath);
162 }
163
164 foreach ($this->inline as $inline)
165 {
166 //TODO
167 Asset::getInstance()->addString($inline);
168 }
169
170 if ($this->getPrefix())
171 {
172 $this->getPrefix()->render();
173 }
174
175 $this->printContent();
176
177 if ($this->getPostfix())
178 {
179 $this->getPostfix()->render();
180 }
181
182 }
183
189 abstract public function printContent();
190
194 public function getJsEventListeners()
195 {
196 return $this->jsEventListeners;
197 }
198
202 public function getJsEvents()
203 {
204 return $this->jsEvents;
205 }
206
215 public function addJsEventListener(Base $field = null, $eventKey, $jsParams)
216 {
217 $field->jsEvents[$eventKey][] = array(
218 'behaviourOwner' => $this,
219 'handlerParams' => $jsParams
220 );
221
222 $this->jsEventListeners[$eventKey][] = array(
223 'eventOwner' => $field,
224 'handlerParams' => $jsParams,
225 );
226 return $this;
227 }
228
232 public function getLabel()
233 {
234 return $this->label;
235 }
236
243 public function setLabel($label)
244 {
245 $this->label = $label;
246 }
247
248
252 public function getCompatibleViewTypes()
253 {
254 return $this->compatibleViewTypes;
255 }
256
263 public function setCompatibleViewTypes($compatibleViewTypes)
264 {
265 $this->compatibleViewTypes = $compatibleViewTypes;
266 }
267
271 public function getId()
272 {
273 return $this->id;
274 }
275
282 public function setId($id)
283 {
284 $this->id = $id;
285 }
286
290 public function getWeight()
291 {
292 return $this->weight;
293 }
294
301 public function setWeight($weight)
302 {
303 $this->weight = $weight;
304 }
305
306
313 public function addClass($class)
314 {
315 $this->classList[] = $class;
316 }
317
321 public function getClasses()
322 {
323 return $this->classList;
324 }
325
332 public function getDataAttribute($key)
333 {
334 return !empty($this->dataAttributes[$key]) ? $this->dataAttributes[$key] : null;
335 }
336
340 public function getDataAttributes()
341 {
342 return $this->dataAttributes;
343 }
344
351 public function setDataAttributes($dataAttributes)
352 {
353 $this->dataAttributes = $dataAttributes;
354 }
355
361 public function addDataAttribute($key, $value)
362 {
363 $this->dataAttributes[$key] = $value;
364 }
365
371 public function getRenderedIdAttribute()
372 {
373 $result = '';
374 if ($this->getId() !== null)
375 {
376 $result = ' id="' . $this->getId() . '"';
377 }
378 return $result;
379 }
380
384 public function getKey()
385 {
386 return $this->key;
387 }
388
395 public function setKey($key)
396 {
397 $this->key = $key;
398 }
399
406 {
407 $classes = $this->getClasses();
408 $classes = array_filter($classes);
409 $result = '';
410 if (!empty($classes))
411 {
412 $result = !empty($classes) ? ' class="' . implode(' ', $classes) . '"' : '';
413 }
414 return $result;
415 }
416
423 {
424 $dataAttributes = $this->getDataAttributes();
425 $result = '';
426 foreach ($dataAttributes as $key => $value)
427 {
428 $result .= ' data-' . $key . '="' . $value . '"';
429 }
430 return $result;
431 }
432
438 public function getRenderedInlineStyle()
439 {
440 $inlineStyles = $this->getInlineStyle();
441 $result = '';
442 if ($inlineStyles)
443 {
444 $result = 'style="';
445 foreach ($inlineStyles as $key => $value)
446 {
447 $result .= ' ' . $key . ': ' . $value . ';';
448 }
449 $result .= '"';
450 }
451
452 return $result;
453 }
454
458 public function isDisplayLabel()
459 {
460 return $this->isDisplayLabel;
461 }
462
469 public function setIsDisplayLabel($isDisplayLabel)
470 {
471 $this->isDisplayLabel = $isDisplayLabel;
472 }
473
481 public function addInlineStyle($key, $value)
482 {
483 $this->inlineStyle[$key] = $value;
484 }
488 public function getInlineStyle()
489 {
490 return $this->inlineStyle;
491 }
492
499 public function setInlineStyle($inlineStyle)
500 {
501 $this->inlineStyle = $inlineStyle;
502 }
503
507 public function isDisplay()
508 {
509 return $this->display;
510 }
511
518 public function setDisplay($display)
519 {
520 $this->display = $display;
521 }
522
530 protected function includeFieldComponent($templateName, $params = array())
531 {
532 global $APPLICATION;
533 $defaultParams = array(
534 'CONFIGURATION_FIELD' => $this,
535 );
536 $params = array_merge($defaultParams, $params);
537 $APPLICATION->IncludeComponent(self::FIELDS_COMPONENT_NAME, $templateName, $params);
538 }
539}
addJsEventListener(Base $field=null, $eventKey, $jsParams)
Definition base.php:215
includeFieldComponent($templateName, $params=array())
Definition base.php:530
setCompatibleViewTypes($compatibleViewTypes)
Definition base.php:263