3namespace Bitrix\Lists\Api\Service;
5use Bitrix\Bizproc\Workflow\Entity\EO_WorkflowMetadata;
6use Bitrix\Lists\Api\Request\WorkflowService\StartWorkflowsRequest;
7use Bitrix\Lists\Api\Response\Response;
8use Bitrix\Lists\Api\Response\WorkflowService\GetParameterValuesResponse;
9use Bitrix\Lists\Api\Response\WorkflowService\StartWorkflowsResponse;
11use Bitrix\Main\Loader;
12use Bitrix\Main\Localization\Loc;
16 private string $iBlockTypeId;
17 private bool $isBpEnabled;
18 private ?
array $complexDocumentType;
22 $this->iBlockTypeId = (string)($iBlockInfo[
'IBLOCK_TYPE_ID'] ??
'');
24 $this->isBpEnabled = (
25 Loader::includeModule(
'bizproc')
26 && \CLists::isBpFeatureEnabled($this->iBlockTypeId)
27 && (isset($iBlockInfo[
'BIZPROC']) && $iBlockInfo[
'BIZPROC'] ===
'Y')
30 $this->complexDocumentType = (
34 max((
int)($iBlockInfo[
'ID'] ?? 0), 0)
42 if ($this->isBpEnabled)
44 return \CBPDocument::signParameters([$this->complexDocumentType, (
string)$elementId]);
52 if ($elementId < 0 ||
$userId <= 0)
58 if ($this->isBpEnabled)
63 $parameters = [
'AllUserGroups' => $userGroups];
67 ? \CBPDocument::canUserOperateDocument($operation,
$userId, $complexDocumentId, $parameters)
68 : \CBPDocument::canUserOperateDocumentType($operation,
$userId, $this->complexDocumentType, $parameters)
77 if ($currentUserId <= 0 || $elementId < 0 || $sectionId < 0)
83 if ($this->isBpEnabled)
87 $canStart = \CBPDocument::canUserOperateDocumentType(
90 $this->complexDocumentType,
91 [
'sectionId' => $sectionId,
'DocumentStates' => $documentStates]
100 $isConstantsTuned =
true;
101 if ($this->isBpEnabled)
103 $templates = array_merge(
104 \CBPWorkflowTemplateLoader::searchTemplatesByDocumentType(
107 \CBPWorkflowTemplateLoader::searchTemplatesByDocumentType(
114 if (!\CBPWorkflowTemplateLoader::isConstantsTuned(
$template[
'ID']))
116 $isConstantsTuned =
false;
123 return $isConstantsTuned;
128 $hasParameters =
false;
129 if ($this->isBpEnabled)
132 foreach ($states as $state)
134 $parameters = $state[
'TEMPLATE_PARAMETERS'] ?? [];
135 if (!empty($parameters) && is_array($parameters))
137 $hasParameters =
true;
144 return $hasParameters;
152 if ($this->isBpEnabled && $elementId >= 0)
155 foreach ($documentStates as $state)
157 if (empty($state[
'ID']))
160 $parameters[$state[
'TEMPLATE_ID']] = \CBPWorkflowTemplateLoader::checkWorkflowParameters(
161 $state[
'TEMPLATE_PARAMETERS'] ?? [],
162 $request[$state[
'TEMPLATE_ID']] ?? [],
163 $this->complexDocumentType,
175 return $response->setParameters($parameters);
186 Loc::getMessage(
'LISTS_LIB_API_WORKFLOW_SERVICE_INCORRECT_START_WORKFLOW_INPUT_DATA') ??
''
192 if ($this->isBpEnabled &&
$response->isSuccess())
195 $documentStates = $this->
getDocumentStates($request->isNewElement ?
null : $complexDocumentId);
196 foreach ($documentStates as $state)
198 if (empty($state[
'ID']))
202 $startWorkflowParameters = [
203 \CBPDocument::PARAM_TAGRET_USER =>
'user_' .
$request->currentUserId,
204 \CBPDocument::PARAM_MODIFIED_DOCUMENT_FIELDS =>
$request->changedFields,
207 $workflowIds[$state[
'TEMPLATE_ID']] = \CBPDocument::startWorkflow(
208 $state[
'TEMPLATE_ID'],
210 array_merge(
$request->parameters[$state[
'TEMPLATE_ID']] ?? [], $startWorkflowParameters),
217 $metadata->setWorkflowId($workflowIds[$state[
'TEMPLATE_ID']]);
218 $metadata->setStartDuration(
$request->timeToStart);
230 return $response->setWorkflowIds($workflowIds);
235 if ($this->isBpEnabled)
245 return $this->complexDocumentType;
250 if ($this->isBpEnabled)
252 return \CBPDocument::getDocumentStates($this->complexDocumentType, $complexDocumentId);
260 if (!$this->isBpEnabled)
267 return \CBPWorkflowTemplateLoader::getDocumentTypeStates($this->complexDocumentType, $autoExecuteType);
272 if (!$this->isBpEnabled)
277 $states = array_merge(
284 foreach ($states as $state)
293 $state[
'TEMPLATE_CONSTANTS'] = \CBPWorkflowTemplateLoader::getTemplateConstants(
$templateId);
302 if (!$this->isBpEnabled)
309 ? \CBPWorkflowTemplateLoader::searchTemplatesByDocumentType(
312 : \CBPWorkflowTemplateLoader::searchTemplatesByDocumentType(
317 return !empty($templates);
322 if ($elementId < 0 || !$this->isBpEnabled)
330 $parameters = $documentState[
'TEMPLATE_PARAMETERS'] ?? [];
331 if (!empty($parameters))
333 $states[] = $documentState;
343 if ($this->isBpEnabled)
348 if (\CBPWorkflowTemplateLoader::isConstantsTuned(
$templateId))
353 $notTuned[] = $state;
365 if ($this->isBpEnabled)
373 $values = \CBPWorkflowTemplateLoader::checkWorkflowParameters(
374 $state[
'TEMPLATE_CONSTANTS'],
376 $this->complexDocumentType,
382 if (!empty(
$error[
'message']))
390 foreach ($state[
'TEMPLATE_CONSTANTS'] as $id => $property)
392 $property[
'Default'] = $values[$id] ??
null;
403 \CBPWorkflowTemplateLoader::update(
$templateId, [
'CONSTANTS' => $constants]);
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
getParameterValuesFromRequest(array $request, int $elementId)
startWorkflows(StartWorkflowsRequest $request)
getDocumentStates(?array $complexDocumentId)
setConstants(array $request)
getNotTunedDocumentTypeStates()
canUserStartWorkflow(int $currentUserId, int $elementId, int $sectionId=0)
getComplexDocumentId(int $elementId)
getDocumentStatesWithParameters(int $elementId)
canUserWriteDocument(int $elementId, int $userId, array $userGroups)
getNotRunningDocumentStates(int $elementId)
hasTemplatesOnStartup(?array $complexDocumentId=null)
getSignedDocument(int $elementId)
hasParameters(int $elementId)
__construct(array $iBlockInfo)
static getDocumentComplexId($iblockType, $documentId)
static generateDocumentComplexType($iblockType, $iblockId)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)