3namespace Bitrix\Bizproc\UI;
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;
15 private int $allCount;
16 private array $usersView = [];
19 public function __construct(
int $tplId,
bool $onlyHuman =
false)
21 $this->tplId = $tplId;
27 $query = WorkflowInstanceTable::query();
28 $query->addFilter(
'WORKFLOW_TEMPLATE_ID', $this->tplId)
29 ->addSelect(
'STARTED_BY')
30 ->addSelect(
'STARTED')
31 ->setOrder([
'STARTED' =>
'ASC'])
36 $query->whereNotNull(
'STARTED_BY');
41 $this->allCount =
$result->getSelectedRowsCount() >= 3
42 ? $this->countFirstHundred()
43 :
$result->getSelectedRowsCount()
46 $userIds = array_column(
$rows,
'STARTED_BY');
47 $this->lastActivity =
$rows[0][
'STARTED'] ??
null;
50 $this->loadUsersView($userIds);
61 return $this->lastActivity;
67 'tplId' => $this->tplId,
68 'allCount' => $this->allCount,
69 'users' => $this->usersView,
73 private function loadUsersView(
array $userIds): void
89 'avatarUrl' =>
$user->getUserAvatar(),
93 $this->usersView = array_map(
99 private function countFirstHundred(): int
101 $query = WorkflowInstanceTable::query();
102 $query->addSelect(
new ExpressionField(
'CNT',
'COUNT(1)'));
104 $subQuery = WorkflowInstanceTable::query();
105 $subQuery->addSelect(
'ID');
106 $subQuery->addFilter(
'WORKFLOW_TEMPLATE_ID', $this->tplId);
107 $subQuery->setLimit(100);
109 $query->registerRuntimeField(
'',
110 new ReferenceField(
'M',
111 \
Bitrix\Main\ORM\Entity::getInstanceByQuery($subQuery),
112 [
'=this.ID' =>
'ref.ID'],
113 [
'join_type' =>
'INNER']
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
loadInstances(bool $onlyHuman)
__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)