Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
analytics.php
1<?php
2
4
5use Bitrix\ImOpenLines\Integrations\Report\Filter;
15
20class Analytics extends Base
21{
23 {
24 //$componentName = 'bitrix:report.analytics.base';
25 $componentName = 'bitrix:ui.sidepanel.wrapper';
26 $params = [
27 'POPUP_COMPONENT_NAME' => 'bitrix:report.analytics.base',
28 'POPUP_COMPONENT_TEMPLATE_NAME' => '',
29 ];
30 return new Component($componentName, '', $params);
31 }
32
33 public function getBoardComponentByKeyAction($boardKey='')
34 {
35 $analyticBoard = $this->getAnalyticBoardByKey($boardKey);
36 if (!$analyticBoard)
37 {
38 $this->addError(new Error('Analytic board with this key not exist'));
39 return false;
40 }
41
42 $additionalParams = [
43 'pageTitle' => $analyticBoard->getTitle(),
44 'pageControlsParams' => $analyticBoard->getButtonsContent()
45 ];
46 return new Component(
47 $analyticBoard->getDisplayComponentName(),
48 $analyticBoard->getDisplayComponentTemplate(),
49 $analyticBoard->getDisplayComponentParams(),
50 $additionalParams
51 );
52 }
53
58 private function getAnalyticBoardByKey($boardKey)
59 {
60 $provider = new AnalyticBoardProvider();
61 $provider->addFilter('boardKey', $boardKey);
62 $board = $provider->execute()->getFirstResult();
63 return $board;
64 }
65
71 public function toggleToDefaultByBoardKeyAction($boardKey, CurrentUser $currentUser)
72 {
73 $analyticBoardProvider = new AnalyticBoardProvider();
74 $analyticBoardProvider->addFilter('boardKey', $boardKey);
75 $analyticBoard = $analyticBoardProvider->execute()->getFirstResult();
76 if (!$analyticBoard)
77 {
78 $this->addError(new Error('Analytic board with this key does not exist'));
79 return false;
80 }
81
82 $dashboardForUser = Dashboard::loadByBoardKeyAndUserId($boardKey, $currentUser->getId());
83 if ($dashboardForUser)
84 {
85 $dashboardForUser->delete();
86 }
87
88 $defaultDashboard = Dashboard::loadByBoardKeyAndUserId($boardKey, 0);
89 if($defaultDashboard)
90 {
91 $defaultDashboard->delete();
92 }
93
94 if (!empty($analyticBoard))
95 {
96 $filter = $analyticBoard->getFilter();
97 if($filter)
98 {
99 $filterId = $filter->getFilterParameters()['FILTER_ID'];
100
101 $options = new Options($filterId, $filter::getPresetsList());
102 $options->restore($filter::getPresetsList());
103 $options->save();
104 }
105 $analyticBoard->resetToDefault();;
106 }
107
108 $additionalParams = [
109 'pageTitle' => $analyticBoard->getTitle(),
110 'pageControlsParams' => $analyticBoard->getButtonsContent()
111
112 ];
113
114 return new Component(
115 $analyticBoard->getDisplayComponentName(),
116 $analyticBoard->getDisplayComponentTemplate(),
117 $analyticBoard->getDisplayComponentParams(),
118 $additionalParams
119 );
120 }
121
122 public function toggleBoardOptionAction($boardKey, CurrentUser $currentUser, string $optionName)
123 {
124 $analyticBoardProvider = new AnalyticBoardProvider();
125 $analyticBoardProvider->addFilter('boardKey', $boardKey);
126 $analyticBoard = $analyticBoardProvider->execute()->getFirstResult();
127 if (!$analyticBoard)
128 {
129 $this->addError(new Error('Analytic board with this key does not exist'));
130 return false;
131 }
132
133 $analyticBoard->toggleOption($optionName);
134
135 AnalyticBoardManager::getInstance()->clearCache();
136 AnalyticBoardBatchManager::getInstance()->clearCache();
137
138 $analyticBoard = $analyticBoardProvider->execute()->getFirstResult();
139
140 $additionalParams = [
141 'pageTitle' => $analyticBoard->getTitle(),
142 'pageControlsParams' => $analyticBoard->getButtonsContent()
143
144 ];
145
146 return new Component(
147 $analyticBoard->getDisplayComponentName(),
148 $analyticBoard->getDisplayComponentTemplate(),
149 $analyticBoard->getDisplayComponentParams(),
150 $additionalParams
151 );
152 }
153}
toggleBoardOptionAction($boardKey, CurrentUser $currentUser, string $optionName)
toggleToDefaultByBoardKeyAction($boardKey, CurrentUser $currentUser)
Definition analytics.php:71