Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basewidget.php
1<?php
2
4
10
15class BaseWidget extends Base
16{
17 private $widget;
18 private $reportHandlerList = array();
19
23 public static function getClassName()
24 {
25 return get_called_class();
26 }
27
31 public function __construct()
32 {
33 $widget = new Widget();
34 $widget->setWidgetClass(static::getClassName());
35 $this->setWidget($widget);
36 }
37
41 public function getCollectedFormElements()
42 {
43 parent::getCollectedFormElements();
44 $this->getView()->collectWidgetHandlerFormElements($this);
45 return $this->getFormElements();
46 }
47
53 protected function collectFormElements()
54 {
55
56
57 }
58
62 public function getWidget()
63 {
64 return $this->widget;
65 }
66
71 public function setWidget($widget)
72 {
73 $this->widget = $widget;
74 }
75
79 public function getFormElements()
80 {
81 $result = array();
82 foreach ($this->formElementsList as $key => $element)
83 {
84 $viewModesWhereFieldAvailable = $element->getCompatibleViewTypes();
85 if ($viewModesWhereFieldAvailable != null)
86 {
87 $viewKey = $this->getWidget()->getViewKey();;
88 $viewProvider = new ViewProvider();
89 $viewProvider->addFilter('primary', $viewKey);
90 $viewProvider->addFilter('dataType', $viewModesWhereFieldAvailable);
91 $views = $viewProvider->execute()->getResults();
92 if (!empty($views))
93 {
94 $result[$key] = $element;
95 }
96 }
97 else
98 {
99 $result[$key] = $element;
100 }
101 if (($element instanceof BaseValuable) || ($element instanceof Container))
102 {
103 $element->setName($this->getNameForFormElement($element));
104 }
105 }
106 return $result;
107 }
108
115 protected function getNameForFormElement(BaseValuable $element)
116 {
117 $name = '';
118 if ($this->getWidget())
119 {
120 $name = 'widget[' . $this->getWidget()->getGId() . ']';
121 }
122 $name .= parent::getNameForFormElement($element);
123 return $name;
124 }
125
129 public function getReportHandlers()
130 {
131 return $this->reportHandlerList;
132 }
133
140 public function addReportHandler(BaseReport $reportHandler)
141 {
142 $reportHandler->setWidgetHandler($this);
143 $this->getWidget()->addReportHandler($reportHandler);
144 $this->reportHandlerList[] = $reportHandler;
145 return $this;
146 }
147
154 public function fillWidget(Widget $widget)
155 {
156 $viewHandler = ViewProvider::getViewByViewKey($widget->getViewKey());
157 if ($viewHandler)
158 {
159 $this->setView($viewHandler);
160 }
161 $this->setWidget($widget);
162 $this->setConfigurations($widget->getConfigurations());
164 $this->fillFormElementValues();
165 if ($widget->getReports())
166 {
167 foreach ($widget->getReports() as $report)
168 {
169 $this->reportHandlerList[] = $report->getReportHandler();
170 }
171 }
172 }
173
174 private function fillFormElementValues()
175 {
176 $formElements = $this->getFormElements();
177 $configurations = $this->getConfigurations();
178 if (!empty($configurations))
179 {
180 foreach ($configurations as $configuration)
181 {
182 if (isset($formElements[$configuration->getKey()]) && ($formElements[$configuration->getKey()] instanceof BaseValuable))
183 {
185 $formElements[$configuration->getKey()]->setValue($configuration->getValue());
186 }
187 }
188 }
189 }
190}