22 private static function getRestActivityData()
24 if (!isset(static::$restActivityData[static::REST_ACTIVITY_ID]))
26 $result = RestActivityTable::getById(static::REST_ACTIVITY_ID);
28 static::$restActivityData[static::REST_ACTIVITY_ID] = $row ?: [];
31 return static::$restActivityData[static::REST_ACTIVITY_ID];
36 parent::__construct(
$name);
38 $activityData = self::getRestActivityData();
39 $this->arProperties = [
42 isset($activityData[
'USE_SUBSCRIPTION']) && $activityData[
'USE_SUBSCRIPTION'] ===
'Y'
47 'AuthUserId' => isset($activityData[
'AUTH_USER_ID']) ?
'user_' . $activityData[
'AUTH_USER_ID'] :
null,
48 'SetStatusMessage' =>
'Y',
49 'StatusMessage' =>
'',
50 'TimeoutDuration' => 0,
51 'TimeoutDurationType' =>
's',
54 if (!empty($activityData[
'PROPERTIES']))
56 foreach ($activityData[
'PROPERTIES'] as $propertyName => $property)
58 if (isset($this->arProperties[$propertyName]))
62 $this->arProperties[$propertyName] = $property[
'DEFAULT'] ??
null;
67 if (!empty($activityData[
'RETURN_PROPERTIES']))
69 foreach ($activityData[
'RETURN_PROPERTIES'] as $returnPropertyName => $property)
71 if (isset($this->arProperties[$returnPropertyName]))
75 $this->arProperties[$returnPropertyName] = $property[
'DEFAULT'] ??
null;
76 if (isset($property[
'TYPE']))
78 $types[$returnPropertyName] = [
79 'Type' => $property[
'TYPE'],
80 'Multiple' => CBPHelper::getBool($property[
'MULTIPLE']),
81 'Options' => $property[
'OPTIONS'] ??
null,
86 $types[
'IsTimeout'] = [
89 $this->SetPropertiesTypes($types);
94 parent::ReInitialize();
97 $this->eventId =
null;
98 $activityData = self::getRestActivityData();
99 if (!empty($activityData[
'RETURN_PROPERTIES']))
101 foreach ($activityData[
'RETURN_PROPERTIES'] as
$name => $property)
103 $this->
__set(
$name, $property[
'DEFAULT'] ??
null);
110 $activityData = static::getRestActivityData();
114 throw new Exception(Loc::getMessage(
'BPRA_NOT_FOUND_ERROR'));
117 if (!Loader::includeModule(
'rest') || !\Bitrix\Rest\OAuthService::getEngine()->isRegistered())
122 $properties = $activityData[
'PROPERTIES'];
123 $propertiesValues = [];
124 if (!empty($properties))
127 $documentService = $this->workflow->GetService(
'DocumentService');
128 foreach ($properties as
$name => $property)
130 $property = static::normalizeProperty($property);
131 $properties[
$name] = $property;
134 if ($propertiesValues[
$name])
136 $fieldTypeObject = $documentService->getFieldTypeObject($this->GetDocumentType(), $property);
137 if ($fieldTypeObject)
139 $fieldTypeObject->setDocumentId($this->GetDocumentId());
140 $propertiesValues[
$name] = $fieldTypeObject->externalizeValue(
142 $propertiesValues[
$name]
147 if ($propertiesValues[
$name] ===
null)
149 $propertiesValues[
$name] =
'';
153 if ($this->workflow->isDebug())
159 $this->writeDebugInfo(
$map);
163 $dbRes = \Bitrix\Rest\AppTable::getList([
165 '=CLIENT_ID' => $activityData[
'APP_ID'],
172 throw new Exception(
'Rest application not found.');
175 $appStatus = \Bitrix\Rest\AppTable::getAppStatusInfo(
$application,
'');
176 if ($appStatus[
'PAYMENT_ALLOW'] ===
'N')
178 throw new Exception(
'Rest application status error: payment required');
181 $userId = CBPHelper::ExtractUsers($this->AuthUserId, $this->GetDocumentId(),
true);
182 if (empty(
$userId) && !empty($activityData[
'AUTH_USER_ID']))
184 $userId = $activityData[
'AUTH_USER_ID'];
190 'CODE' => $activityData[
'CODE'],
191 \Bitrix\Rest\OAuth\Auth::PARAM_LOCAL_USER =>
$userId,
192 "application_token" => \CRestUtil::getApplicationToken(
$application),
195 $this->eventId = \Bitrix\Main\Security\Random::getString(32,
true);
197 $queryItem = Sqs::queryItem(
198 $activityData[
'APP_ID'],
199 $activityData[
'HANDLER'],
202 'code' => $activityData[
'CODE'],
203 'document_id' => $this->GetDocumentId(),
204 'document_type' => $this->GetDocumentType(),
206 'properties' => $propertiesValues,
207 'use_subscription' => $this->UseSubscription,
208 'timeout_duration' => $this->CalculateTimeoutDuration(),
214 "sendRefreshToken" =>
true,
215 "category" => Sqs::CATEGORY_BIZPROC,
219 if ($activityData[
'IS_ROBOT'] ===
'Y')
221 \Bitrix\Rest\UsageStatTable::logRobot($activityData[
'APP_ID'], $activityData[
'CODE']);
225 \Bitrix\Rest\UsageStatTable::logActivity($activityData[
'APP_ID'], $activityData[
'CODE']);
228 if (is_callable([\Bitrix\Rest\Event\Sender::class,
'queueEvent']))
230 \Bitrix\Rest\Event\Sender::queueEvent($queryItem);
234 \Bitrix\Rest\OAuthService::getEngine()->getClient()->sendEvent([$queryItem]);
235 \Bitrix\Rest\UsageStatTable::finalize();
238 if ($this->SetStatusMessage ===
'Y')
243 $message = Loc::getMessage(
'BPRA_DEFAULT_STATUS_MESSAGE');
248 if ($this->UseSubscription !==
'Y')
253 $this->Subscribe($this);
260 $timeoutDuration = $this->CalculateTimeoutDuration();
261 if ($timeoutDuration > 0)
263 $schedulerService = $this->workflow->GetService(
'SchedulerService');
264 $this->subscriptionId = $schedulerService->SubscribeOnTime(
265 $this->workflow->GetInstanceId(),
267 time() + $timeoutDuration
271 $this->workflow->AddEventHandler($this->name, $eventHandler);
276 if ($this->subscriptionId > 0)
278 $schedulerService = $this->workflow->GetService(
"SchedulerService");
279 $schedulerService->UnSubscribeOnTime($this->subscriptionId);
280 $this->subscriptionId = 0;
283 $this->eventId =
null;
284 $this->workflow->RemoveEventHandler($this->name, $eventHandler);
294 $onAgent = (array_key_exists(
'SchedulerService', $eventParameters) && $eventParameters[
'SchedulerService'] ===
'OnAgent');
297 $this->IsTimeout = 1;
298 $this->Unsubscribe($this);
299 $this->workflow->CloseActivity($this);
304 if ($this->eventId !== (
string)$eventParameters[
'EVENT_ID'])
309 $this->WriteToTrackingService(
310 !empty($eventParameters[
'LOG_MESSAGE']) && is_string($eventParameters[
'LOG_MESSAGE'])
311 ? $eventParameters[
'LOG_MESSAGE']
312 : Loc::getMessage(
'BPRA_DEFAULT_LOG_MESSAGE')
315 if (!empty($eventParameters[
'RETURN_VALUES']))
317 $activityData = self::getRestActivityData();
318 $whiteList =
array();
319 if (!empty($activityData[
'RETURN_PROPERTIES']))
321 foreach ($activityData[
'RETURN_PROPERTIES'] as
$name => $property)
328 $documentService = $this->workflow->GetService(
'DocumentService');
329 $eventParameters[
'RETURN_VALUES'] = array_change_key_case(
330 (
array)$eventParameters[
'RETURN_VALUES'],
333 foreach ($eventParameters[
'RETURN_VALUES'] as
$name => $value)
335 if (!isset($whiteList[
$name]))
340 $property = $activityData[
'RETURN_PROPERTIES'][$whiteList[
$name]];
341 if ($property && $value)
343 $property = static::normalizeProperty($property);
344 $fieldTypeObject = $documentService->getFieldTypeObject($this->GetDocumentType(), $property);
345 if ($fieldTypeObject)
347 $fieldTypeObject->setDocumentId($this->GetDocumentId());
348 $value = $fieldTypeObject->internalizeValue($this->GetName(), $value);
351 if ($this->workflow->isDebug())
357 $this->writeDebugInfo(
$map);
365 if (empty($eventParameters[
'LOG_ACTION']))
367 $this->Unsubscribe($this);
368 $this->workflow->CloseActivity($this);
379 $this->writeDebugTrack(
382 $this->executionStatus,
383 $this->executionResult,
388 $this->Unsubscribe($this);
389 $this->workflow->CloseActivity($this);
394 if ($this->UseSubscription ===
'Y')
396 $this->Unsubscribe($this);
411 $currentSiteId =
null,
412 $workflowConstants =
null
420 $activityData = self::getRestActivityData();
422 $dbRes = \Bitrix\Rest\AppTable::getList([
425 '=CLIENT_ID' => $activityData[
'APP_ID'],
435 $dialog = new \Bitrix\Bizproc\Activity\PropertiesDialog(__FILE__, [
436 'documentType' => $documentType,
437 'activityName' => $activityName,
438 'workflowTemplate' => $workflowTemplate,
439 'workflowParameters' => $workflowParameters,
440 'workflowVariables' => $workflowVariables,
442 'formName' => $formName,
443 'workflowConstants' => $workflowConstants,
448 'Name' => Loc::getMessage(
"BPRA_PD_USER_ID"),
449 'FieldName' =>
'authuserid',
451 'Default' =>
'user_' . $activityData[
'AUTH_USER_ID'],
453 'SetStatusMessage' => [
454 'Name' =>
'SetStatusMessage',
455 'FieldName' =>
'setstatusmessage',
459 'Name' =>
'StatusMessage',
460 'FieldName' =>
'statusmessage',
462 'Default' => Loc::getMessage(
'BPRA_DEFAULT_STATUS_MESSAGE'),
464 'UseSubscription' => [
465 'Name' =>
'StatusMessage',
466 'FieldName' =>
'usesubscription',
468 'Default' => $activityData[
'USE_SUBSCRIPTION'],
470 'TimeoutDuration' => [
471 'Name' =>
'StatusMessage',
472 'FieldName' =>
'timeoutduration',
475 'TimeoutDurationType' => [
476 'Name' =>
'StatusMessage',
477 'FieldName' =>
'timeoutdurationtype',
483 $properties = isset($activityData[
'PROPERTIES']) && is_array($activityData[
'PROPERTIES']) ? $activityData[
'PROPERTIES'] : [];
484 foreach ($properties as
$name => $property)
491 'FieldName' => static::PROPERTY_NAME_PREFIX . mb_strtolower(
$name),
492 'Type' => $property[
'TYPE'] ??
'string',
493 'Required' => $property[
'REQUIRED'] ??
false,
494 'Multiple' => $property[
'MULTIPLE'] ??
false,
495 'Default' => $property[
'DEFAULT'] ??
null,
496 'Options' => $property[
'OPTIONS'] ??
null,
501 $appPlacement =
null;
502 if (!empty($activityData[
'APP_ID_INT']))
504 $appPlacement = self::getAppPlacement($activityData[
'APP_ID_INT'], $activityData[
'CODE']);
510 'ACTIVITY_DATA' => $activityData,
511 'IS_ADMIN' => static::checkAdminPermissions(),
512 'APP_PLACEMENT' => $appPlacement,
514 ->setRenderer([__CLASS__,
'renderPropertiesDialog']);
519 private static function getAppPlacement(
int $appId,
string $code): ?
array
521 $result = \Bitrix\Rest\PlacementTable::getList([
524 '=ADDITIONAL' =>
$code,
532 public static function renderPropertiesDialog(\Bitrix\Bizproc\Activity\PropertiesDialog $dialog)
534 $runtime = CBPRuntime::GetRuntime();
535 $data = $dialog->getRuntimeData();
536 $activityData =
$data[
'ACTIVITY_DATA'];
539 $documentService = $runtime->GetService(
"DocumentService");
540 $activityDocumentType = is_array($activityData[
'DOCUMENT_TYPE']) ? $activityData[
'DOCUMENT_TYPE'] : $dialog->getDocumentType();
541 $properties = isset($activityData[
'PROPERTIES']) && is_array($activityData[
'PROPERTIES']) ? $activityData[
'PROPERTIES'] :
array();
545 $appPlacement =
$data[
'APP_PLACEMENT'];
546 $placementSid =
null;
547 $appCurrentValues = [];
553 foreach ($properties as
$key => $property)
555 $appCurrentValues[
$key] = $dialog->getCurrentValue(
'property_'.mb_strtolower(
$key));
559 echo
'<tr><td align="right" colspan="2">';
564 'ID' => $appPlacement[
'APP_ID'],
566 'PLACEMENT_ID' => $appPlacement[
'ID'],
567 "PLACEMENT_OPTIONS" => [
568 'code' => $activityData[
'CODE'],
569 'activity_name' => $dialog->getActivityName(),
570 'properties' => $properties,
571 'current_values' => $appCurrentValues,
572 'document_type' => $dialog->getDocumentType(),
573 'document_fields' => $documentService->GetDocumentFields($dialog->getDocumentType()),
574 'template' => $dialog->getTemplateExpressions(),
577 'FRAME_WIDTH' =>
'100%',
578 'FRAME_HEIGHT' =>
'350px'
582 array(
'HIDE_ICONS' =>
'Y')
587 foreach ($properties as
$name => $property):
592 $property[
'NAME'] = RestActivityTable::getLocalization($property[
'NAME'], LANGUAGE_ID);
593 if (isset($property[
'DESCRIPTION']))
595 $property[
'DESCRIPTION'] = RestActivityTable::getLocalization($property[
'DESCRIPTION'], LANGUAGE_ID);
601 <span
class=
"<?=$required?'adm-required-field':''?>">
604 <?
if (!empty($property[
'DESCRIPTION'])):?>
609 <?=$documentService->getFieldInputControl(
610 $activityDocumentType,
612 array(
'Field' => static::PROPERTY_NAME_PREFIX.
$name,
'Form' => $dialog->getFormName()),
625 if (static::checkAdminPermissions()):?>
627 <td
align=
"right" width=
"40%" valign=
"top"><span
class=
""><?= Loc::getMessage(
"BPRA_PD_USER_ID") ?>:</span></td>
629 <?=$dialog->renderFieldControl(
'AuthUserId',
$currentValues[
'authuserid'],
true, 0)?>
634 <td
align=
"right"><?= Loc::getMessage(
"BPRA_PD_SET_STATUS_MESSAGE") ?>:</td>
636 <
select name=
"setstatusmessage">
637 <option value=
"Y"<?=
$currentValues[
"setstatusmessage"] ===
"Y" ?
" selected" :
"" ?>><?= Loc::getMessage(
"BPRA_PD_YES") ?></option>
638 <option value=
"N"<?=
$currentValues[
"setstatusmessage"] ===
"N" ?
" selected" :
"" ?>><?= Loc::getMessage(
"BPRA_PD_NO") ?></option>
643 <td
align=
"right"><?= Loc::getMessage(
"BPRA_PD_STATUS_MESSAGE") ?>:</td>
644 <td valign=
"top"><?=CBPDocument::ShowParameterField(
"string",
'statusmessage',
$currentValues[
'statusmessage'], Array(
'size'=>
'45'))?></td>
647 <td
align=
"right"><?= Loc::getMessage(
"BPRA_PD_USE_SUBSCRIPTION") ?>:</td>
649 <
select name=
"usesubscription" <?=!empty($activityData[
'USE_SUBSCRIPTION'])?
'disabled' :
''?>>
650 <option value=
"Y"<?=
$currentValues[
"usesubscription"] ===
'Y' ?
" selected" :
"" ?>><?= Loc::getMessage(
"BPRA_PD_YES") ?></option>
651 <option value=
"N"<?=
$currentValues[
"usesubscription"] ===
'N' ?
" selected" :
"" ?>><?= Loc::getMessage(
"BPRA_PD_NO") ?></option>
655 <?
if ($activityData[
'USE_SUBSCRIPTION'] !==
'N'):?>
657 <td
align=
"right"><?= Loc::getMessage(
"BPRA_PD_TIMEOUT_DURATION") ?>:<br/><?= Loc::getMessage(
"BPRA_PD_TIMEOUT_DURATION_HINT") ?></td>
659 <?=CBPDocument::ShowParameterField(
'int',
'timeoutduration',
$currentValues[
"timeoutduration"],
array(
'size' => 20))?>
660 <
select name=
"timeoutdurationtype">
661 <option value=
"s"<?= (
$currentValues[
"timeoutdurationtype"] ===
"s") ?
" selected" :
"" ?>><?= Loc::getMessage(
"BPRA_PD_TIME_S") ?></option>
662 <option value=
"m"<?= (
$currentValues[
"timeoutdurationtype"] ===
"m") ?
" selected" :
"" ?>><?= Loc::getMessage(
"BPRA_PD_TIME_M") ?></option>
663 <option value=
"h"<?= (
$currentValues[
"timeoutdurationtype"] ===
"h") ?
" selected" :
"" ?>><?= Loc::getMessage(
"BPRA_PD_TIME_H") ?></option>
664 <option value=
"d"<?= (
$currentValues[
"timeoutdurationtype"] ===
"d") ?
" selected" :
"" ?>><?= Loc::getMessage(
"BPRA_PD_TIME_D") ?></option>
667 $delayMinLimit = CBPSchedulerService::getDelayMinLimit();
670 <p
style=
"color: red;">* <?= Loc::getMessage(
"BPRA_PD_TIMEOUT_LIMIT") ?>: <?=CBPHelper::FormatTimePeriod($delayMinLimit)?></p>
678 if ($placementSid):?>
682 var appLayout = BX.rest.AppLayout.get(
'<?=CUtil::JSEscape($placementSid)?>');
683 var properties = <?=\Bitrix\Main\Web\Json::encode($properties)?>;
684 var values = <?=\Bitrix\Main\Web\Json::encode($appCurrentValues)?>;
685 var form = document.forms[
'<?=CUtil::JSEscape($dialog->getFormName())?>'];
687 function setValueToForm(name, value)
689 name =
'property_' + name.toLowerCase();
690 if (BX.type.isArray(value))
699 Array.from(form.querySelectorAll(
'[name="'+name+
'"]')).forEach(function(element)
704 value.forEach(function(val)
706 form.appendChild(BX.create(
'input', {
716 var placementInterface = appLayout.messageInterface;
717 placementInterface.setPropertyValue =
function(param,
callback)
719 for (var key in param)
723 setValueToForm(key, param[key]);
730 setValueToForm(k, values[k]);
736 return ob_get_clean();
739 public static function getPropertiesDialogValues(
743 &$workflowParameters,
749 $runtime = CBPRuntime::GetRuntime();
753 'setstatusmessage' =>
'SetStatusMessage',
754 'statusmessage' =>
'StatusMessage',
755 'usesubscription' =>
'UseSubscription',
756 'timeoutduration' =>
'TimeoutDuration',
757 'timeoutdurationtype' =>
'TimeoutDurationType',
766 $activityData = self::getRestActivityData();
767 $activityProperties = isset($activityData[
'PROPERTIES']) && is_array($activityData[
'PROPERTIES']) ? $activityData[
'PROPERTIES'] : [];
769 $documentService = $runtime->GetService(
'DocumentService');
770 $activityDocumentType = is_array($activityData[
'DOCUMENT_TYPE']) ? $activityData[
'DOCUMENT_TYPE'] : $documentType;
772 foreach ($activityProperties as
$name => $property)
774 $requestName = static::PROPERTY_NAME_PREFIX . mb_strtolower(
$name);
776 if (isset($properties[$requestName]))
783 $properties[
$name] = $documentService->GetFieldInputValue(
784 $activityDocumentType,
797 if (static::checkAdminPermissions() && isset(
$currentValues[
'authuserid']))
811 unset($properties[
'AuthUserId']);
814 if (!empty($activityData[
'USE_SUBSCRIPTION']))
816 $properties[
'UseSubscription'] = $activityData[
'USE_SUBSCRIPTION'];
819 $errors = self::ValidateProperties(
829 $currentActivity[
"Properties"] = $properties;
838 $activityData = self::getRestActivityData();
845 $properties = isset($activityData[
'PROPERTIES']) && is_array($activityData[
'PROPERTIES']) ? $activityData[
'PROPERTIES'] : [];
846 foreach ($properties as
$name => $property)
848 $value = $testProperties[
$name] ?? $property[
'DEFAULT'] ??
null;
849 if (CBPHelper::getBool($property[
'REQUIRED'] ??
false) && CBPHelper::isEmptyValue($value))
852 'code' =>
'NotExist',
853 'parameter' =>
$name,
854 'message' => Loc::getMessage(
'BPRA_PD_ERROR_EMPTY_PROPERTY',
864 isset($testProperties[
'AuthUserId'], $activityData[
'AUTH_USER_ID'])
865 && CBPHelper::stringify($testProperties[
'AuthUserId']) !==
'user_' . $activityData[
'AUTH_USER_ID']
866 && !static::checkAdminPermissions()
870 'code' =>
'NotExist',
871 'parameter' =>
'AuthUserId',
872 'message' => Loc::getMessage(
'BPRA_PD_ERROR_EMPTY_PROPERTY',
874 '#NAME#' => Loc::getMessage(
'BPRA_PD_USER_ID'),
880 return array_merge(
$errors, parent::ValidateProperties($testProperties,
$user));
883 private function calculateTimeoutDuration()
885 $timeoutDuration = ($this->IsPropertyExists(
'TimeoutDuration') ? $this->TimeoutDuration : 0);
887 $timeoutDurationType = ($this->IsPropertyExists(
'TimeoutDurationType') ? $this->TimeoutDurationType :
"s");
888 $timeoutDurationType = mb_strtolower($timeoutDurationType);
889 if (!in_array($timeoutDurationType, [
's',
'd',
'h',
'm']))
891 $timeoutDurationType =
's';
894 $timeoutDuration = intval($timeoutDuration);
895 switch ($timeoutDurationType)
898 $timeoutDuration *= 3600 * 24;
901 $timeoutDuration *= 3600;
904 $timeoutDuration *= 60;
910 return min($timeoutDuration, 3600 * 24 * 365 * 5);
913 private static function checkAdminPermissions()
917 return $user->isAdmin();
920 private static function normalizeProperty(
array $property):
array
922 $property[
'NAME'] = RestActivityTable::getLocalization($property[
'NAME'], LANGUAGE_ID);
923 $property[
'DESCRIPTION'] = RestActivityTable::getLocalization($property[
'DESCRIPTION'] ??
'', LANGUAGE_ID);
925 return Bizproc\FieldType::normalizeProperty($property);
930 $signer = new \Bitrix\Main\Security\Sign\Signer;
932 return $signer->sign($workflowId.
'|'.$activityName.
'|'.
$eventId, self::TOKEN_SALT);
937 $signer = new \Bitrix\Main\Security\Sign\Signer;
941 $unsigned = $signer->unsign($token, self::TOKEN_SALT);
942 $result = explode(
'|', $unsigned);
global_menu_<?echo $menu["menu_id"]?> adm main menu item icon adm main menu item text text adm main menu hover adm submenu menucontainer menu_id menu_id items_id items_id desktop menu_id block none adm global submenu<?=($subMenuDisplay=="block" ? " adm-global-submenu-active" :"")?> global_submenu_<?echo $menu["menu_id"]?> text MAIN_PR_ADMIN_FAV items adm submenu items wrap adm submenu items stretch wrap BX adminMenu itemsStretchScroll()"> <table class if (!empty( $menu["items"])) elseif ( $menu[ 'menu_id']=='desktop') if ( $menu[ 'menu_id']=='desktop') endforeach