1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
timelinetask.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\Workflow\Task;
4
5use Bitrix\Bizproc\UI\Helpers\DurationFormatter;
6use Bitrix\Bizproc\Workflow\Task;
7use Bitrix\Main\Type\DateTime;
8
9class TimelineTask implements \JsonSerializable
10{
11 private Task $task;
12 private ?int $userId = null;
13 private ?string $approveType = null;
14
15 public function __construct(Task $task)
16 {
17 $this->task = $task;
18 if ($this->hasApproveType())
19 {
20 $parameters = $this->task->getParameters();
21 $this->approveType = is_string($parameters['ApproveType'] ?? null) ? $parameters['ApproveType'] : 'all';
22 }
23 }
24
25 public function setUserId(int $userId): static
26 {
27 $this->userId = $userId;
28
29 return $this;
30 }
31
32 public function calculateExecutionTime(): ?int
33 {
34 $createdDate = $this->getCreatedDate();
35 if (isset($createdDate))
36 {
37 $duration = (
38 $this->task->isCompleted()
39 ? $this->task->getModified()->getTimestamp() - $createdDate->getTimestamp()
40 : (new DateTime())->getTimestamp() - $createdDate->getTimestamp()
41 );
42
43 return DurationFormatter::roundTimeInSeconds($duration, 2);
44 }
45
46 return null;
47 }
48
52 public function getTaskUserIds(): array
53 {
54 $ids = [];
55 foreach ($this->task->getTaskUsers() as $taskUser)
56 {
57 $ids[] = $taskUser->getUserId();
58 }
59
60 return $ids;
61 }
62
63 private function checkViewRights(): bool
64 {
65 return isset($this->userId) && $this->task->hasViewRights($this->userId);
66 }
67
68 public function jsonSerialize(): array
69 {
70 $users = [];
71 if (!$this->checkViewRights())
72 {
73 return [
74 'canView' => false,
75 'status' => $this->task->getStatus(),
76 ];
77 }
78
79 foreach ($this->task->getTaskUsers() as $taskUser)
80 {
81 $userData = [
82 'id' => $taskUser->getUserId(),
83 'status' => $taskUser->getStatus(),
84 ];
85
86 if ($taskUser->hasDateUpdate() && $taskUser->get('DATE_UPDATE') !== null)
87 {
88 $dateUpdate = $taskUser->get('DATE_UPDATE');
89 }
90 else
91 {
92 $dateUpdate = new DateTime();
93 }
94
95 if ($this->getCreatedDate())
96 {
97 $userData['executionTime'] = $dateUpdate->getTimestamp() - $this->getCreatedDate()->getTimestamp();
98 }
99
100 $users[] = $userData;
101 }
102
103 $viewData = [
104 'canView' => true,
105 'id' => $this->task->getId(),
106 'name' => html_entity_decode($this->task->getName()),
107 'status' => $this->task->getStatus(),
108 'modified' => $this->task->getModified()->getTimestamp(),
109 'executionTime' => $this->calculateExecutionTime(),
110 'users' => $users,
111 'url' => $this->getTaskUrl(),
112 ];
113
114 if ($this->approveType)
115 {
116 $viewData['approveType'] = $this->approveType;
117 }
118
119 return $viewData;
120 }
121
122 private function getCreatedDate(): ?DateTime
123 {
124 return $this->task->hasCreatedDate() ? $this->task->get('CREATED_DATE') : null;
125 }
126
127 private function getTaskUrl(): ?string
128 {
129 $url = sprintf(
130 '/company/personal/bizproc/%s/',
131 $this->task->getId(),
132 );
133
134 if ($this->task->isFilled('PARAMETERS') && isset($this->task->getParameters()['DOCUMENT_ID'][0]))
135 {
136 $moduleId = $this->task->getParameters()['DOCUMENT_ID'][0];
137 $url = ($moduleId === 'rpa') ? "/rpa/task/id/{$this->task->getId()}/" : $url;
138 }
139
140 return $url;
141 }
142
143 public function hasApproveType(): int
144 {
145 return in_array(
146 $this->task->getActivity(),
147 [
148 'ApproveActivity',
149 'ReviewActivity',
150 ],
151 true,
152 );
153 }
154}
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$moduleId
$url
Определения iframe.php:7