Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
view.php
1<?php
2
4
20
25abstract class View
26{
27 const VIEW_KEY = '';
31
32 private $label;
33 private $logoUri;
34 private $previewImageUri;
35 private $compatibleDataType;
36 private $height;
37 private $jsClassName;
38 private $draggable = true;
39 private $horizontalResizable = true;
40
44 public function getHeight()
45 {
46 return $this->height;
47 }
48
56 public function setHeight($height)
57 {
58 $this->height = $height;
59 }
60
64 public function getKey()
65 {
66 return static::VIEW_KEY;
67 }
68
72 public function getLabel()
73 {
74 return $this->label;
75 }
76
83 public function setLabel($label)
84 {
85 $this->label = $label;
86 }
87
91 public function getLogoUri()
92 {
93 return $this->logoUri;
94 }
95
102 public function setLogoUri($logoUri)
103 {
104 $this->logoUri = $logoUri;
105 }
106
110 public function getCompatibleDataType()
111 {
112 return $this->compatibleDataType;
113 }
114
121 public function setCompatibleDataType($compatibleDataType)
122 {
123 $this->compatibleDataType = $compatibleDataType;
124 }
125
131 public function getCompatibleViewTypes()
132 {
133 return array();
134 }
135
142 abstract public function handlerFinallyBeforePassToView($dataFromReport);
143
150 final public function buildWidgetHandlerForBoard($boardId)
151 {
152 $widgetHandler = new BaseWidget();
153 $widgetHandler->setView($this);
154 $widgetHandler->getWidget()->setWidgetHandler($widgetHandler);
155 $widgetHandler->getWidget()->setBoardId($boardId);
156 $widgetHandler->getWidget()->setViewKey($this->getKey());
157 $widgetHandler->getCollectedFormElements();
158 return $widgetHandler;
159 }
160
168 {
169 for ($emptyReportNum = 0; $emptyReportNum < static::DEFAULT_EMPTY_REPORT_COUNT; $emptyReportNum++)
170 {
171 $reportHandler = Report::buildReportHandlerForWidget(EmptyReport::getClassName(), $widgetHandler->getWidget(), true);
172 $widgetHandler->addReportHandler($reportHandler);
173 }
174
175 return $widgetHandler;
176 }
177
185 public function getReportHandler($reportHandlerClassName, BaseWidget $widgetHandler)
186 {
187 $reportHandler = ReportProvider::getReportHandlerByClassName($reportHandlerClassName);
188 if (!$reportHandler)
189 {
190 return null;
191 }
192 if ($reportHandler instanceof BaseReport)
193 {
195 $reportHandler = new $reportHandler;
196 $reportHandler->setView($this);
197 $reportHandler->setWidgetHandler($widgetHandler);
198 $reportHandler->getCollectedFormElements();
199 $reportHandler->getReport()->setReportHandler($reportHandler);
200 }
201 return $reportHandler;
202 }
203
211 {
212 return $form;
213 }
214
215
222 public function collectWidgetHandlerFormElements(BaseWidget $widgetHandler)
223 {
224 $label = new LabelField('label', 'big');
225 $label->setDefaultValue(Loc::getMessage('REPORT_WIDGET_DEFAULT_TITLE'));
226 $label->addAssets(array(
227 'js' => array('/bitrix/js/report/js/visualconstructor/fields/reporttitle.js')
228 ));
229 $label->setIsDisplayLabel(false);
230
231 $timePeriod = new TimePeriod('time_period', $widgetHandler->getWidget()->getFilterId());
232 $timePeriod->setLabel(Loc::getMessage('REPORT_CALCULATION_PERIOD'));
233
234 $colorPicker = new ColorPicker('color');
235 $colorPicker->setLabel(Loc::getMessage('BACKGROUND_COLOR_OF_WIDGET'));
236 $colorPicker->setDefaultValue('#ffffff');
237
238 $previewBlockField = new PreviewBlock('view_type');
239 $previewBlockField->setWidget($widgetHandler->getWidget());
240 $previewBlockField->addJsEventListener($previewBlockField, $previewBlockField::JS_EVENT_ON_VIEW_SELECT, array(
241 'class' => 'BX.Report.VisualConstructor.FieldEventHandlers.PreviewBlock',
242 'action' => 'viewTypeSelect'
243 ));
244
245 $previewBlockField->addJsEventListener($label, $label::JS_EVENT_ON_CHANGE, array(
246 'class' => 'BX.Report.VisualConstructor.FieldEventHandlers.PreviewBlock',
247 'action' => 'reloadWidgetPreview'
248 ));
249 $previewBlockField->addJsEventListener($timePeriod, $timePeriod::JS_EVENT_ON_SELECT, array(
250 'class' => 'BX.Report.VisualConstructor.FieldEventHandlers.PreviewBlock',
251 'action' => 'reloadWidgetPreview'
252 ));
253
254 $previewBlockField->addAssets(array(
255 'js' => array('/bitrix/js/report/js/visualconstructor/fields/previewblock.js')
256 ));
257 $titleContainer = new Div();
258 $titleContainer->addClass('report-configuration-row');
259 $titleContainer->addClass('report-configuration-no-padding-bottom');
260 $titleContainer->addClass('report-configuration-row-white-background');
261 $titleContainer->addClass('report-configuration-row-margin-bottom');
262 $widgetHandler->addFormElement($titleContainer->start());
263 $widgetHandler->addFormElement($label);
264 $widgetHandler->addFormElement($colorPicker);
265 $widgetHandler->addFormElement($titleContainer->end());
266
267 $timePeriodContainer = new Div();
268 $timePeriodContainer->addClass('report-configuration-row');
269 $timePeriodContainer->addClass('report-configuration-row-white-background');
270 $widgetHandler->addFormElement($timePeriodContainer->start());
271 $widgetHandler->addFormElement($timePeriod);
272 $widgetHandler->addFormElement($timePeriodContainer->end());
273
274 $previewBlockContainer = new Div();
275 $previewBlockContainer->addClass('report-configuration-row');
276 $previewBlockContainer->addClass('report-configuration-row-margin-top-big');
277 $previewBlockContainer->addClass('report-configuration-row-white-background');
278 $widgetHandler->addFormElement($previewBlockContainer->start());
279 $widgetHandler->addFormElement($previewBlockField);
280 $widgetHandler->addFormElement($previewBlockContainer->end());
281 }
282
289 public function collectReportHandlerFormElements($reportHandler)
290 {
291 $headContainer = new Div();
292 $headContainer->addAssets(array(
293 'css' => array('/bitrix/js/report/css/visualconstructor/configheader.css')
294 ));
295
296 $widgetHandler = $reportHandler->getWidgetHandler();
297 $previewBlock = $widgetHandler->getFormElement('view_type');
298
299 $headContainer->setKey('head_container');
300 $headContainer->addClass('report-configuration-head');
301 $labelColorContainer = new Div();
302 $labelColorContainer->setKey('label_color_container');
303 $labelColorContainer->addClass('report-configuration-row');
304
305 $labelField = new LabelField('label');
306 $labelField->setDefaultValue(Loc::getMessage('REPORT_DEFAULT_TITLE'));
307 $labelField->setIsDisplayLabel(false);
308 $labelField->addAssets(array(
309 'js' => array('/bitrix/js/report/js/visualconstructor/fields/reporttitle.js')
310 ));
311 $previewBlock->addJsEventListener($labelField, $labelField::JS_EVENT_ON_CHANGE, array(
312 'class' => 'BX.Report.VisualConstructor.FieldEventHandlers.PreviewBlock',
313 'action' => 'reloadWidgetPreview'
314 ));
315
316 $colorField = new ColorPicker('color');
317 $colorField->setDefaultValue('#4fc3f7');
318 $colorField->addAssets(array(
319 'js' => array('/bitrix/js/report/js/visualconstructor/fields/colorfield.js')
320 ));
321 $colorField->addJsEventListener($colorField, $colorField::JS_EVENT_ON_SELECT, array(
322 'class' => 'BX.Report.VisualConstructor.FieldEventHandlers.ColorField',
323 'action' => 'selectColorInConfigurationForm'
324 ));
325
326 if ($reportHandler->getConfiguration('color'))
327 {
328 $headContainer->addInlineStyle('background-color', $reportHandler->getConfiguration('color')->getValue());
329 }
330 else
331 {
332 $reportHandlersCount = count($reportHandler->getWidgetHandler()->getReportHandlers());
333 $colorDefaultValue = $this->getReportDefaultColor($reportHandlersCount);
334 $headContainer->addInlineStyle('background-color', $colorDefaultValue);
335 $colorField->setValue($colorDefaultValue);
336 }
337
338 $previewBlock->addJsEventListener($colorField, $colorField::JS_EVENT_ON_SELECT, array(
339 'class' => 'BX.Report.VisualConstructor.FieldEventHandlers.PreviewBlock',
340 'action' => 'reloadWidgetPreview'
341 ));
342 $container = new Container();
343 $container->addDataAttribute('role', 'report-remove-button');
344 $removeButton = new ComplexHtml('report-remove-button-' . $reportHandler->getReport()->getGId(), '<div class="report-remove-button"></div>');
345 $removeButton->addJsEventListener($removeButton, $removeButton::JS_EVENT_ON_CLICK, array(
346 'class' => 'BX.Report.VisualConstructor.FieldEventHandlers.ReportHandlerSelect',
347 'action' => 'removeReportFromConfiguration'
348 ));
349 $previewBlock->addJsEventListener($removeButton, $removeButton::JS_EVENT_ON_CLICK, array(
350 'class' => 'BX.Report.VisualConstructor.FieldEventHandlers.PreviewBlock',
351 'action' => 'reloadWidgetPreview'
352 ));
353
354 $container->addElement($removeButton);
355 $headContainerStart = $headContainer->start();
356 $headContainerEnd = $headContainer->end();
357 $containerStartElement = $labelColorContainer->start();
358 $containerEndElement = $labelColorContainer->end();
359
360 $reportHandler->addFormElementToStart($headContainerStart);
361 $reportHandler->addFormElementAfter($containerStartElement, $headContainerStart);
362 $reportHandler->addFormElementAfter($labelField, $containerStartElement);
363 $reportHandler->addFormElementAfter($colorField, $labelField);
364 $reportHandler->addFormElementAfter($container, $colorField);
365 $reportHandler->addFormElementAfter($containerEndElement, $container);
366 $reportHandler->addFormElementAfter($headContainerEnd, $containerEndElement);
367 }
368
372 public function getJsClassName()
373 {
374 return $this->jsClassName;
375 }
376
383 public function setJsClassName($jsClassName)
384 {
385 $this->jsClassName = $jsClassName;
386 }
387
395 public function prepareWidgetContent(Widget $widget, $withCalculatedData = false)
396 {
397 $resultWidget = array(
398 'id' => $widget->getGId(),
399 'title' => 'No Title',
400 'isHeadEnabled' => true,
401 'draggable' => $this->isDraggable(),
402 'droppable' => true,
403 'loaded' => $withCalculatedData,
404 'weight' => $widget->getWeight(),
405 'className' => 'BX.VisualConstructor.Widget',
406 'resizable' => $this->isHorizontalResizable(),
407 'content' => array(
408 'params' => array(
409 'height' => $this->getHeight(),
410 'previewImageUri' => $this->getPreviewImageUri()
411 ),
412 'className' => $this->getJsClassName()
413 )
414 );
415
416 $widgetHandler = $widget->getWidgetHandler();
418 $color = $widgetHandler->getFormElement('color');
419 $colorValue = $color->getValue();
420 $resultWidget['config']['color'] = htmlspecialcharsbx($colorValue);
421 $resultWidget['config']['header']['color'] = htmlspecialcharsbx($colorValue);
422
424 $label = $widgetHandler->getFormElement('label');
425 $labelValue = $label->getValue();
426 $resultWidget['config']['title'] = htmlspecialcharsbx($labelValue);
427
429 $timePeriodField = $widgetHandler->getFormElement('time_period');
430 if ($timePeriodField)
431 {
432 $timePeriodTitle = $timePeriodField->getValueForHuman();
433 $resultWidget['config']['timePeriod'] = Loc::getMessage('REPORT_TIME_PERIOD_MARK_TEXT') . ': ' . $timePeriodTitle;
434 }
435
436 return $resultWidget;
437 }
438
442 public function isDraggable()
443 {
444 return $this->draggable;
445 }
446
453 public function setDraggable($draggable)
454 {
455 $this->draggable = $draggable;
456 }
457
464 public function isCompatibleWithView(View $view)
465 {
466 return in_array($this->getKey(), $view->getCompatibleViewTypes());
467 }
468
475 public function getReportDefaultColor($num)
476 {
477 $defaultColorList = array(
478 "#00c4fb",
479 "#75d900",
480 "#ffab00",
481 "#47d1e2",
482 "#ff5752",
483 "#468ee5",
484 "#1eae43",
485 "#f7d622",
486 "#4fc3f7",
487 '#9dcf00',
488 '#f6ce00'
489 );
490 return $defaultColorList[$num % count($defaultColorList)];
491 }
492
496 public function isHorizontalResizable()
497 {
498 return $this->horizontalResizable;
499 }
500
507 public function setHorizontalResizable($horizontalResizable)
508 {
509 $this->horizontalResizable = $horizontalResizable;
510 }
511
515 public function getPreviewImageUri()
516 {
517 return $this->previewImageUri;
518 }
519
523 public function setPreviewImageUri($previewImageUri)
524 {
525 $this->previewImageUri = $previewImageUri;
526 }
527}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
setHorizontalResizable($horizontalResizable)
Definition view.php:507
setPreviewImageUri($previewImageUri)
Definition view.php:523
setCompatibleDataType($compatibleDataType)
Definition view.php:121
addDefaultReportHandlersToWidgetHandler(BaseWidget $widgetHandler)
Definition view.php:167
collectWidgetHandlerFormElements(BaseWidget $widgetHandler)
Definition view.php:222
prepareWidgetFormBeforeRender(WidgetForm $form)
Definition view.php:210
handlerFinallyBeforePassToView($dataFromReport)
collectReportHandlerFormElements($reportHandler)
Definition view.php:289