53 $componentName =
'bitrix:report.visualconstructor.widget.form';
54 $widget = \Bitrix\Report\VisualConstructor\Entity\Widget::getCurrentUserWidgetByGId($widgetId);
60 'ORIGINAL_WIDGET_GID' => $widgetId,
62 'BOARD_ID' => $boardId,
63 'PAGE_TITLE' =>
Loc::getMessage(
'REPORT_WIDGET_SETTINGS_CONTENT_TITLE'),
64 'SAVE_BUTTON_TITLE' =>
Loc::getMessage(
'REPORT_WIDGET_SETTINGS_SAVE_BUTTON_TITLE'),
66 return new Component($componentName, $templateName, $params);
83 if (!empty($formParams[
'boardId']))
85 $boardKey = $formParams[
'boardId'];
96 if (!$dashboardForUser)
98 $this->
addError(
new Error(
'Can\'t save configuration because current user has not dashboard to edit'));
103 if (!empty($formParams[
'isPattern']))
105 $isPattern = $formParams[
'isPattern'] ===
'on' ? true :
false;
108 $categoryKey = !empty($formParams[
'categoryKey']) ? $formParams[
'categoryKey']:
'';
110 $widgetGId = $formParams[
'widgetId'];
111 $originalWidgetGId = $formParams[
'originalWidgetGId'];
112 $widgetConfigurations = $formParams[
'widget'][$widgetGId][
'configurations'];
113 $reportsConfigurationsFromForm = $formParams[
'widget'][$widgetGId][
'reports'];
114 $deletedReportIds = !empty($formParams[
'deletedReports']) ? $formParams[
'deletedReports'] : array();
117 if ($widgetGId !== $originalWidgetGId)
119 $widget = \Bitrix\Report\VisualConstructor\Entity\Widget::getCurrentUserWidgetByGId($originalWidgetGId);
123 $widget = \Bitrix\Report\VisualConstructor\Entity\Widget::getCurrentUserWidgetByGId($widgetGId);
128 $this->
addError(
new Error(
'Can\'t save configuration because widget with this id not exist'));
133 if ($widgetGId !== $originalWidgetGId)
135 $newWidget = $this->createWidgetByParams($formParams);
136 $newWidget->setWeight($widget->getWeight());
137 $newWidget->setGId($widget->getGId());
138 $newWidget->setRowId((
int)$widget->getRowId());
139 $newWidget->setCategoryKey($widget->getCategoryKey());
143 return array(
'widgetId' => $newWidget->getGId());
147 $widget->loadAttribute(
'reports');
148 $widgetHandler = $widget->getWidgetHandler();
149 $this->setConfigurableEntityConfiguration($widget, $widgetHandler, $widgetConfigurations);
150 $widget->setViewKey($widget->getWidgetHandler()->getConfiguration(
'view_type')->getValue());
151 $widget->setBoardId($boardKey);
152 $widget->setCategoryKey($categoryKey);
158 $widgetReports = $widget->getReportsGidKeyed();
162 foreach ($deletedReportIds as $deletedReportId)
164 if (!empty($widgetReports[$deletedReportId]))
166 $widgetReports[$deletedReportId]->delete();
168 unset($reportsConfigurationsFromForm[$deletedReportId]);
172 foreach ($reportsConfigurationsFromForm as $reportId => $configurationFromForm)
174 $configuration = $configurationFromForm[
'configurations'];
176 if ($this->isReportPseudo($reportId))
178 $this->addReportToWidget($widget, $configuration);
182 $report = $widgetReports[$reportId];
183 $reportHandler = $report->getReportHandler();
184 $this->setConfigurableEntityConfiguration($report, $reportHandler, $configuration);
192 \Bitrix\Report\VisualConstructor\Helper\Widget::saveWidgetAsCurrentUserPattern($widget);
195 return array(
'widgetId' => $widget->getGId());
207 $widget = $this->createWidgetByParams($formParams);
209 return array(
'widgetId' => $widget->getGId());
217 private function createWidgetByParams($params)
219 $widgetGid = $params[
'widgetId'];
221 $viewController = ViewProvider::getViewByViewKey($params[
'widget'][$widgetGid][
'configurations'][
'new'][
'view_type']);
222 if (!$viewController)
229 $userId = $USER->getId();
232 $this->
addError(
new Error(
'Can\'t create widget because current user has not id'));
237 if (!$dashboardForUser)
239 $this->
addError(
new Error(
'Can\'t create widget because current user has not board to edit'));
245 if (!empty($params[
'isPattern']))
247 $isPattern = $params[
'isPattern'] ===
'on' ? true :
false;
250 $categoryKey = !empty($params[
'categoryKey']) ? $params[
'categoryKey']:
'';
251 $widgetHandler = $viewController->buildWidgetHandlerForBoard($params[
'boardId']);
254 $widgetPositions = array(
'cell_' . rand(999, 99999));
258 $row = \Bitrix\Report\VisualConstructor\Helper\Row::getRowDefaultEntity(array(
259 'cellIds' => $widgetPositions
262 catch (ArgumentException $e)
268 $dashboardForUser->addRows($row);
272 $widget = $widgetHandler->getWidget();
273 $widget->setCategoryKey($categoryKey);
274 $widget->setWeight($widgetPositions[0]);
275 $widget->setOwnerId($userId);
276 $widget->setGId(Util::generateUserUniqueId());
277 $row->addWidgets($widget);
278 $dashboardForUser->save();
281 $widgetGId = $params[
'widgetId'];
282 $widgetConfigurations = $params[
'widget'][$widgetGId][
'configurations'];
283 $reportsConfigurationsFromForm = $params[
'widget'][$widgetGId][
'reports'];
285 $widgetHandler = $widget->getWidgetHandler();
286 $this->setConfigurableEntityConfiguration($widget, $widgetHandler, $widgetConfigurations);
288 foreach ($reportsConfigurationsFromForm as $reportId => $configurationFromForm)
290 $configuration = $configurationFromForm[
'configurations'];
292 if (is_array($params[
'deletedReports']) && in_array($reportId, $params[
'deletedReports']))
297 if ($this->isReportPseudo($reportId))
299 $this->addReportToWidget($widget, $configuration);
305 \Bitrix\Report\VisualConstructor\Helper\Widget::saveWidgetAsCurrentUserPattern($widget, $widget->getCategoryKey());
319 $componentName =
'bitrix:report.visualconstructor.widget.form';
321 $boardId = $params[
'boardId'];
322 $mode = $params[
'mode'];
325 $widget = \Bitrix\Report\VisualConstructor\Helper\Widget::constructNewPseudoWidgetByParams($params);
333 $widget->setGId(
'pseudo_widget_for_add');
339 'ORIGINAL_WIDGET_GID' => $params[
'widgetId'],
341 'BOARD_ID' => $boardId,
342 'PAGE_TITLE' => $mode ===
'create' ?
Loc::getMessage(
'REPORT_CREATE_WIDGET_SETTINGS_CONTENT_TITLE') :
Loc::getMessage(
'REPORT_WIDGET_SETTINGS_CONTENT_TITLE'),
343 'SAVE_BUTTON_TITLE' => $mode ===
'create' ?
Loc::getMessage(
'REPORT_CREATE_WIDGET_SETTINGS_SAVE_BUTTON_TITLE') :
Loc::getMessage(
'REPORT_WIDGET_SETTINGS_SAVE_BUTTON_TITLE'),
345 return new Component($componentName, $templateName, $params);
363 if (!isset($params[
'newViewKey']))
369 if (!isset($params[
'oldViewKey']))
374 $newView = ViewProvider::getViewByViewKey($params[
'newViewKey']);
375 $oldView = ViewProvider::getViewByViewKey($params[
'oldViewKey']);
379 $this->
addError(
new Error(
'view not found with key: ' . $params[
'newViewKey']));
385 $this->
addError(
new Error(
'view not found with key: ' . $params[
'oldViewKey']));
390 $result = $oldView->isCompatibleWithView($newView);
391 return array(
'isCompatible' => $result);
404 $widget = \Bitrix\Report\VisualConstructor\Helper\Widget::constructPseudoWidgetByParams($params);
412 $pseudoWidgetPreparedData = \Bitrix\Report\VisualConstructor\Helper\Widget::prepareWidgetContent($widget,
true);
413 $widgetConfigurationFields = $widget->getWidgetHandler()->getFormElements();
414 $reports = $widget->getReports();
415 $reportsResult = array();
418 foreach ($reports as $report)
420 $configurationFields = $report->getReportHandler()->getFormElements();
421 $reportsResult[] = array(
422 'configurationFields' => $configurationFields
429 'pseudoWidget' => $pseudoWidgetPreparedData,
430 'configurationFields' => $widgetConfigurationFields,
432 'reports' => $reportsResult
441 private function setConfigurableEntityConfiguration(
ConfigurableModel $model,
Base $handler, $formConfigurations)
443 if (!empty($formConfigurations[
'old']))
445 $keys = array_keys($formConfigurations[
'old']);
446 $configurations = $handler->getConfigurationsGidKeyed();
447 foreach ($configurations as $id => $configuration)
449 if (in_array($id, $keys))
451 $field = $handler->getFormElement($configuration->getKey());
454 $newValue = $formConfigurations[
'old'][$id][$configuration->getKey()];
455 $field->setValue($newValue);
456 $configuration->setValue($field->getValue());
463 if (!empty($formConfigurations[
'new']))
465 foreach ($formConfigurations[
'new'] as $key => $newConfiguration)
467 $field = $handler->getFormElement($key);
468 if ($field instanceof BaseValuable)
470 $field->setDefaultValue($newConfiguration);
484 private function isReportPseudo($reportId)
486 return (mb_strpos($reportId,
'_pseudo') === 0);
494 private function addReportToWidget(\
Bitrix\Report\VisualConstructor\Entity\Widget $widget, $configuration)
496 if (!empty($configuration[
'new'][
'reportHandler']))
498 $reportHandler = Report::buildReportHandlerForWidget($configuration[
'new'][
'reportHandler'], $widget);
499 if ($reportHandler instanceof BaseReport)
501 foreach ($configuration[
'new'] as $key => $configurationValue)
503 $formElement = $reportHandler->getFormElementFromCollected($key);
504 if ($formElement instanceof BaseValuable)
506 $formElement->setValue($configurationValue);
507 $reportConfiguration = $reportHandler->getConfiguration($key);
508 if ($reportConfiguration)
510 $reportConfiguration->setValue($formElement->getValue());
514 $reportHandler->getReport()->setConfigurations($reportHandler->getConfigurations());
515 $widget->addReportHandler($reportHandler);
531 $widget = \Bitrix\Report\VisualConstructor\Entity\Widget::getCurrentUserWidgetByGId($widgetId);
532 if (!$widget->getId())
537 $preparedWidget = \Bitrix\Report\VisualConstructor\Helper\Widget::prepareWidgetContent($widget,
true);
538 $preparedWidget[
'row'] = array(
539 'id' => $widget->getRow()->getGId(),
540 'layoutMap' => $widget->getRow()->getLayoutMap(),
542 return $preparedWidget;
553 $preparedObjectForDashboard = \Bitrix\Report\VisualConstructor\Helper\Widget::prepareBoardWithEntitiesByBoardId($boardId);
554 return $preparedObjectForDashboard;
570 if (!$dashboardForUser)
572 $this->
addError(
new Error(
'Can\'t update widget because current user has not dashboard to edit'));
576 $widget = \Bitrix\Report\VisualConstructor\Entity\Widget::getCurrentUserWidgetByGId($widgetId);
580 if (!empty($params[
'rowId']) && $params[
'rowId'] != $widget->getRow()->getGId())
582 $row = DashboardRow::getCurrentUserRowByGId($params[
'rowId']);
586 $widget->setRow($row);
590 $this->
addError(
new Error(
"No row with id: " . $params[
'rowId']));
594 $widget->getRow()->setLayoutMap($params[
'rowLayoutMap']);
597 if (!empty($params[
'cellId']))
599 $widget->setWeight($params[
'cellId']);
603 return $widget->getGId();
607 $this->
addError(
new Error(
"No widget with id: " . $widgetId));
621 $boardKey = $params[
'boardId'];
622 $widgetId = $params[
'widgetId'];
625 if ($dashboardForUser)
627 $deleteWidgetId = \Bitrix\Report\VisualConstructor\Entity\Widget::removeCurrentUserWidgetByGId($widgetId);
628 return $deleteWidgetId;
632 $this->
addError(
new Error(
'Cant delete row because current user has not own dashboard'));
648 $filter = Query::filter();
649 $filter->where(
'GID', $widgetId);
650 $filter->where(
'OWNER_ID', $USER->getId());
651 $filter->where(
'IS_PATTERN',
true);
652 $widget = \Bitrix\Report\VisualConstructor\Entity\Widget::load($filter);
654 if ($widget->getOwnerId() === $USER->getId())
656 $widget->deletePatternWidget();
static getMessage($code, $replace=null, $language=null)