Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
dashboardmanager.php
1<?php
2
4
11
13{
14 private static DashboardManager $manager;
15
19 private array $dashboardList = [];
24 private ?array $allowedDashboardList;
25
30 public static function getManager(): self
31 {
32 if (!isset(self::$manager))
33 {
34 self::$manager = new DashboardManager();
35 }
36
37 return self::$manager;
38 }
39
40 public static function getCatalogDashboardList(): array
41 {
42 $dashboards = [
46 ];
47
48 return $dashboards;
49 }
50
51 public function getActiveViewList(): array
52 {
53 if (!self::checkAccessRights())
54 {
55 return [];
56 }
57
58 $viewList = [];
59
61 foreach ($this->getAllowedDashboards() as $dashboard)
62 {
63 array_push($viewList, ...$dashboard->getActiveViewList());
64 }
65 return $viewList;
66 }
67
68 public function getActiveHandlerList(): array
69 {
70 if (!self::checkAccessRights())
71 {
72 return [];
73 }
74
75 $handlersList = [];
76
78 foreach ($this->getAllowedDashboards() as $dashboard)
79 {
81 $viewHandlers = array_map(static function(ViewRenderable $view) {
82 return $view->getViewHandler();
83 }, $dashboard->getActiveViewList());
84
85 array_push($handlersList, ...$viewHandlers);
86 }
87
88 return $handlersList;
89 }
90
91 public function getDashboardList(): array
92 {
93 if (!self::checkAccessRights())
94 {
95 return [];
96 }
97
98 $dashboards = [];
100 foreach ($this->getAllowedDashboards() as $dashboard)
101 {
102 $dashboards[] = $dashboard->getDashboard();
103 }
104
105 return $dashboards;
106 }
107
108 public function getAnalyticBoardList(): array
109 {
110 if (!self::checkAccessRights())
111 {
112 return [];
113 }
114
115 if (!ToolAvailabilityManager::getInstance()->checkInventoryManagementAvailability())
116 {
117 return [];
118 }
119
120 $boards = [];
122 foreach ($this->getAllowedDashboards() as $dashboard)
123 {
124 $boards[] = $dashboard->getAnalyticBoard();
125 }
126
127 return $boards;
128 }
129
130 public function getAnalyticBoardBatchList(): array
131 {
132 if (!self::checkAccessRights())
133 {
134 return [];
135 }
136
137 if (!ToolAvailabilityManager::getInstance()->checkInventoryManagementAvailability())
138 {
139 return [];
140 }
141
142 $boards = [];
144 foreach ($this->getAllowedDashboards() as $dashboard)
145 {
146 $boards[] = $dashboard->getAnalyticBoardBatch();
147 }
148
149 return $boards;
150 }
151
157 public function addDashboard(CatalogDashboard ...$dashboard): void
158 {
159 array_push($this->dashboardList, ...$dashboard);
160 }
161
162 private function __construct()
163 {
164 $this->addDashboard(...self::getCatalogDashboardList());
165 }
166
170 public function getAllowedDashboards(): array
171 {
172 if (isset($this->allowedDashboardList))
173 {
174 return $this->allowedDashboardList;
175 }
176
177 $acceptedDashboards = AccessController::getCurrent()->getPermissionValue(ActionDictionary::ACTION_STORE_ANALYTIC_VIEW);
178 if (!$acceptedDashboards)
179 {
180 return [];
181 }
182
183 $allAccepted = in_array(PermissionDictionary::VALUE_VARIATION_ALL, $acceptedDashboards, true);
184 $this->allowedDashboardList = [];
186 foreach ($this->dashboardList as $dashboard)
187 {
188 if ($allAccepted || in_array($dashboard->getAccessBoardId(), $acceptedDashboards, true))
189 {
190 $this->allowedDashboardList[] = $dashboard;
191 }
192 }
193
194 return $this->allowedDashboardList;
195 }
196
197 private static function checkAccessRights(): bool
198 {
199 return
200 Loader::includeModule('catalog')
201 && AccessController::getCurrent()->check(ActionDictionary::ACTION_CATALOG_READ)
202 && AccessController::getCurrent()->check(ActionDictionary::ACTION_STORE_ANALYTIC_VIEW)
203 ;
204 }
205}