403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/bizproc/lib/controller/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/bizproc/lib/controller/workflow.php
<?php

namespace Bitrix\Bizproc\Controller;

use Bitrix\Bizproc\Api\Request\WorkflowStateService\GetEfficiencyDataRequest;
use Bitrix\Main\Loader;
use Bitrix\Main\Error;
use Bitrix\Main\Localization\Loc;
use Bitrix\Bizproc\Api\Data\UserService\UsersToGet;
use Bitrix\Bizproc\Api\Request\WorkflowStateService\GetAverageWorkflowDurationRequest;
use Bitrix\Bizproc\Api\Request\WorkflowStateService\GetTimelineRequest;
use Bitrix\Bizproc\Api\Service\UserService;
use Bitrix\Bizproc\Api\Service\WorkflowStateService;
use Bitrix\Main\Engine\CurrentUser;
use Bitrix\Bizproc;

class Workflow extends Base
{
	private const PAGE_SIZE = 20;

	public function getTimelineAction(string $workflowId): ?array
	{
		$workflowStateService = new WorkflowStateService();

		$request = new GetTimelineRequest(workflowId: $workflowId, userId: CurrentUser::get()->getId());
		$response = $workflowStateService->getTimeline($request);
		$timeline = $response->getTimeline();

		if (!$timeline || !$response->isSuccess())
		{
			$this->addErrors($response->getErrors());

			return null;
		}

		$workflowState = $timeline->getWorkflowState();

		$userIds = [$workflowState->getStartedBy()];
		foreach ($timeline->getTasks() as $task)
		{
			$userIds = array_merge($userIds, $task->getTaskUserIds());
		}

		$userService = new UserService();

		$request = new UsersToGet($userIds);
		$response = $userService->getUsersView($request);

		if (!$response->isSuccess())
		{
			$this->addErrors($response->getErrors());

			return null;
		}

		$data = $timeline->jsonSerialize();
		$data['users'] = $response->getUserViews();
		$duration = $workflowStateService->getAverageWorkflowDuration(
			new GetAverageWorkflowDurationRequest($workflowState->getWorkflowTemplateId())
		)->getRoundedAverageDuration();
		$executionTime = $workflowStateService->getExecutionTime(
			new Bizproc\Api\Request\WorkflowStateService\GetExecutionTimeRequest(
				workflowId: $workflowState->getId(),
				workflowStarted: $workflowState->getStarted(),
				workflowModified: $workflowState->getModified()
			)
		)->getRoundedExecutionTime();
		$efficiencyData = $workflowStateService->getEfficiencyData(
			new GetEfficiencyDataRequest(
				executionTime: $executionTime ?? 0,
				averageDuration: $duration
			)
		);

		$data['stats'] = [
			'averageDuration' => $efficiencyData->getAverageDuration(),
			'efficiency' => $efficiencyData->getEfficiency(),
		];

		$data['biMenu'] = $this->getBiMenu($workflowState->getWorkflowTemplateId());

		return $data;
	}

	private function getBiMenu(int $workflowTemplateId): ?array
	{
		if (!Loader::includeModule('biconnector'))
		{
			return null;
		}

		if (!defined('\Bitrix\BIConnector\Superset\Scope\ScopeService::BIC_SCOPE_WORKFLOW_TEMPLATE'))
		{
			return null;
		}

		$menu = \Bitrix\BIConnector\Superset\Scope\ScopeService::getInstance()->prepareScopeMenuItem(
			\Bitrix\BIConnector\Superset\Scope\ScopeService::BIC_SCOPE_WORKFLOW_TEMPLATE,
			[
				'workflow_template_id' => $workflowTemplateId,
			]
		);

		return $menu ?: null;
	}

	public function terminateAction(string $workflowId): bool
	{
		$currentUserId = $this->getCurrentUser()?->getId();

		$workflowService = new \Bitrix\Bizproc\Api\Service\WorkflowService(
			accessService: new \Bitrix\Bizproc\Api\Service\WorkflowAccessService(),
		);

		$request = new Bizproc\Api\Request\WorkflowService\TerminateWorkflowRequest(
			workflowId: $workflowId,
			userId: $currentUserId,
		);

		$result = $workflowService->terminateWorkflow($request);
		if ($result->isSuccess())
		{
			return true;
		}

		$this->addErrors($result->getErrors());

		return false;
	}

	public function terminateByTemplateAction(int $templateId, string $signedDocument): bool
	{
		$currentUserId = $this->getCurrentUser()?->getId();

		$workflowService = new \Bitrix\Bizproc\Api\Service\WorkflowService(
			new \Bitrix\Bizproc\Api\Service\WorkflowAccessService(),
		);

		[$documentType, $documentCategoryId, $documentId] = \CBPDocument::unSignParameters($signedDocument);
		$complexDocumentId = [$documentType[0], $documentType[1], $documentId];

		$request = new Bizproc\Api\Request\WorkflowService\TerminateByTemplateRequest(
			$templateId,
			$complexDocumentId,
			$currentUserId,
		);

		$result = $workflowService->terminateWorkflowsByTemplate($request);
		if ($result->isSuccess())
		{
			return true;
		}

		$this->addErrors($result->getErrors());

		return false;
	}

	public function getTemplateInstancesAction(int $templateId, int $offset = 0): ?array
	{
		$template = Bizproc\Workflow\Template\Entity\WorkflowTemplateTable::getById($templateId)->fetchObject();
		$hasPermission = false;

		if ($template)
		{
			$hasPermission = \CBPDocument::canUserOperateDocumentType(
				\CBPCanUserOperateOperation::StartWorkflow,
				$this->getCurrentUser()->getId(),
				$template->getDocumentComplexType(),
			);
		}

		if (!$hasPermission)
		{
			$this->addError(new Error(Loc::getMessage('BIZPROC_CONTROLLER_WORKFLOW_TEMPLATE_NO_PRERMISSIONS')));

			return null;
		}

		$query = Bizproc\Workflow\Entity\WorkflowInstanceTable::query();
		$query->addFilter('WORKFLOW_TEMPLATE_ID', $templateId)
			->addSelect('ID')
			->setOrder(['STARTED' => 'ASC'])
			->setLimit(self::PAGE_SIZE + 1)
			->setOffset($offset)
		;
		$result = $query->exec();
		$ids = array_column($result->fetchAll(), 'ID');

		if (!$ids)
		{
			$this->addError(new Error(Loc::getMessage('BIZPROC_CONTROLLER_WORKFLOW_TEMPLATE_NO_LIST')));

			return null;
		}

		$hasNextPage = count($ids) > self::PAGE_SIZE;

		if ($hasNextPage)
		{
			$ids = array_slice($ids, 0, self::PAGE_SIZE);
		}

		return [
			'list' => array_map(
				static fn($id) => new Bizproc\UI\WorkflowFacesView($id),
				$ids,
			),
			'hasNextPage' => $hasNextPage,
		];
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit