Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
board.php
1<?php
2
4
14
19class Board extends Base
20{
21
28 public function toggleToDefaultAction($boardKey)
29 {
30 global $USER;
31 $userId = $USER->getId();
32 $dashboardForUser = Dashboard::loadByBoardKeyAndUserId($boardKey, $userId);
33 if ($dashboardForUser)
34 {
35 $dashboardForUser->delete();
36 }
37
38 $analyticBoardProvider = new AnalyticBoardProvider;
39 $analyticBoardProvider->addFilter('boardKey', $boardKey);
40 $analyticBoard = $analyticBoardProvider->execute()->getFirstResult();
41 if(!$analyticBoard)
42 {
43 return true;
44 }
45 $filter = $analyticBoard->getFilter();
46 if(!$filter)
47 {
48 return true;
49 }
50 $filterId = $filter->getFilterParameters()['FILTER_ID'];
51 $options = new Options($filterId, $filter::getPresetsList());
52 $options->setFilterSettingsArray($filter::getPresetsList());
53 return true;
54 }
55
60 public function toggleModeAction($boardKey)
61 {
62 $oldMode = DashboardHelper::getBoardModeIsDemo($boardKey);
63 DashboardHelper::setBoardModeIsDemo($boardKey, !$oldMode);
64 return array('demoMode' => !$oldMode);
65 }
66
74 public function showAddFormAction($categories, $boardId)
75 {
76 $componentName = 'bitrix:report.visualconstructor.board.controls';
77 $templateName = 'addform';
78 $params = array(
79 'BOARD_ID' => $boardId,
80 'REPORTS_CATEGORIES' => array(),// @TODO
81 );
82 return new Component($componentName, $templateName, $params);
83 }
84
91 public function submitAddFormAction($formParams = array())
92 {
93 if ($formParams['boardId'])
94 {
95 if ($formParams['patternWidgetId'])
96 {
97 $widgetGId = $this->createWidgetFromExisting($formParams);
98 }
99 else
100 {
101 $this->addError(new Error('Should select view type or select from widget pattern'));
102 return false;
103 }
104
105
106 return array('widgetId' => $widgetGId);
107 }
108 else
109 {
110 $this->addError(new Error('Board id might be not blank'));
111 return false;
112 }
113
114 }
115
120 private function createWidgetFromExisting($formParams)
121 {
122 $dashboardForUser = DashboardHelper::getDashboardByKeyForCurrentUser($formParams['boardId']);
123 if (!$dashboardForUser)
124 {
125 $this->addError(new Error('Can\'t create widget because current user has not board to edit'));
126 return false;
127 }
128
129 $widget = \Bitrix\Report\VisualConstructor\Entity\Widget::getWidgetByGId($formParams['patternWidgetId']);
130
131 $copy = $widget->getCopyForCurrentUser();
132 $cellId = 'cell_' . randString(4);
133 try
134 {
135 $row = Row::getRowDefaultEntity(array(
136 'cellIds' => array($cellId)
137 ));
138 }
139 catch (ArgumentException $e)
140 {
141 $this->errorCollection[] = new Error($e->getMessage());
142 return false;
143 }
144
145 $row->setBoardId($formParams['boardId']);
146 $copy->setWeight($cellId);
147 $copy->setGId(Util::generateUserUniqueId());
148 $copy->setIsPattern(false);
149 $copy->setBoardId($formParams['boardId']);
150 $row->addWidgets($copy);
151 $row->setWeight(0);
152 $dashboardForUser->addRows($row);
153 $dashboardForUser->save();
154 return $copy->getGId();
155 }
156}