1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
WorkflowTemplateInstancesView.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\UI;
4
5use Bitrix\Bizproc\Api\Data\UserService\UsersToGet;
6use Bitrix\Bizproc\Api\Service\UserService;
7use Bitrix\Bizproc\Workflow\Entity\WorkflowInstanceTable;
8use Bitrix\Main\Entity\ReferenceField;
9use Bitrix\Main\ORM\Fields\ExpressionField;
10use Bitrix\Main\Type\DateTime;
11
12class WorkflowTemplateInstancesView implements \JsonSerializable
13{
14 private int $tplId;
15 private int $allCount;
16 private array $usersView = [];
17 private ?DateTime $lastActivity;
18
19 public function __construct(int $tplId, bool $onlyHuman = false)
20 {
21 $this->tplId = $tplId;
22 $this->loadInstances($onlyHuman);
23 }
24
25 protected function loadInstances(bool $onlyHuman): void
26 {
27 $query = WorkflowInstanceTable::query();
28 $query->addFilter('WORKFLOW_TEMPLATE_ID', $this->tplId)
29 ->addSelect('STARTED_BY')
30 ->addSelect('STARTED')
31 ->setOrder(['STARTED' => 'ASC'])
32 ->setLimit(3)
33 ;
34 if ($onlyHuman)
35 {
36 $query->whereNotNull('STARTED_BY');
37 }
38 $result = $query->exec();
39 $rows = $result->fetchAll();
40
41 $this->allCount = $result->getSelectedRowsCount() >= 3
42 ? $this->countFirstHundred()
43 : $result->getSelectedRowsCount()
44 ;
45
46 $userIds = array_column($rows, 'STARTED_BY');
47 $this->lastActivity = $rows[0]['STARTED'] ?? null;
48 if ($userIds)
49 {
50 $this->loadUsersView($userIds);
51 }
52 }
53
54 public function getTplId(): int
55 {
56 return $this->tplId;
57 }
58
59 public function getLastActivity(): ?DateTime
60 {
61 return $this->lastActivity;
62 }
63
64 public function jsonSerialize(): array
65 {
66 return [
67 'tplId' => $this->tplId,
68 'allCount' => $this->allCount,
69 'users' => $this->usersView,
70 ];
71 }
72
73 private function loadUsersView(array $userIds): void
74 {
75 $userService = new UserService();
76 $response = $userService->getUsersView(new UsersToGet($userIds));
77
78 if (!$response->isSuccess())
79 {
80 return;
81 }
82
83 $userViews = [];
84 foreach ($response->getUserViews() as $user)
85 {
86 $userId = $user->getUserId();
87 $userViews[$userId] = [
88 'id' => $userId,
89 'avatarUrl' => $user->getUserAvatar(),
90 ];
91 }
92
93 $this->usersView = array_map(
94 static fn($userId) => $userViews[$userId] ?? ['id' => 0],
95 $userIds,
96 );
97 }
98
99 private function countFirstHundred(): int
100 {
101 $query = WorkflowInstanceTable::query();
102 $query->addSelect(new ExpressionField('CNT', 'COUNT(1)'));
103
104 $subQuery = WorkflowInstanceTable::query();
105 $subQuery->addSelect('ID');
106 $subQuery->addFilter('WORKFLOW_TEMPLATE_ID', $this->tplId);
107 $subQuery->setLimit(100);
108
109 $query->registerRuntimeField('',
110 new ReferenceField('M',
111 \Bitrix\Main\ORM\Entity::getInstanceByQuery($subQuery),
112 ['=this.ID' => 'ref.ID'],
113 ['join_type' => 'INNER']
114 )
115 );
116
117 $result = $query->exec()->fetch();
118
119 return (int)$result['CNT'];
120 }
121}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
__construct(int $tplId, bool $onlyHuman=false)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
$user
Определения mysql_to_pgsql.php:33
$response
Определения result.php:21
$rows
Определения options.php:264