Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
counter.php
1<?php
2
4
11use Bitrix\Tasks\Internals\Counter\Template\ProjectCounter;
12use Bitrix\Tasks\Internals\Counter\Template\ScrumCounter;
13use Bitrix\Tasks\Internals\Counter as TasksCounter;
14
16{
17 public static function fillCounters(array $params = []): array
18 {
19 $result = [];
20
21 if (
22 !isset($params['groupIdList'], $params['counterData'])
23 || !is_array($params['groupIdList'])
24 || !is_array($params['counterData'])
25 )
26 {
27 return $result;
28 }
29
30 $counterData = $params['counterData'];
31
32 $groupIdList = Util::filterNumericIdList($params['groupIdList']);
33 if (empty($groupIdList))
34 {
35 return $result;
36 }
37
38 $scrumIdList = [];
39 if (isset($params['scrumIdList']))
40 {
41 $scrumIdList = Util::filterNumericIdList($params['scrumIdList']);
42 }
43
44 $currentUserId = static::getCurrentUserId();
45 if ($currentUserId <= 0)
46 {
47 return $result;
48 }
49
50 $mode = ($params['mode'] ?? WorkgroupList::MODE_COMMON);
51 $groupUrlTemplate = ($params['groupUrl'] ?? Helper\Path::get('group_path_template'));
52
53 if (in_array($mode, WorkgroupList::getTasksModeList(), true))
54 {
55 $result = static::fillTasksCounters([
56 'counterData' => $counterData,
57 'mode' => $mode,
58 'groupUrl' => $groupUrlTemplate,
59 'groupIdList' => $groupIdList,
60 'scrumIdList' => $scrumIdList,
61 ]);
62 }
63 else
64 {
65 $result = static::fillCommonCounters([
66 'counterData' => $counterData,
67 'groupUrl' => Helper\Path::get('group_livefeed_path_template'),
68 'groupIdList' => $groupIdList,
69 'scrumIdList' => $scrumIdList,
70 'livefeedCounterSliderOptions' => $params['livefeedCounterSliderOptions'],
71 ]);
72 }
73
74 return $result;
75 }
76
77 public static function getCounterData(array $params = []): array
78 {
79 static $tasksCounterCache = [];
80
81 $result = [];
82
83 $mode = ($params['mode'] ?? WorkgroupList::MODE_COMMON);
84
85 $groupIdList = $params['groupIdList'] ?? [];
86 if (empty($groupIdList))
87 {
88 return $result;
89 }
90
91 $scrumIdList = $params['scrumIdList'] ?? [];
92
93 $currentUserId = static::getCurrentUserId();
94 if ($currentUserId <= 0)
95 {
96 return $result;
97 }
98
99 $tasksModuleInstalled = Loader::includeModule('tasks');
100
101 if (in_array($mode, WorkgroupList::getTasksModeList(), true))
102 {
103 $projectCounter = (
104 $mode === WorkgroupList::MODE_TASKS_SCRUM
105 ? new ScrumCounter($currentUserId)
106 : new ProjectCounter($currentUserId)
107 );
108
109 foreach ($groupIdList as $groupId)
110 {
111 $counterData = $projectCounter->getRowCounter($groupId);
112
113 $result[$groupId] = [
114 'all' => [
115 'VALUE' => $counterData['VALUE'],
116 'COLOR' => $counterData['COLOR'],
117 ],
118 ];
119 }
120 }
121 else
122 {
123 $counters = \CUserCounter::getValues($currentUserId);
124 if (!isset($tasksCounterCache[$currentUserId]))
125 {
126 $tasksCounterCache[$currentUserId] = TasksCounter::getInstance($currentUserId);
127 }
128
129 $tasksCounter = $tasksCounterCache[$currentUserId];
130
131 foreach ($groupIdList as $groupId)
132 {
133 $counterKey = \CUserCounter::LIVEFEED_CODE . 'SG' . $groupId;
134
135 $result[$groupId] = [
136 'livefeed' => [
137 'VALUE' => (int)($counters[$counterKey] ?? 0),
138 ],
139 ];
140
141 if ($tasksModuleInstalled)
142 {
143 $result[$groupId]['tasks_expired'] = [
144 'VALUE' => (
145 in_array($groupId, $scrumIdList, true)
146 ? 0
147 : $tasksCounter->get(TasksCounter\CounterDictionary::COUNTER_EXPIRED, $groupId)
148 )
149 ];
150
151 $result[$groupId]['tasks_new_comments'] = [
152 'VALUE' => $tasksCounter->get(TasksCounter\CounterDictionary::COUNTER_NEW_COMMENTS, $groupId),
153 ];
154 }
155 }
156 }
157
158 return $result;
159 }
160
161 protected static function fillTasksCounters(array $params = []): array
162 {
163 $result = [];
164
165 $groupIdList = $params['groupIdList'] ?? [];
166 if (empty($groupIdList))
167 {
168 return $result;
169 }
170
171 $currentUserId = static::getCurrentUserId();
172 if ($currentUserId <= 0)
173 {
174 return $result;
175 }
176
177 $counterData = $params['counterData'] ?? [];
178
179 $scrumIdList = $params['scrumIdList'] ?? [];
180
181 $groupUrlTemplate = ($params['groupUrl'] ?? Helper\Path::get('group_path_template'));
182
183 $colorMap = [
184 Helper\UI\Grid\CounterStyle::STYLE_GRAY => Grid\Counter\Color::GRAY,
185 Helper\UI\Grid\CounterStyle::STYLE_GREEN => Grid\Counter\Color::SUCCESS,
186 Helper\UI\Grid\CounterStyle::STYLE_RED => Grid\Counter\Color::DANGER,
187 ];
188
189 $sliderOptionsData = [
190 'contentClassName' => 'bitrix24-group-slider-content',
191 'loader' => 'intranet:slider-tasklist',
192 'cacheable' => false,
193 'customLeftBoundary' => 0,
194 'newWindowLabel' => true,
195 'copyLinkLabel' => true,
196 ];
197
198 foreach ($groupIdList as $groupId)
199 {
200 $groupCounterData = ($counterData[$groupId] ?? []);
201
202 $groupUrl = str_replace([ '#id#', '#ID#', '#GROUP_ID#', '#group_id#' ], $groupId, $groupUrlTemplate);
203
204 if (in_array($groupId, $scrumIdList, true))
205 {
206 $sliderOptionsData['loader'] = 'intranet:scrum';
207 }
208
209 $sliderOptions = Json::encode($sliderOptionsData);
210
211 $result[$groupId] = [
212 'ACTIVITY_DATE' => [
213 'type' => Grid\Counter\Type::LEFT_ALIGNED,
214 'color' => $colorMap[$groupCounterData['all']['COLOR']],
215 'value' => $groupCounterData['all']['VALUE'],
216 'events' => [
217 'click' => "BX.SidePanel.Instance.open.bind(BX.SidePanel.Instance, '{$groupUrl}', {$sliderOptions})",
218 ],
219 'class' => 'sonet-ui-grid-counter',
220 ],
221 ];
222 }
223
224 return $result;
225 }
226
227 protected static function fillCommonCounters(array $params = []): array
228 {
229 $result = [];
230
231 $groupIdList = $params['groupIdList'] ?? [];
232 if (empty($groupIdList))
233 {
234 return $result;
235 }
236
237 $counterData = $params['counterData'] ?? [];
238
239 $scrumIdList = $params['scrumIdList'] ?? [];
240
241 $groupUrlTemplate = ($params['groupUrl'] ?? Helper\Path::get('group_livefeed_path_template'));
242 $sliderOptionsData = ($params['sliderOptions'] ?? static::getLivefeedCounterSliderOptions());
243
244 $tasksModuleInstalled = ModuleManager::isModuleInstalled('tasks');
245
246 foreach ($groupIdList as $groupId)
247 {
248 $groupCounterData = ($counterData[$groupId] ?? []);
249
250 $livefeedCounterValue = (int)($groupCounterData['livefeed']['VALUE'] ?? 0);
251 $tasksCounterValue = (
252 $tasksModuleInstalled
253 ? (int)($groupCounterData['tasks_expired']['VALUE'] ?? 0)
254 + (int)($groupCounterData['tasks_new_comments']['VALUE'] ?? 0)
255 : 0
256 );
257
258 $groupUrl = str_replace([ '#id#', '#ID#', '#GROUP_ID#', '#group_id#' ], $groupId, $groupUrlTemplate);
259
260 if (in_array($groupId, $scrumIdList, true))
261 {
262 $sliderOptionsData['loader'] = 'intranet:scrum';
263 }
264
265 $sliderOptions = Json::encode($sliderOptionsData);
266
267 $result[$groupId] = [
268 static::getLivefeedCounterColumnId() => [
269 'type' => Grid\Counter\Type::RIGHT,
270 'color' => Grid\Counter\Color::DANGER,
271 'value' => $livefeedCounterValue + $tasksCounterValue,
272 'events' => [
273 'click' => "BX.SidePanel.Instance.open.bind(BX.SidePanel.Instance, '{$groupUrl}', {$sliderOptions})",
274 ],
275 'class' => 'sonet-ui-grid-counter',
276 ],
277 ];
278 }
279
280 return $result;
281 }
282
283 protected static function getCurrentUserId(): int
284 {
285 static $result = null;
286 if ($result === null)
287 {
288 global $USER;
289 $result = (int)$USER->getId();
290 }
291
292 return $result;
293 }
294
295 public static function getLivefeedCounterColumnId(): string
296 {
297 return 'NAME';
298 }
299
300 public static function getLivefeedCounterSliderOptions(): array
301 {
302 return [
303// 'contentClassName' => 'bitrix24-group-slider-content',
304 'cacheable' => false,
305// 'customLeftBoundary' => 0,
306// 'newWindowLabel' => true,
307// 'copyLinkLabel' => true,
308 ];
309 }
310}
static includeModule($moduleName)
Definition loader.php:69
static isModuleInstalled($moduleName)
static encode($data, $options=null)
Definition json.php:24