Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
counterprovider.php
1<?php
2
4
8use Bitrix\Tasks\Internals\Counter;
9
11{
12 public function __construct(private int $userId) { }
13
14 public function getTotal(int $spaceId = 0): int
15 {
16 $result = 0;
17
18 if (!$this->isTasksModuleAvailable())
19 {
20 return $result;
21 }
22
23 return Counter::getInstance($this->userId)->get(Counter\CounterDictionary::COUNTER_MEMBER_TOTAL, $spaceId);
24 }
25
26 public function getValue(int $spaceId = 0, array $metrics = []): int
27 {
28 $result = 0;
29
30 if (!$this->isTasksModuleAvailable())
31 {
32 return $result;
33 }
34
35 foreach ($metrics as $metric)
36 {
37 switch ($metric)
38 {
39 case Dictionary::COUNTERS_TASKS_TOTAL:
40 return $this->getTotal($spaceId);
41 //TODO: other cases...
42 }
43 }
44
45 return $result;
46 }
47
48 public function getAvailableMetrics(): array
49 {
50 return [
51 Dictionary::COUNTERS_TASKS_TOTAL,
52 ];
53 }
54
55 private function isTasksModuleAvailable(): bool
56 {
57 return Loader::includeModule('tasks');
58 }
59}