Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
base.php
1<?php
2
4
9
15abstract class Base extends View
16{
17 private $componentName;
18 private $componentTemplateName = '';
19 private $componentParameters;
20
24 public function __construct()
25 {
26 $this->setJsClassName('BX.Report.Dashboard.Content.Html');
27 }
28
32 public function getComponentName()
33 {
34 return $this->componentName;
35 }
36
43 public function setComponentName($componentName)
44 {
45 $this->componentName = $componentName;
46 }
47
51 public function getComponentParameters()
52 {
53 return $this->componentParameters;
54 }
55
62 public function setComponentParameters($componentParameters)
63 {
64 $this->componentParameters = $componentParameters;
65 }
66
71 public function addComponentParameters($key, $value)
72 {
73 $this->componentParameters[$key] = $value;
74 }
75
82 public function handlerFinallyBeforePassToView($calculatedPerformedData)
83 {
84 $result['data'] = $calculatedPerformedData;
85 return $result;
86 }
87
95 public function prepareWidgetContent(Widget $widget, $withCalculatedData = false)
96 {
97 $resultWidget = parent::prepareWidgetContent($widget, $withCalculatedData);
98 if (!$withCalculatedData)
99 {
100 return $resultWidget;
101 }
102 if ($withCalculatedData)
103 {
104 $resultWidget['content']['params']['color'] = $widget->getWidgetHandler()->getFormElement('color')->getValue();
105 }
106
107 try
108 {
109 $result = $this->getCalculatedPerformedData($widget, $withCalculatedData);
110 }
111 catch (\Throwable $exception)
112 {
113 $result = [];
114 $error = $exception->getMessage();
115 }
116
117 if (!empty($result['data']) && static::MAX_RENDER_REPORT_COUNT > 1)
118 {
119 foreach ($result['data'] as $num => &$reportResult)
120 {
121 if (!isset($reportResult['config']['color']))
122 {
123 $reportResult['config']['color'] = $widget->getWidgetHandler()->getReportHandlers()[$num]->getFormElement('color')->getValue();
124 }
125
126 if (!isset($reportResult['config']['title']))
127 {
128 $reportResult['title'] = $widget->getWidgetHandler()->getReportHandlers()[$num]->getFormElement('label')->getValue();
129 }
130 else
131 {
132 $reportResult['title'] = $reportResult['config']['title'];
133 }
134 }
135 }
136 elseif (!empty($result['data']))
137 {
138 $reportResult['config']['color'] = $widget->getWidgetHandler()->getReportHandlers()[0]->getFormElement('color')->getValue();
139 $reportResult['title'] = $widget->getWidgetHandler()->getReportHandlers()[0]->getFormElement('label')->getValue();
140 }
141
142 $this->addComponentParameters('WIDGET', $widget);
143 $this->addComponentParameters('RESULT', $result);
144
145 if (!isset($error))
146 {
147 $componentResult = $this->includeComponent();
148
149 $resultWidget['content']['params']['html'] = $componentResult['html'];
150 $resultWidget['content']['params']['css'] = $componentResult['css'];
151 $resultWidget['content']['params']['js'] = $componentResult['js'];
152 }
153 else
154 {
155 $errorResult = static::GetErrorHTML($error);
156
157 $resultWidget['content']['params']['html'] = $errorResult['html'];
158 $resultWidget['content']['params']['css'] = $errorResult['css'];
159 $resultWidget['content']['params']['js'] = $errorResult['js'];
160 }
161
162 return $resultWidget;
163 }
164
165 protected static function GetErrorHTML($errorText)
166 {
167 global $APPLICATION;
168 ob_start();
169 ShowError($errorText);
170 $result['html'] = ob_get_clean();;
171 $result['js'] = $APPLICATION->arHeadScripts;
172 $result['css'] = $APPLICATION->sPath2css;
173
174 foreach ($result['js'] as $key => $value)
175 {
176 $result['js'][$key] = \CUtil::GetAdditionalFileURL($value);
177 }
178 foreach ($result['css'] as $key => $value)
179 {
180 $result['css'][$key] = \CUtil::GetAdditionalFileURL($value);
181 }
182 return $result;
183 }
184
192 protected function getCalculatedPerformedData(Widget $widget, $withCalculatedData)
193 {
194 static $data;
195 if (!$data)
196 {
197 $data = $withCalculatedData ? WidgetHelper::getCalculatedPerformedData($this, $widget) : array();
198 $data = $this->handlerFinallyBeforePassToView($data);
199 }
200 return $data;
201 }
202
208 private function includeComponent()
209 {
210 global $APPLICATION;
211 ob_start();
212 $APPLICATION->IncludeComponent(
213 $this->getComponentName(),
216 );
217 $componentContent = ob_get_clean();
218 $result['html'] = $componentContent;
219 $result['js'] = $APPLICATION->arHeadScripts;
220 $result['css'] = $APPLICATION->sPath2css;
221
222 foreach ($result['js'] as $key => $value)
223 {
224 $result['js'][$key] = \CUtil::GetAdditionalFileURL($value);
225 }
226 foreach ($result['css'] as $key => $value)
227 {
228 $result['css'][$key] = \CUtil::GetAdditionalFileURL($value);
229 }
230 return $result;
231 }
232
236 public function getComponentTemplateName()
237 {
238 return $this->componentTemplateName;
239 }
240
244 public function setComponentTemplateName($componentTemplateName)
245 {
246 $this->componentTemplateName = $componentTemplateName;
247 }
248}
static getCalculatedPerformedData($view, $widget)
Definition widget.php:42
prepareWidgetContent(Widget $widget, $withCalculatedData=false)
Definition base.php:95
getCalculatedPerformedData(Widget $widget, $withCalculatedData)
Definition base.php:192
handlerFinallyBeforePassToView($calculatedPerformedData)
Definition base.php:82