1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
workflowusercommenttable.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\Workflow\Entity;
4
5use Bitrix\Main\Application;
6use Bitrix\Main\Entity\ExpressionField;
7use Bitrix\Main\ORM\Data\DataManager;
8use Bitrix\Main\ORM\Fields\IntegerField;
9use Bitrix\Main\ORM\Fields\StringField;
10use Bitrix\Main\ORM\Fields\DatetimeField;
11use Bitrix\Main\Type\DateTime;
12
30{
31 public const COMMENT_TYPE_DEFAULT = 0;
32
33 public const COMMENT_TYPE_SYSTEM = 1;
34
35 public static function getTableName()
36 {
37 return 'b_bp_workflow_user_comment';
38 }
39
40 public static function getMap()
41 {
42 return [
43 (new IntegerField('USER_ID'))
44 ->configurePrimary()
45 ,
46 (new StringField('WORKFLOW_ID'))
47 ->configureSize(32)
48 ->configurePrimary()
49 ,
50 (new IntegerField('UNREAD_CNT'))
51 ->configureNullable(false)
52 ,
53 (new IntegerField('LAST_TYPE'))
54 ->configureNullable(false)
55 ->configureDefaultValue(0)
56 ,
57 (new DatetimeField('MODIFIED'))
58 ->configureNullable(false)
59 ,
60 ];
61 }
62
63 public static function incrementUnreadCounter(
64 string $workflowId,
65 array $userIds,
66 int $commentType = self::COMMENT_TYPE_DEFAULT
67 ): void
68 {
69 $connection = Application::getConnection();
70 $sqlHelper = $connection->getSqlHelper();
71 $modified = new DateTime();
72
73 $tableName = static::getTableName();
74
75 $insert = [
76 'WORKFLOW_ID' => $workflowId,
77 'UNREAD_CNT' => 1,
78 'MODIFIED' => $modified,
79 'LAST_TYPE' => $commentType,
80 ];
81 $update = [
82 'UNREAD_CNT' => new \Bitrix\Main\DB\SqlExpression('?#.?# + ?i', $tableName, 'UNREAD_CNT', 1),
83 'MODIFIED' => $modified,
84 'LAST_TYPE' => $commentType,
85 ];
86
87 $primary = [
88 'WORKFLOW_ID',
89 'USER_ID',
90 ];
91
92 foreach ($userIds as $userId)
93 {
94 $insert['USER_ID'] = $userId;
95
96 $queries = $sqlHelper->prepareMerge($tableName, $primary, $insert, $update);
97
98 foreach ($queries as $query)
99 {
100 $connection->queryExecute($query);
101 }
102 }
103 }
104
105 public static function decrementUnreadCounterByDate(string $workflowId, DateTime $modified): array
106 {
107 $rows = static::getList([
108 'filter' => [
109 '=WORKFLOW_ID' => $workflowId,
110 '=MODIFIED' => $modified,
111 ],
112 'select' => ['USER_ID', 'UNREAD_CNT'],
113 ])->fetchAll();
114
115 foreach ($rows as $row)
116 {
117 $key = [
118 'WORKFLOW_ID' => $workflowId,
119 'USER_ID' => $row['USER_ID'],
120 ];
121 if ($row['UNREAD_CNT'] <= 1)
122 {
123 static::delete($key);
124
125 continue;
126 }
127
128 static::update($key, [
129 'UNREAD_CNT' => new \Bitrix\Main\DB\SqlExpression('?# - ?i', 'UNREAD_CNT', 1),
130 ]);
131 }
132
133 return array_map(
134 static fn ($row) => (int)$row['USER_ID'],
135 $rows,
136 );
137 }
138
139 public static function verifyUserUnread(int $userId): void
140 {
141 $rows = static::query()
142 ->where('USER_ID', $userId)
143 ->setSelect(['WORKFLOW_ID'])
144 ->fetchAll()
145 ;
146
147 $workflowIds = array_column($rows, 'WORKFLOW_ID');
148
149 if (!$workflowIds)
150 {
151 return;
152 }
153
154 $workflowRows = WorkflowUserTable::query()
155 ->whereIn('WORKFLOW_ID', $workflowIds)
156 ->where('USER_ID', $userId)
157 ->setSelect(['WORKFLOW_ID'])
158 ->fetchAll();
159
160 $realIds = array_column($workflowRows, 'WORKFLOW_ID');
161 $oldIds = array_diff($workflowIds, $realIds);
162
163 foreach ($oldIds as $id)
164 {
165 static::delete([
166 'USER_ID' => $userId,
167 'WORKFLOW_ID' => $id,
168 ]);
169 }
170 }
171
172 public static function getCountUserUnread(int $userId): int
173 {
174 $row = static::query()
175 ->where('USER_ID', $userId)
176 ->setSelect([new ExpressionField('SUM', 'SUM(%s)', 'UNREAD_CNT')])
177 ->fetch()
178 ;
179
180 return (int)($row['SUM'] ?? 0);
181 }
182
183 public static function deleteByWorkflow(string $workflowId): void
184 {
185 $iterator = static::query()
186 ->setSelect(['USER_ID', 'WORKFLOW_ID'])
187 ->setFilter(['=WORKFLOW_ID' => $workflowId])
188 ->exec()
189 ;
190
191 while ($row = $iterator->fetch())
192 {
193 static::delete($row);
194 }
195 }
196
197 public static function deleteUsersByWorkflow(array $userIds, string $workflowId): void
198 {
199 foreach ($userIds as $userId)
200 {
201 static::delete([
202 'USER_ID' => $userId,
203 'WORKFLOW_ID' => $workflowId,
204 ]);
205 }
206 }
207}
$connection
Определения actionsdefinitions.php:38
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static incrementUnreadCounter(string $workflowId, array $userIds, int $commentType=self::COMMENT_TYPE_DEFAULT)
Определения workflowusercommenttable.php:63
static decrementUnreadCounterByDate(string $workflowId, DateTime $modified)
Определения workflowusercommenttable.php:105
static deleteUsersByWorkflow(array $userIds, string $workflowId)
Определения workflowusercommenttable.php:197
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
Определения arrayresult.php:2
if(empty($signedUserToken)) $key
Определения quickway.php:257
$rows
Определения options.php:264
$iterator
Определения yandex_run.php:610