1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
WorkflowUserDetailView.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\UI;
4
5use Bitrix\Bizproc\Workflow\Entity\WorkflowUserTable;
6use Bitrix\Main\Type\DateTime;
7
9{
10 protected ?array $task = null;
11 private int $taskId = 0;
12 protected ?DateTime $modified = null;
13
14 public function setTaskId(int $taskId): static
15 {
16 $this->taskId = $taskId;
17
18 return $this;
19 }
20
21 public function jsonSerialize(): array
22 {
23 $userView = \Bitrix\Bizproc\UI\UserView::createFromId($this->userId);
24
25 return [
26 'workflowId' => $this->getId(),
27 'typeName' => $this->getTypeName(),
28 'name' => $this->getName(),
29 'description' => $this->getDescription(),
30 'documentUrl' => $this->getDocumentUrl(),
31 'task' => $this->extractTask() ?: null,
32 'userName' => $userView?->getFullName(),
33 'modified' => $this->getTime(),
34 'status' => $this->getStatusText(),
35 'result' => $this->getIsCompleted() ? $this->getWorkflowResult() : null,
36 ];
37 }
38
39 public function getTime(): string
40 {
41 if (is_null($this->modified))
42 {
43 $row = WorkflowUserTable::getByPrimary(
44 ['USER_ID' => $this->userId, 'WORKFLOW_ID' => $this->workflow->getId()],
45 ['select' => ['MODIFIED']]
46 )->fetch();
47 if ($row)
48 {
49 $this->modified = $row['MODIFIED'];
50 }
51 }
52
53 return \CBPViewHelper::formatDateTime($this->modified);
54 }
55
56 public function getName(): mixed
57 {
58 $task = $this->extractTask();
59 if ($task)
60 {
61 return $task['name'];
62 }
63
64 return parent::getName();
65 }
66
67 public function getDescription(): ?string
68 {
69 return \CBPViewHelper::prepareTaskDescription(
70 \CBPHelper::convertBBtoText(
71 preg_replace('|\n+|', "\n", trim($this->getClearDescription()))
72 )
73 );
74 }
75
76 protected function getClearDescription(): string
77 {
78 $task = $this->extractTask();
79 if ($task && isset($task['description']))
80 {
81 return (string)$task['description'];
82 }
83
84 return (string)parent::getDescription();
85 }
86
87 protected function extractTask(): ?array
88 {
89 if (is_null($this->task))
90 {
91 $this->task = $this->getFirstRunningTask() ?? [];
92
93 if ($this->taskId > 0)
94 {
95 $task = $this->getTaskById($this->taskId);
96 if ($task)
97 {
98 $this->task = $task;
99 }
100 }
101
102 if (!$this->task && !$this->isWorkflowAuthorView() && $this->getCompletedTasks())
103 {
104 $this->task = current($this->getCompletedTasks());
105 }
106 }
107
108 return $this->task;
109 }
110
111 public function getExtractedTaskId(): ?int
112 {
113 $task = $this->extractTask();
114
115 return $task ? (int)$task['id'] : null;
116 }
117
118 protected function prepareTasks(array $myTasks): array
119 {
120 $tasks = [];
121 foreach ($myTasks as $task)
122 {
123 $isRunning = (int)$task['STATUS'] === \CBPTaskStatus::Running;
124 if ($isRunning)
125 {
126 $isRunning = $this->isRunningTaskUser($task);
127 }
128
129 $taskId = (int)$task['ID'];
130 $tasks[] = [
131 'id' => $taskId,
132 'name' => html_entity_decode($task['~NAME']),
133 'description' => $task['~DESCRIPTION'],
134 'userId' => $this->userId,
135 'controls' => $isRunning ? $this->getTaskControls($task) : [],
136 'isRunning' => $isRunning,
137 'activityName' => $task['~ACTIVITY_NAME'],
138 'activity' => $task['~ACTIVITY'],
139 'saveVariables' => $task['~PARAMETERS']['SaveVariables'] ?? false,
140 'delegationType' => $task['~DELEGATION_TYPE'] ?? null,
141 ];
142 }
143
144 return $tasks;
145 }
146}
static createFromId(int $userId)
Определения UserView.php:13
getTaskControls(array $task)
Определения WorkflowUserView.php:453
getTaskById(int $taskId)
Определения WorkflowUserView.php:141
isRunningTaskUser(array $task)
Определения WorkflowUserView.php:438
const Running
Определения constants.php:258
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804