Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
dashboard.php
1<?php
3
9
15{
22 public static function getDashboardByKeyForCurrentUser($boardKey)
23 {
24 global $USER;
25 $userId = $USER->getId();
26 $dashboardForUser = DashboardEntity::loadByBoardKeyAndUserId($boardKey, $userId);
27 if (!$dashboardForUser)
28 {
31
32 $dashboardForUser = $defaultDashboard->getCopyForCurrentUser();
33 $dashboardForUser->setVersion('');
34 $dashboardForUser->setUserId($userId);
35 $dashboardForUser->save();
36 }
37 return $dashboardForUser;
38 }
39
47 public static function addWidgetToDashboardsWithKey($boardKey, WidgetEntity $widget)
48 {
49 $dashboards = DashboardEntity::loadByBoardKeyMultiple($boardKey);
50 $dashboardIds = array();
51 foreach ($dashboards as $dashboard)
52 {
53 $cellId = 'cell_' . randString(4);
54 $row = Row::getRowDefaultEntity(array(
55 'cellIds' => array($cellId)
56 ));
57 $widget->setWeight($cellId);
58 $widget->setBoardId($boardKey);
59 $row->addWidgets($widget->getCopyForCurrentUser());
60 $dashboard->addRows($row);
61 $dashboard->save();
62 $dashboardIds[] = $dashboard->getId();
63 }
64 return $dashboardIds;
65 }
66
67
77 public static function renewDefaultDashboard($boardKey)
78 {
79 $board = new DefaultBoardProvider();
80 $board->addFilter('boardKey', $boardKey);
81 $board = $board->execute()->getFirstResult();
82 if ($board)
83 {
84 if (!$board->getVersion())
85 {
86 throw new SystemException("To renew default dashboard in db state, version of dashboard should exist");
87 }
88
89 $boardFromDb = DashboardEntity::getDefaultBoardByBoardKey($boardKey);
90
91 if ($boardFromDb && $boardFromDb->getVersion() !== $board->getVersion())
92 {
93 $boardFromDb->delete();
94 $board->save();
95 }
96 elseif (!$boardFromDb)
97 {
98 $board->save();
99 }
100 }
101 }
102
103
108 public static function getBoardModeIsDemo($boardKey)
109 {
110 $boardModes = \CUserOptions::GetOption('report_dashboard', 'IS_DEMO_MODE_MARKERS', array());
111 if (isset($boardModes[$boardKey]))
112 {
113 return $boardModes[$boardKey];
114 }
115 return self::getBoardCustomDefaultModeIsDemo($boardKey);
116 }
117
118 public static function setBoardModeIsDemo($boardKey, $mode)
119 {
120 $boardModes = \CUserOptions::GetOption('report_dashboard', 'IS_DEMO_MODE_MARKERS', array());
121 $boardModes[$boardKey] = $mode;
122 \CUserOptions::SetOption('report_dashboard', 'IS_DEMO_MODE_MARKERS', $boardModes);
123 }
124
125 public static function updateBoardCustomDefaultMode($boardKey, $demo = false)
126 {
127 if (self::checkBoardCustomDefaultModeIsExist($boardKey))
128 {
129 if (self::getBoardCustomDefaultModeIsDemo($boardKey) != $demo)
130 {
131 self::setBoardCustomDefaultModeIsDemo($boardKey, $demo);
132 }
133
134 }
135 else
136 {
137 self::setBoardCustomDefaultModeIsDemo($boardKey, $demo);
138 }
139 }
140
141 private static function setBoardCustomDefaultModeIsDemo($boardKey, $demo = false)
142 {
143 $modes = Option::get('report', 'BOARD_CUSTOM_DEFAULT_MODES', serialize(array()));
144 $modes = unserialize($modes, ['allowed_classes' => false]);
145 $modes[$boardKey] = $demo ? 1 : 0;
146 Option::set('report', 'BOARD_CUSTOM_DEFAULT_MODES', serialize($modes));
147 }
148
149 private static function checkBoardCustomDefaultModeIsExist($boardKey)
150 {
151 $modes = Option::get('report', 'BOARD_CUSTOM_DEFAULT_MODES', serialize(array()));
152 $modes = unserialize($modes, ['allowed_classes' => false]);
153 return isset($modes[$boardKey]);
154 }
155
156 private static function getBoardCustomDefaultModeIsDemo($boardKey)
157 {
158 $modes = Option::get('report', 'BOARD_CUSTOM_DEFAULT_MODES', serialize(array()));
159 $modes = unserialize($modes, ['allowed_classes' => false]);
160 return !empty($modes[$boardKey]);
161 }
162
163}
static loadByBoardKeyAndUserId($boardKey, $userId)
static getDefaultBoardWithEverythingByBoardKey($boardKey, $createIfNotExist=true)
static addWidgetToDashboardsWithKey($boardKey, WidgetEntity $widget)
Definition dashboard.php:47
static updateBoardCustomDefaultMode($boardKey, $demo=false)