3namespace Bitrix\Bizproc\UI;
5use Bitrix\Bizproc\Workflow\Entity\WorkflowUserCommentTable;
6use Bitrix\Bizproc\Workflow\WorkflowState;
7use Bitrix\Bizproc\WorkflowInstanceTable;
8use Bitrix\Main\EO_User;
9use Bitrix\Main\SystemException;
10use Bitrix\Main\Type\Collection;
11use Bitrix\Main\Type\DateTime;
12use Bitrix\Main\UserTable;
18 private array $myRunningTasks;
19 private array $myCompletedTasks;
31 $this->myRunningTasks = $this->getMyWaitingTasks();
32 $this->myCompletedTasks = $this->getMyCompletedTasks();
43 'id' => $this->
getId(),
45 'id' => $this->
getId(),
62 return $this->workflow->getId();
69 return current($this->
getTasks())[
'name'];
81 $documentService = \CBPRuntime::getRuntime()->getDocumentService();
83 return html_entity_decode(
84 $documentService->getDocumentName($this->workflow->getComplexDocumentId()) ??
''
102 return trim($task[
'description']);
110 return $this->workflow->getStateTitle();
115 if ($this->isCompleted ===
null)
117 $this->isCompleted = !WorkflowInstanceTable::exists($this->
getId());
125 $row = WorkflowUserCommentTable::getList([
127 '=WORKFLOW_ID' => $this->
getId(),
128 '=USER_ID' => $this->userId,
130 'select' => [
'UNREAD_CNT'],
133 return $row ? (int)$row[
'UNREAD_CNT'] : 0;
138 return $this->myRunningTasks;
143 foreach ($this->
getTasks() as $task)
145 if ($task[
'id'] === $taskId)
153 if ($task[
'id'] === $taskId)
161 [
'ID' => $taskId,
'USER_ID' => $this->userId],
185 return $preparedTasks[0] ??
null;
193 return $this->myCompletedTasks;
198 return $this->workflow->getStartedBy();
203 return \CBPViewHelper::formatDateTime($this->workflow->getModified());
208 $task = $this->
getTasks()[0] ??
null;
209 if (!$task || !isset($task[
'overdueDate']))
214 return DateTime::createFromUserTime($task[
'overdueDate']);
220 $currentUserId = $currentUser->getId();
221 if (!is_null($currentUserId) && (
int)$currentUserId === $this->workflow->getStartedBy())
224 'ID' => $currentUser->getId(),
225 'LOGIN' => $currentUser->getLogin(),
226 'NAME' => $currentUser->getFirstName(),
227 'SECOND_NAME' => $currentUser->getSecondName(),
228 'LAST_NAME' => $currentUser->getLastName(),
231 return UserTable::wakeUpObject(
$rows);
234 return \Bitrix\Main\UserTable::getByPrimary(
235 $this->workflow->getStartedBy(),
236 [
'select' => [
'ID',
'LOGIN',
'NAME',
'SECOND_NAME',
'LAST_NAME']]
251 private function getMyWaitingTasks():
array
255 $myTasks = array_filter(
256 $this->tasks[
'RUNNING'],
257 static function($task) use (
$userId) {
258 $waitingUsers = array_filter(
263 return in_array(
$userId, array_column($waitingUsers,
'USER_ID'));
270 private function getMyCompletedTasks():
array
274 $completedRunningTasks = array_filter(
275 $this->tasks[
'RUNNING'],
276 static function ($task) use (
$userId) {
277 $completedUsers = array_filter(
282 $taskUserIds = array_column($completedUsers,
'USER_ID');
283 Collection::normalizeArrayValuesByInt($taskUserIds);
285 return in_array(
$userId, $taskUserIds,
true);
289 $completedTasks = array_filter(
290 $this->tasks[
'COMPLETED'],
291 static function ($task) use (
$userId) {
292 $taskUserIds = array_column($task[
'USERS'],
'USER_ID');
293 Collection::normalizeArrayValuesByInt($taskUserIds);
295 return in_array(
$userId, $taskUserIds,
true);
299 return $this->
prepareTasks(array_values(array_merge($completedRunningTasks, $completedTasks)));
304 $isRpa = $this->workflow->getModuleId() ===
'rpa';
308 foreach ($myTasks as $task)
313 $users = array_filter(
314 $task[
'USERS'] ?? [],
321 $user = current($users);
326 $controls = $isRunning ? \CBPDocument::getTaskControls($task,
$userId) : [];
327 $buttons = $controls[
'BUTTONS'] ??
null;
328 if (!empty($buttons))
330 foreach ($buttons as &$button)
332 if (!empty($button[
'TEXT']))
341 $taskId = (int)$task[
'ID'];
344 'name' => html_entity_decode($task[
'~NAME']),
345 'description' => $task[
'~DESCRIPTION'],
346 'isInline' => \CBPHelper::getBool($task[
'IS_INLINE']),
348 'buttons' => $buttons,
349 'fields' => $controls[
'FIELDS'] ??
null,
351 'createdDate' => $task[
'~CREATED_DATE'] ??
null,
352 'delegationType' => $task[
'~DELEGATION_TYPE'] ??
null,
353 'overdueDate' => $task[
'~OVERDUE_DATE'] ??
null,
355 ?
"/rpa/task/id/$taskId/"
357 '/company/personal/bizproc/%s/?USER_ID=%d',
363 'isRunning' => $isRunning,
372 $this->workflow->fillTemplate();
374 $this->workflow->getModuleId() !==
'lists'
375 && !empty($this->workflow->getTemplate()?->getName())
378 return $this->workflow->getTemplate()?->getName();
381 $documentService = \CBPRuntime::getRuntime()->getDocumentService();
383 $complexDocumentType =
null;
386 $complexDocumentType = $documentService->getDocumentType($this->workflow->getComplexDocumentId());
391 return $complexDocumentType ? $documentService->getDocumentTypeCaption($complexDocumentType) :
null;
396 return \CBPViewHelper::getWorkflowResult($this->
getId(), $this->userId);
404 private function formatDateTime(
string $format, $datetime): ?string
408 $datetime = (string)$datetime;
411 if (is_string($datetime) && DateTime::isCorrect($datetime))
413 $timestamp = (
new DateTime($datetime))->getTimestamp();
423 return \Bitrix\Bizproc\UI\UserView::createFromId($this->
getAuthorId());
428 $complexDocumentId = $this->workflow->getComplexDocumentId();
430 return \CBPDocument::getDocumentAdminPage($complexDocumentId);
435 return $this->
getTasks()[0] ??
null;
440 $taskUsers = $task[
'USERS'] ?? [];
442 foreach ($taskUsers as
$user)
444 if ((
int)
$user[
'USER_ID'] === $this->userId)
455 $controls = \CBPDocument::getTaskControls($task, $this->userId);
456 $buttons = $controls[
'BUTTONS'] ??
null;
457 if (!empty($buttons))
459 foreach ($buttons as &$button)
461 if (!empty($button[
'TEXT']))
471 'buttons' => $buttons,
472 'fields' => $controls[
'FIELDS'] ??
null,
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
prepareTasks(array $myTasks)
getTaskControls(array $task)
__construct(WorkflowState $workflow, int $userId)
isRunningTaskUser(array $task)
static getTaskUsers($taskId)
static getList($arOrder=array("ID"=> "DESC"), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
static getWorkflowTasks($workflowId, $withUsers=false, $extendUserInfo=false)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
FormatDate($format="", $timestamp=false, $now=false, ?string $languageId=null)
htmlspecialcharsback($str)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)