1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
workflowusercounters.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\Workflow;
4
6{
7 private const TASK_COUNTER_CODE = 'bp_tasks';
8 private const COMMENT_COUNTER_CODE = 'bp_wf_comments';
9 private const WORKFLOW_COUNTER_CODE = 'bp_workflow';
10 private readonly int $userId;
11 private readonly string $siteId;
12 private static array $isNeedSyncWorkflow = [];
13
14 public function __construct(int $userId)
15 {
16 $this->userId = max($userId, 0);
17 $this->siteId = '**';
18
19 if (!isset(self::$isNeedSyncWorkflow[$this->userId]))
20 {
21 [
22 'task' => $task,
23 'comment' => $comment,
24 'workflow' => $workflow,
25 ] = $this->getCounters();
26
27 $newWorkflow = ($task ?: 0) + ($comment ?: 0);
28
29 self::$isNeedSyncWorkflow[$this->userId] = $workflow !== $newWorkflow;
30 }
31 }
32
33 public function incrementTask(int $increment = 1): void
34 {
35 if ($increment <= 0)
36 {
37 return;
38 }
39
40 $this->syncWorkflowIfNeed();
41 $this->increment(self::TASK_COUNTER_CODE, $increment);
42 $this->increment(self::WORKFLOW_COUNTER_CODE, $increment);
43 }
44
45 public function decrementTask(int $decrement = 1): void
46 {
47 if ($decrement <= 0)
48 {
49 return;
50 }
51
52 $this->syncWorkflowIfNeed();
53 $this->decrement(self::TASK_COUNTER_CODE, $decrement);
54 $this->decrement(self::WORKFLOW_COUNTER_CODE, $decrement);
55 }
56
57 public function incrementComment(int $increment = 1): void
58 {
59 if ($increment <= 0)
60 {
61 return;
62 }
63
64 $this->syncWorkflowIfNeed();
65 $this->increment(self::COMMENT_COUNTER_CODE, $increment);
66 $this->increment(self::WORKFLOW_COUNTER_CODE, $increment);
67 }
68
69 public function decrementComment(int $decrement = 1): void
70 {
71 if ($decrement <= 0)
72 {
73 return;
74 }
75
76 $this->syncWorkflowIfNeed();
77 $this->decrement(self::COMMENT_COUNTER_CODE, $decrement);
78 $this->decrement(self::WORKFLOW_COUNTER_CODE, $decrement);
79 }
80
81 public function setTask(int $value = 0): void
82 {
83 if ($value < 0)
84 {
85 return;
86 }
87
88 $task = $this->get(self::TASK_COUNTER_CODE);
89 if ($task !== $value)
90 {
91 $this->set(self::TASK_COUNTER_CODE, $value);
92 }
93
94 $this->syncWorkflow();
95 }
96
97 public function setComment(int $value = 0): void
98 {
99 if ($value < 0)
100 {
101 return;
102 }
103
104 $comment = $this->get(self::COMMENT_COUNTER_CODE);
105 if ($comment !== $value)
106 {
107 $this->set(self::COMMENT_COUNTER_CODE, $value);
108 }
109
110 $this->syncWorkflow();
111 }
112
113 private function syncWorkflowIfNeed(): void
114 {
115 if (self::$isNeedSyncWorkflow[$this->userId])
116 {
117 $this->syncWorkflow();
118 self::$isNeedSyncWorkflow[$this->userId] = false;
119 }
120 }
121
122 private function syncWorkflow(): void
123 {
124 [
125 'task' => $task,
126 'comment' => $comment,
127 'workflow' => $workflow,
128 ] = $this->getCounters();
129
130 $newWorkflow = ($task ?: 0) + ($comment ?: 0);
131 if ($newWorkflow !== $workflow)
132 {
133 $this->set(self::WORKFLOW_COUNTER_CODE, $newWorkflow);
134 }
135 }
136
137 private function getCounters(): array
138 {
139 $task = $this->get(self::TASK_COUNTER_CODE);
140 $comment = $this->get(self::COMMENT_COUNTER_CODE);
141 $workflow = $this->get(self::WORKFLOW_COUNTER_CODE);
142
143 return [
144 'task' => $task,
145 'comment' => $comment,
146 'workflow' => $workflow
147 ];
148 }
149
150 private function increment(string $code, int $increment): void
151 {
152 \CUserCounter::Increment($this->userId, $code, $this->siteId, true, $increment);
153 }
154
155 private function decrement(string $code, int $decrement): void
156 {
157 \CUserCounter::Decrement($this->userId, $code, $this->siteId, true, $decrement);
158 }
159
160 private function set(string $code, int $value): void
161 {
162 \CUserCounter::Set($this->userId, $code, $value, $this->siteId);
163 }
164
165 private function get(string $code): false|int
166 {
167 return \CUserCounter::GetValue($this->userId, $code, $this->siteId);
168 }
169}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$value
Определения Param.php:39
return false
Определения prolog_main_admin.php:185
$comment
Определения template.php:15