43 return 'b_bp_workflow_user';
57 ->configureNullable(
false)
60 ->configureNullable(
false)
63 ->configureNullable(
false)
66 ->configureNullable(
false)
70 WorkflowFilterTable::class,
71 Join::on(
'this.WORKFLOW_ID',
'ref.WORKFLOW_ID')
73 ->configureJoinType(Join::TYPE_INNER)
77 WorkflowUserCommentTable::class,
78 Join::on(
'this.WORKFLOW_ID',
'ref.WORKFLOW_ID')
79 ->whereColumn(
'this.USER_ID',
'ref.USER_ID')
87 $users = static::getTaskUsers($workflowId);
88 $hasUsers = !empty($users) || static::hasStoredUsers($workflowId);
90 if (!$hasUsers && !static::isLiveFeedProcess($workflow->
getDocumentId()))
97 ? static::WORKFLOW_STATUS_COMPLETED
98 : static::WORKFLOW_STATUS_ACTIVE
103 $users[$authorId][
'IS_AUTHOR'] ??= 1;
106 foreach ($users as $id =>
$user)
108 $users[$id][
'WORKFLOW_STATUS'] = $workflowStatus;
109 $users[$id][
'IS_AUTHOR'] ??= 0;
112 static::syncUsers($workflowId, $users);
117 $users = static::getTaskUsers($workflowId);
119 return static::syncUsers($workflowId, $users);
125 'select' => [
'USER_ID'],
126 'filter' => [
'=WORKFLOW_ID' => $workflowId],
129 $ids = array_column(
$result,
'USER_ID');
131 static fn($id) => (
int)$id,
138 static::updateOnSync(
140 array_fill_keys($userIds, [])
144 private static function isLiveFeedProcess(
array $documentId): bool
146 return ($documentId[0] ??
'') ===
'lists' && ($documentId[1] ??
'') ===
'BizprocDocument';
149 private static function getTaskUsers(
string $workflowId):
array
154 foreach ($taskUsers as $id => $taskStatus)
158 ? static::TASK_STATUS_ACTIVE
159 : static::TASK_STATUS_COMPLETED
164 $authorId = static::getAuthorId($workflowId);
165 if ($authorId && !isset($users[$authorId]))
167 $users[$authorId] = [
168 'TASK_STATUS' => static::TASK_STATUS_NONE,
175 private static function syncUsers(
string $workflowId,
array $users):
array
177 $stored = static::getStoredUsers($workflowId);
179 $toDelete = array_diff_key($stored, $users);
180 $toAdd = array_diff_key($users, $stored);
181 $toUpdate = array_intersect_key($users, $stored);
183 self::deleteOnSync($workflowId, $toDelete);
184 self::addOnSync($workflowId, $toAdd);
185 self::updateOnSync($workflowId, $toUpdate, $stored);
187 return [array_keys($toAdd), array_keys($toUpdate), array_keys($toDelete)];
190 private static function getAuthorId(
string $workflowId): int
193 'select' => [
'USER_ID'],
195 '=WORKFLOW_ID' => $workflowId,
200 return (
int)(
$result[
'USER_ID'] ?? 0);
203 private static function deleteOnSync(
string $workflowId,
array $toDelete): void
210 $deleted = array_keys($toDelete);
215 'WORKFLOW_ID' => $workflowId,
223 private static function addOnSync(
string $workflowId,
array $toAdd): void
234 'WORKFLOW_ID' => $workflowId,
235 'IS_AUTHOR' =>
$user[
'IS_AUTHOR'] ?? 0,
236 'WORKFLOW_STATUS' =>
$user[
'WORKFLOW_STATUS'] ?? static::WORKFLOW_STATUS_ACTIVE,
237 'TASK_STATUS' =>
$user[
'TASK_STATUS'] ?? static::TASK_STATUS_NONE,
238 'MODIFIED' =>
new DateTime(),
245 private static function updateOnSync(
string $workflowId,
array $toUpdate, ?
array $stored =
null): void
252 $modified =
new DateTime();
258 &&
$user[
'TASK_STATUS'] !== static::TASK_STATUS_ACTIVE
266 $user[
'MODIFIED'] ??= $modified;
271 'WORKFLOW_ID' => $workflowId,
280 private static function isEqualUser(
array $userA,
array $userB): bool
283 ($userA[
'IS_AUTHOR'] ??
null) === ($userB[
'IS_AUTHOR'] ??
null)
284 && ($userA[
'WORKFLOW_STATUS'] ??
null) === ($userB[
'WORKFLOW_STATUS'] ??
null)
285 && ($userA[
'TASK_STATUS'] ??
null) === ($userB[
'TASK_STATUS'] ??
null)
289 private static function getStoredUsers(
string $workflowId):
array
292 'select' => [
'USER_ID',
'IS_AUTHOR',
'WORKFLOW_STATUS',
'TASK_STATUS'],
293 'filter' => [
'=WORKFLOW_ID' => $workflowId],
298 while ($row =
$result->fetch())
300 $users[(int)$row[
'USER_ID']] = [
301 'IS_AUTHOR' => (
int)$row[
'IS_AUTHOR'],
302 'WORKFLOW_STATUS' => (int)$row[
'WORKFLOW_STATUS'],
303 'TASK_STATUS' => (
int)$row[
'TASK_STATUS'],
310 private static function hasStoredUsers(
string $workflowId): bool
312 return static::getCount([
'=WORKFLOW_ID' => $workflowId]) > 0;
317 $stored = static::getStoredUsers($workflowId);
318 self::deleteOnSync($workflowId, $stored);
320 return array_keys($stored);
334 $tableName = $sqlHelper->forSql(static::getTableName());
336 'DELETE from %s WHERE WORKFLOW_ID IN(%s)',
338 implode(
',', array_map(fn($id) =>
"'{$id}'", $stateIds))
356 DELETE FROM b_bp_workflow_user WHERE USER_ID = {
$userId}
363 INSERT INTO b_bp_workflow_user
364 (USER_ID, WORKFLOW_ID, IS_AUTHOR, WORKFLOW_STATUS, MODIFIED)
366 select wt.STARTED_BY, wt.ID, 1,
case when wi.id is
null then 1
else 0 end, wt.MODIFIED
367 from b_bp_workflow_state wt
368 left join b_bp_workflow_instance wi on (wt.id = wi.id)
369 where wt.STARTED_BY = {$userId} and wt.MODULE_ID =
'lists' and wt.ENTITY =
'BizprocDocument'
371 ON DUPLICATE KEY UPDATE IS_AUTHOR = 1, WORKFLOW_STATUS = VALUES(WORKFLOW_STATUS), MODIFIED = VALUES(MODIFIED)
378 INSERT INTO b_bp_workflow_user
379 (USER_ID, WORKFLOW_ID, IS_AUTHOR, WORKFLOW_STATUS, TASK_STATUS, MODIFIED)
381 select tu.USER_ID, t.WORKFLOW_ID, 0, 0, 2,
382 case when tu.DATE_UPDATE is
null then now()
else tu.DATE_UPDATE end
383 from b_bp_task_user tu
384 inner join b_bp_task t on (t.ID = tu.TASK_ID)
385 where tu.USER_ID = {$userId} and tu.STATUS =
'0'
387 ON DUPLICATE KEY UPDATE TASK_STATUS = VALUES(TASK_STATUS), MODIFIED = VALUES(MODIFIED)
392 \Bitrix\Bizproc\Worker\Task\UserToWorkflowStepper::bindUser(
$userId);
hidden mSiteList<?=htmlspecialcharsbx(serialize( $siteList))?><?=htmlspecialcharsbx( $siteList[ $j]["ID"])?> _Propery<? if(((COption::GetOptionString( $module_id, "different_set", "N")=="Y") &&( $j !=0))||(COption::GetOptionString( $module_id, "different_set", "N")=="N")) echo "display: none;"?> top adm detail content cell l top adm detail content cell r heading center center ID left