1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
restactivity.php
См. документацию.
1<?php
2
8
9class CBPRestActivity extends CBPActivity implements
13{
14 const TOKEN_SALT = 'bizproc';
15 const PROPERTY_NAME_PREFIX = 'property_';
17 protected static $restActivityData = [];
18
19 protected $subscriptionId = 0;
20 protected $eventId;
21
22 private static function getRestActivityData()
23 {
24 if (!isset(static::$restActivityData[static::REST_ACTIVITY_ID]))
25 {
26 $result = RestActivityTable::getById(static::REST_ACTIVITY_ID);
27 $row = $result->fetch();
28 static::$restActivityData[static::REST_ACTIVITY_ID] = $row ?: [];
29 }
30
31 return static::$restActivityData[static::REST_ACTIVITY_ID];
32 }
33
34 public function __construct($name)
35 {
36 parent::__construct($name);
37
38 $activityData = self::getRestActivityData();
39 $this->arProperties = [
40 'Title' => '',
41 'UseSubscription' =>
42 isset($activityData['USE_SUBSCRIPTION']) && $activityData['USE_SUBSCRIPTION'] === 'Y'
43 ? 'Y'
44 : 'N'
45 ,
46 'IsTimeout' => 0,
47 'AuthUserId' => isset($activityData['AUTH_USER_ID']) ? 'user_' . $activityData['AUTH_USER_ID'] : null,
48 'SetStatusMessage' => 'Y',
49 'StatusMessage' => '',
50 'TimeoutDuration' => 0,
51 'TimeoutDurationType' => 's',
52 ];
53
54 if (!empty($activityData['PROPERTIES']))
55 {
56 foreach ($activityData['PROPERTIES'] as $propertyName => $property)
57 {
58 if (isset($this->arProperties[$propertyName]))
59 {
60 continue;
61 }
62 $this->arProperties[$propertyName] = $property['DEFAULT'] ?? null;
63 }
64 }
65
66 $types = [];
67 if (!empty($activityData['RETURN_PROPERTIES']))
68 {
69 foreach ($activityData['RETURN_PROPERTIES'] as $returnPropertyName => $property)
70 {
71 if (isset($this->arProperties[$returnPropertyName]))
72 {
73 continue;
74 }
75 $this->arProperties[$returnPropertyName] = $property['DEFAULT'] ?? null;
76 if (isset($property['TYPE']))
77 {
78 $types[$returnPropertyName] = [
79 'Type' => $property['TYPE'],
80 'Multiple' => CBPHelper::getBool($property['MULTIPLE']),
81 'Options' => $property['OPTIONS'] ?? null,
82 ];
83 }
84 }
85 }
86 $types['IsTimeout'] = [
87 'Type' => 'int',
88 ];
89 $this->SetPropertiesTypes($types);
90 }
91
92 protected function reInitialize()
93 {
94 parent::ReInitialize();
95
96 $this->IsTimeout = 0;
97 $this->eventId = null;
98 $activityData = self::getRestActivityData();
99 if (!empty($activityData['RETURN_PROPERTIES']))
100 {
101 foreach ($activityData['RETURN_PROPERTIES'] as $name => $property)
102 {
103 $this->__set($name, $property['DEFAULT'] ?? null);
104 }
105 }
106 }
107
108 public function execute()
109 {
110 $activityData = static::getRestActivityData();
111
112 if (!$activityData)
113 {
114 throw new Exception(Loc::getMessage('BPRA_NOT_FOUND_ERROR'));
115 }
116
117 if (!Loader::includeModule('rest') || !\Bitrix\Rest\OAuthService::getEngine()->isRegistered())
118 {
120 }
121
122 $properties = $activityData['PROPERTIES'];
123 $propertiesValues = [];
124 if (!empty($properties))
125 {
127 $documentService = $this->workflow->GetService('DocumentService');
128 foreach ($properties as $name => $property)
129 {
130 $property = static::normalizeProperty($property);
131 $properties[$name] = $property;
132 $propertiesValues[$name] = $this->__get($name);
133
134 if ($propertiesValues[$name])
135 {
136 $fieldTypeObject = $documentService->getFieldTypeObject($this->GetDocumentType(), $property);
137 if ($fieldTypeObject)
138 {
139 $fieldTypeObject->setDocumentId($this->GetDocumentId());
140 $propertiesValues[$name] = $fieldTypeObject->externalizeValue(
141 $this->GetName(),
142 $propertiesValues[$name]
143 );
144 }
145 }
146
147 if ($propertiesValues[$name] === null)
148 {
149 $propertiesValues[$name] = '';
150 }
151 }
152
153 if ($this->workflow->isDebug())
154 {
155 $map = $this->getDebugInfo(
156 $propertiesValues,
157 $properties
158 );
159 $this->writeDebugInfo($map);
160 }
161 }
162
163 $dbRes = \Bitrix\Rest\AppTable::getList([
164 'filter' => [
165 '=CLIENT_ID' => $activityData['APP_ID'],
166 ],
167 ]);
168 $application = $dbRes->fetch();
169
170 if (!$application)
171 {
172 throw new Exception('Rest application not found.');
173 }
174
175 $appStatus = \Bitrix\Rest\AppTable::getAppStatusInfo($application, '');
176 if ($appStatus['PAYMENT_ALLOW'] === 'N')
177 {
178 throw new Exception('Rest application status error: payment required');
179 }
180
181 $userId = CBPHelper::ExtractUsers($this->AuthUserId, $this->GetDocumentId(), true);
182 if (empty($userId) && !empty($activityData['AUTH_USER_ID']))
183 {
184 $userId = $activityData['AUTH_USER_ID'];
185 }
186
187 $auth = [
188 'WORKFLOW_ID' => $this->getWorkflowInstanceId(),
189 'ACTIVITY_NAME' => $this->name,
190 'CODE' => $activityData['CODE'],
191 \Bitrix\Rest\OAuth\Auth::PARAM_LOCAL_USER => $userId,
192 "application_token" => \CRestUtil::getApplicationToken($application),
193 ];
194
195 $this->eventId = \Bitrix\Main\Security\Random::getString(32, true);
196
197 $queryItem = Sqs::queryItem(
198 $activityData['APP_ID'],
199 $activityData['HANDLER'],
200 [
201 'workflow_id' => $this->getWorkflowInstanceId(),
202 'code' => $activityData['CODE'],
203 'document_id' => $this->GetDocumentId(),
204 'document_type' => $this->GetDocumentType(),
205 'event_token' => self::generateToken($this->getWorkflowInstanceId(), $this->name, $this->eventId),
206 'properties' => $propertiesValues,
207 'use_subscription' => $this->UseSubscription,
208 'timeout_duration' => $this->CalculateTimeoutDuration(),
209 'ts' => time(),
210 ],
211 $auth,
212 [
213 "sendAuth" => true,
214 "sendRefreshToken" => true,
215 "category" => Sqs::CATEGORY_BIZPROC,
216 ]
217 );
218
219 if ($activityData['IS_ROBOT'] === 'Y')
220 {
221 \Bitrix\Rest\UsageStatTable::logRobot($activityData['APP_ID'], $activityData['CODE']);
222 }
223 else
224 {
225 \Bitrix\Rest\UsageStatTable::logActivity($activityData['APP_ID'], $activityData['CODE']);
226 }
227
228 if (is_callable([\Bitrix\Rest\Event\Sender::class, 'queueEvent']))
229 {
230 \Bitrix\Rest\Event\Sender::queueEvent($queryItem);
231 }
232 else
233 {
234 \Bitrix\Rest\OAuthService::getEngine()->getClient()->sendEvent([$queryItem]);
235 \Bitrix\Rest\UsageStatTable::finalize();
236 }
237
238 if ($this->SetStatusMessage === 'Y')
239 {
240 $message = $this->StatusMessage;
241 if (empty($message) || !is_string($message))
242 {
243 $message = Loc::getMessage('BPRA_DEFAULT_STATUS_MESSAGE');
244 }
245 $this->SetStatusTitle($message);
246 }
247
248 if ($this->UseSubscription !== 'Y')
249 {
251 }
252
253 $this->Subscribe($this);
254
256 }
257
258 public function subscribe(IBPActivityExternalEventListener $eventHandler)
259 {
260 $timeoutDuration = $this->CalculateTimeoutDuration();
261 if ($timeoutDuration > 0)
262 {
263 $schedulerService = $this->workflow->GetService('SchedulerService');
264 $this->subscriptionId = $schedulerService->SubscribeOnTime(
265 $this->workflow->GetInstanceId(),
266 $this->name,
267 time() + $timeoutDuration
268 );
269 }
270
271 $this->workflow->AddEventHandler($this->name, $eventHandler);
272 }
273
274 public function unsubscribe(IBPActivityExternalEventListener $eventHandler)
275 {
276 if ($this->subscriptionId > 0)
277 {
278 $schedulerService = $this->workflow->GetService("SchedulerService");
279 $schedulerService->UnSubscribeOnTime($this->subscriptionId);
280 $this->subscriptionId = 0;
281 }
282
283 $this->eventId = null;
284 $this->workflow->RemoveEventHandler($this->name, $eventHandler);
285 }
286
287 public function onExternalEvent($eventParameters = [])
288 {
289 if ($this->executionStatus === CBPActivityExecutionStatus::Closed)
290 {
291 return;
292 }
293
294 $onAgent = (array_key_exists('SchedulerService', $eventParameters) && $eventParameters['SchedulerService'] === 'OnAgent');
295 if ($onAgent)
296 {
297 $this->IsTimeout = 1;
298 $this->Unsubscribe($this);
299 $this->workflow->CloseActivity($this);
300
301 return;
302 }
303
304 if ($this->eventId !== (string)$eventParameters['EVENT_ID'])
305 {
306 return;
307 }
308
309 $this->WriteToTrackingService(
310 !empty($eventParameters['LOG_MESSAGE']) && is_string($eventParameters['LOG_MESSAGE'])
311 ? $eventParameters['LOG_MESSAGE']
312 : Loc::getMessage('BPRA_DEFAULT_LOG_MESSAGE')
313 );
314
315 if (!empty($eventParameters['RETURN_VALUES']))
316 {
317 $activityData = self::getRestActivityData();
318 $whiteList = array();
319 if (!empty($activityData['RETURN_PROPERTIES']))
320 {
321 foreach ($activityData['RETURN_PROPERTIES'] as $name => $property)
322 {
323 $whiteList[mb_strtoupper($name)] = $name;
324 }
325 }
326
328 $documentService = $this->workflow->GetService('DocumentService');
329 $eventParameters['RETURN_VALUES'] = array_change_key_case(
330 (array)$eventParameters['RETURN_VALUES'],
331 CASE_UPPER
332 );
333 foreach ($eventParameters['RETURN_VALUES'] as $name => $value)
334 {
335 if (!isset($whiteList[$name]))
336 {
337 continue;
338 }
339
340 $property = $activityData['RETURN_PROPERTIES'][$whiteList[$name]];
341 if ($property && $value)
342 {
343 $property = static::normalizeProperty($property);
344 $fieldTypeObject = $documentService->getFieldTypeObject($this->GetDocumentType(), $property);
345 if ($fieldTypeObject)
346 {
347 $fieldTypeObject->setDocumentId($this->GetDocumentId());
348 $value = $fieldTypeObject->internalizeValue($this->GetName(), $value);
349 }
350
351 if ($this->workflow->isDebug())
352 {
353 $map = $this->getDebugInfo(
354 [$name => $value],
355 [$name => $property]
356 );
357 $this->writeDebugInfo($map);
358 }
359 }
360
361 $this->__set($whiteList[$name], $value);
362 }
363 }
364
365 if (empty($eventParameters['LOG_ACTION']))
366 {
367 $this->Unsubscribe($this);
368 $this->workflow->CloseActivity($this);
369 }
370 }
371
372 public function onDebugEvent(array $eventParameters = [])
373 {
374 if ($this->executionStatus === CBPActivityExecutionStatus::Closed)
375 {
376 return;
377 }
378
379 $this->writeDebugTrack(
380 $this->getWorkflowInstanceId(),
381 $this->getName(),
382 $this->executionStatus,
383 $this->executionResult,
384 $this->Title,
385 \Bitrix\Main\Localization\Loc::getMessage('BPRA_DEBUG_EVENT')
386 );
387
388 $this->Unsubscribe($this);
389 $this->workflow->CloseActivity($this);
390 }
391
392 public function cancel()
393 {
394 if ($this->UseSubscription === 'Y')
395 {
396 $this->Unsubscribe($this);
397 }
398
400 }
401
402 public static function getPropertiesDialog(
403 $documentType,
404 $activityName,
405 $workflowTemplate,
406 $workflowParameters,
407 $workflowVariables,
408 $currentValues = null,
409 $formName = "",
410 $popupWindow = null,
411 $currentSiteId = null,
412 $workflowConstants = null
413 )
414 {
415 if (!Loader::includeModule('rest'))
416 {
417 return false;
418 }
419
420 $activityData = self::getRestActivityData();
421
422 $dbRes = \Bitrix\Rest\AppTable::getList([
423 'select' => ['ID'],
424 'filter' => [
425 '=CLIENT_ID' => $activityData['APP_ID'],
426 ],
427 ]);
428 $application = $dbRes->fetch();
429
430 if ($application)
431 {
432 $activityData['APP_ID_INT'] = $application['ID'];
433 }
434
435 $dialog = new \Bitrix\Bizproc\Activity\PropertiesDialog(__FILE__, [
436 'documentType' => $documentType,
437 'activityName' => $activityName,
438 'workflowTemplate' => $workflowTemplate,
439 'workflowParameters' => $workflowParameters,
440 'workflowVariables' => $workflowVariables,
441 'currentValues' => $currentValues,
442 'formName' => $formName,
443 'workflowConstants' => $workflowConstants,
444 ]);
445
446 $map = [
447 'AuthUserId' => [
448 'Name' => Loc::getMessage("BPRA_PD_USER_ID"),
449 'FieldName' => 'authuserid',
450 'Type' => 'user',
451 'Default' => 'user_' . $activityData['AUTH_USER_ID'],
452 ],
453 'SetStatusMessage' => [
454 'Name' => 'SetStatusMessage',
455 'FieldName' => 'setstatusmessage',
456 'Type' => 'bool',
457 ],
458 'StatusMessage' => [
459 'Name' => 'StatusMessage',
460 'FieldName' => 'statusmessage',
461 'Type' => 'text',
462 'Default' => Loc::getMessage('BPRA_DEFAULT_STATUS_MESSAGE'),
463 ],
464 'UseSubscription' => [
465 'Name' => 'StatusMessage',
466 'FieldName' => 'usesubscription',
467 'Type' => 'bool',
468 'Default' => $activityData['USE_SUBSCRIPTION'],
469 ],
470 'TimeoutDuration' => [
471 'Name' => 'StatusMessage',
472 'FieldName' => 'timeoutduration',
473 'Type' => 'int',
474 ],
475 'TimeoutDurationType' => [
476 'Name' => 'StatusMessage',
477 'FieldName' => 'timeoutdurationtype',
478 'Type' => 'string',
479 'Default' => 's',
480 ],
481 ];
482
483 $properties = isset($activityData['PROPERTIES']) && is_array($activityData['PROPERTIES']) ? $activityData['PROPERTIES'] : [];
484 foreach ($properties as $name => $property)
485 {
486 if (!array_key_exists($name, $map))
487 {
488 $map[$name] = [
489 'Name' => RestActivityTable::getLocalization($property['NAME'], LANGUAGE_ID),
490 'Description' => RestActivityTable::getLocalization($property['DESCRIPTION'] ?? '', LANGUAGE_ID),
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,
497 ];
498 }
499 }
500
501 $appPlacement = null;
502 if (!empty($activityData['APP_ID_INT']))
503 {
504 $appPlacement = self::getAppPlacement($activityData['APP_ID_INT'], $activityData['CODE']);
505 }
506
507 $dialog
508 ->setMap($map)
509 ->setRuntimeData([
510 'ACTIVITY_DATA' => $activityData,
511 'IS_ADMIN' => static::checkAdminPermissions(),
512 'APP_PLACEMENT' => $appPlacement,
513 ])
514 ->setRenderer([__CLASS__, 'renderPropertiesDialog']);
515
516 return $dialog;
517 }
518
519 private static function getAppPlacement(int $appId, string $code): ?array
520 {
521 $result = \Bitrix\Rest\PlacementTable::getList([
522 'filter' => [
523 '=APP_ID' => $appId,
524 '=ADDITIONAL' => $code,
526 ],
527 ])->fetch();
528
529 return $result ?: null;
530 }
531
532 public static function renderPropertiesDialog(\Bitrix\Bizproc\Activity\PropertiesDialog $dialog)
533 {
534 $runtime = CBPRuntime::GetRuntime();
535 $data = $dialog->getRuntimeData();
536 $activityData = $data['ACTIVITY_DATA'];
537
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();
542
543 $currentValues = $dialog->getCurrentValues();
544
545 $appPlacement = $data['APP_PLACEMENT'];
546 $placementSid = null;
547 $appCurrentValues = [];
548
549 ob_start();
550
551 if ($appPlacement):
552
553 foreach ($properties as $key => $property)
554 {
555 $appCurrentValues[$key] = $dialog->getCurrentValue('property_'.mb_strtolower($key));
556 }
557
558 global $APPLICATION;
559 echo '<tr><td align="right" colspan="2">';
560 $placementSid = $APPLICATION->includeComponent(
561 'bitrix:app.layout',
562 '',
563 array(
564 'ID' => $appPlacement['APP_ID'],
565 'PLACEMENT' => \Bitrix\Bizproc\RestService::PLACEMENT_ACTIVITY_PROPERTIES_DIALOG,
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(),
575 ],
576 'PARAM' => array(
577 'FRAME_WIDTH' => '100%',
578 'FRAME_HEIGHT' => '350px'
579 ),
580 ),
581 null,
582 array('HIDE_ICONS' => 'Y')
583 );
584 echo '</td></tr>';
585 else:
586
587 foreach ($properties as $name => $property):
588 $required = CBPHelper::getBool($property['REQUIRED']);
589 $name = mb_strtolower($name);
590 $value = !CBPHelper::isEmptyValue($currentValues[static::PROPERTY_NAME_PREFIX.$name]) ? $currentValues[static::PROPERTY_NAME_PREFIX.$name] : $property['DEFAULT'];
591
592 $property['NAME'] = RestActivityTable::getLocalization($property['NAME'], LANGUAGE_ID);
593 if (isset($property['DESCRIPTION']))
594 {
595 $property['DESCRIPTION'] = RestActivityTable::getLocalization($property['DESCRIPTION'], LANGUAGE_ID);
596 }
597
598 ?>
599 <tr>
600 <td align="right" width="40%" valign="top">
601 <span class="<?=$required?'adm-required-field':''?>">
602 <?= htmlspecialcharsbx($property['NAME']) ?>:
603 </span>
604 <?if (!empty($property['DESCRIPTION'])):?>
605 <br/><?= htmlspecialcharsbx($property['DESCRIPTION']) ?>
606 <?endif;?>
607 </td>
608 <td width="60%">
609 <?=$documentService->getFieldInputControl(
610 $activityDocumentType,
611 $property,
612 array('Field' => static::PROPERTY_NAME_PREFIX.$name, 'Form' => $dialog->getFormName()),
613 $value,
614 true,
615 false
616 )?>
617 </td>
618 </tr>
619
620 <?
622
623 endif;
624
625 if (static::checkAdminPermissions()):?>
626 <tr>
627 <td align="right" width="40%" valign="top"><span class=""><?= Loc::getMessage("BPRA_PD_USER_ID") ?>:</span></td>
628 <td width="60%">
629 <?=$dialog->renderFieldControl('AuthUserId', $currentValues['authuserid'], true, 0)?>
630 </td>
631 </tr>
632 <?endif?>
633 <tr>
634 <td align="right"><?= Loc::getMessage("BPRA_PD_SET_STATUS_MESSAGE") ?>:</td>
635 <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>
639 </select>
640 </td>
641 </tr>
642 <tr>
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>
645 </tr>
646 <tr>
647 <td align="right"><?= Loc::getMessage("BPRA_PD_USE_SUBSCRIPTION") ?>:</td>
648 <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>
652 </select>
653 </td>
654 </tr>
655 <? if ($activityData['USE_SUBSCRIPTION'] !== 'N'):?>
656 <tr>
657 <td align="right"><?= Loc::getMessage("BPRA_PD_TIMEOUT_DURATION") ?>:<br/><?= Loc::getMessage("BPRA_PD_TIMEOUT_DURATION_HINT") ?></td>
658 <td valign="top">
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>
665 </select>
666 <?
667 $delayMinLimit = CBPSchedulerService::getDelayMinLimit();
668 if ($delayMinLimit):
669 ?>
670 <p style="color: red;">* <?= Loc::getMessage("BPRA_PD_TIMEOUT_LIMIT") ?>: <?=CBPHelper::FormatTimePeriod($delayMinLimit)?></p>
671 <?
672 endif;
673 ?>
674 </td>
675 </tr>
676 <?endif;
677
678 if ($placementSid):?>
679 <script>
680 BX.ready(function()
681 {
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())?>'];
686
687 function setValueToForm(name, value)
688 {
689 name = 'property_' + name.toLowerCase();
690 if (BX.type.isArray(value))
691 {
692 name += '[]';
693 }
694 else
695 {
696 value = [value];
697 }
698
699 Array.from(form.querySelectorAll('[name="'+name+'"]')).forEach(function(element)
700 {
701 BX.remove(element);
702 });
703
704 value.forEach(function(val)
705 {
706 form.appendChild(BX.create('input', {
707 props: {
708 type: 'hidden',
709 name: name,
710 value: val
711 }
712 }));
713 });
714 }
715
716 var placementInterface = appLayout.messageInterface;
717 placementInterface.setPropertyValue = function(param, callback)
718 {
719 for (var key in param)
720 {
721 if (properties[key])
722 {
723 setValueToForm(key, param[key]);
724 }
725 }
726 }
727
728 for(var k in values)
729 {
730 setValueToForm(k, values[k]);
731 }
732 });
733 </script>
734 <?php endif;
735
736 return ob_get_clean();
737 }
738
739 public static function getPropertiesDialogValues(
740 $documentType,
741 $activityName,
742 &$workflowTemplate,
743 &$workflowParameters,
744 &$workflowVariables,
746 &$errors
747 )
748 {
749 $runtime = CBPRuntime::GetRuntime();
750 $errors = [];
751
752 $map = [
753 'setstatusmessage' => 'SetStatusMessage',
754 'statusmessage' => 'StatusMessage',
755 'usesubscription' => 'UseSubscription',
756 'timeoutduration' => 'TimeoutDuration',
757 'timeoutdurationtype' => 'TimeoutDurationType',
758 ];
759
760 $properties = [];
761 foreach ($map as $key => $value)
762 {
763 $properties[$value] = $currentValues[$key] ?? null;
764 }
765
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;
771
772 foreach ($activityProperties as $name => $property)
773 {
774 $requestName = static::PROPERTY_NAME_PREFIX . mb_strtolower($name);
775
776 if (isset($properties[$requestName]))
777 {
778 continue;
779 }
780
781 $errors = [];
782
783 $properties[$name] = $documentService->GetFieldInputValue(
784 $activityDocumentType,
785 $property,
786 $requestName,
788 $errors
789 );
790
791 if (count($errors) > 0)
792 {
793 return false;
794 }
795 }
796
797 if (static::checkAdminPermissions() && isset($currentValues['authuserid']))
798 {
799 $properties['AuthUserId'] = CBPHelper::usersStringToArray(
800 $currentValues['authuserid'],
801 $documentType,
802 $errors
803 );
804 if (count($errors) > 0)
805 {
806 return false;
807 }
808 }
809 else
810 {
811 unset($properties['AuthUserId']);
812 }
813
814 if (!empty($activityData['USE_SUBSCRIPTION']))
815 {
816 $properties['UseSubscription'] = $activityData['USE_SUBSCRIPTION'];
817 }
818
819 $errors = self::ValidateProperties(
820 $properties,
822 );
823 if (count($errors) > 0)
824 {
825 return false;
826 }
827
828 $currentActivity = &CBPWorkflowTemplateLoader::FindActivityByName($workflowTemplate, $activityName);
829 $currentActivity["Properties"] = $properties;
830
831 return true;
832 }
833
834 public static function validateProperties($testProperties = [], CBPWorkflowTemplateUser $user = null)
835 {
836 $errors = [];
837
838 $activityData = self::getRestActivityData();
839
840 if (!$activityData)
841 {
842 return $errors;
843 }
844
845 $properties = isset($activityData['PROPERTIES']) && is_array($activityData['PROPERTIES']) ? $activityData['PROPERTIES'] : [];
846 foreach ($properties as $name => $property)
847 {
848 $value = $testProperties[$name] ?? $property['DEFAULT'] ?? null;
849 if (CBPHelper::getBool($property['REQUIRED'] ?? false) && CBPHelper::isEmptyValue($value))
850 {
851 $errors[] = [
852 'code' => 'NotExist',
853 'parameter' => $name,
854 'message' => Loc::getMessage('BPRA_PD_ERROR_EMPTY_PROPERTY',
855 [
856 '#NAME#' => RestActivityTable::getLocalization($property['NAME'], LANGUAGE_ID),
857 ]
858 ),
859 ];
860 }
861 }
862
863 if (
864 isset($testProperties['AuthUserId'], $activityData['AUTH_USER_ID'])
865 && CBPHelper::stringify($testProperties['AuthUserId']) !== 'user_' . $activityData['AUTH_USER_ID']
866 && !static::checkAdminPermissions()
867 )
868 {
869 $errors[] = [
870 'code' => 'NotExist',
871 'parameter' => 'AuthUserId',
872 'message' => Loc::getMessage('BPRA_PD_ERROR_EMPTY_PROPERTY',
873 [
874 '#NAME#' => Loc::getMessage('BPRA_PD_USER_ID'),
875 ]
876 ),
877 ];
878 }
879
880 return array_merge($errors, parent::ValidateProperties($testProperties, $user));
881 }
882
883 private function calculateTimeoutDuration()
884 {
885 $timeoutDuration = ($this->IsPropertyExists('TimeoutDuration') ? $this->TimeoutDuration : 0);
886
887 $timeoutDurationType = ($this->IsPropertyExists('TimeoutDurationType') ? $this->TimeoutDurationType : "s");
888 $timeoutDurationType = mb_strtolower($timeoutDurationType);
889 if (!in_array($timeoutDurationType, ['s', 'd', 'h', 'm']))
890 {
891 $timeoutDurationType = 's';
892 }
893
894 $timeoutDuration = intval($timeoutDuration);
895 switch ($timeoutDurationType)
896 {
897 case 'd':
898 $timeoutDuration *= 3600 * 24;
899 break;
900 case 'h':
901 $timeoutDuration *= 3600;
902 break;
903 case 'm':
904 $timeoutDuration *= 60;
905 break;
906 default:
907 break;
908 }
909
910 return min($timeoutDuration, 3600 * 24 * 365 * 5);
911 }
912
913 private static function checkAdminPermissions()
914 {
916
917 return $user->isAdmin();
918 }
919
920 private static function normalizeProperty(array $property): array
921 {
922 $property['NAME'] = RestActivityTable::getLocalization($property['NAME'], LANGUAGE_ID);
923 $property['DESCRIPTION'] = RestActivityTable::getLocalization($property['DESCRIPTION'] ?? '', LANGUAGE_ID);
924
925 return Bizproc\FieldType::normalizeProperty($property);
926 }
927
928 public static function generateToken($workflowId, $activityName, $eventId)
929 {
930 $signer = new \Bitrix\Main\Security\Sign\Signer;
931
932 return $signer->sign($workflowId.'|'.$activityName.'|'.$eventId, self::TOKEN_SALT);
933 }
934
935 public static function extractToken($token)
936 {
937 $signer = new \Bitrix\Main\Security\Sign\Signer;
938
939 try
940 {
941 $unsigned = $signer->unsign($token, self::TOKEN_SALT);
942 $result = explode('|', $unsigned);
943 }
944 catch (\Exception $e)
945 {
946 $result = false;
947 }
948
949 return $result;
950 }
951}
return select
Определения access_edit.php:440
$popupWindow
Определения access_edit.php:10
global $APPLICATION
Определения include.php:80
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getLocalization($field, $langId)
Определения restactivity.php:226
const PLACEMENT_ACTIVITY_PROPERTIES_DIALOG
Определения restservice.php:20
Определения loader.php:13
static includeModule($moduleName)
Определения loader.php:67
Определения sqs.php:8
const Executing
Определения constants.php:8
const Closed
Определения constants.php:10
Определения activity.php:8
getDebugInfo(array $values=[], array $map=[])
Определения activity.php:1590
execute()
Определения activity.php:1193
getName()
Определения activity.php:384
string $name
Определения activity.php:38
getWorkflowInstanceId()
Определения activity.php:415
__set($name, $val)
Определения activity.php:1060
__get($name)
Определения activity.php:1036
static isEmptyValue($value)
Определения helper.php:2075
static getBool($value)
Определения helper.php:2060
static usersStringToArray($strUsers, $documentType, &$arErrors, $callbackFunction=null)
Определения helper.php:152
Определения restactivity.php:13
const TOKEN_SALT
Определения restactivity.php:14
static validateProperties($testProperties=[], CBPWorkflowTemplateUser $user=null)
Определения restactivity.php:834
static extractToken($token)
Определения restactivity.php:935
static getPropertiesDialog( $documentType, $activityName, $workflowTemplate, $workflowParameters, $workflowVariables, $currentValues=null, $formName="", $popupWindow=null, $currentSiteId=null, $workflowConstants=null)
Определения restactivity.php:402
const PROPERTY_NAME_PREFIX
Определения restactivity.php:15
onDebugEvent(array $eventParameters=[])
Определения restactivity.php:372
__construct($name)
Определения restactivity.php:34
static $restActivityData
Определения restactivity.php:17
$subscriptionId
Определения restactivity.php:19
cancel()
Определения restactivity.php:392
subscribe(IBPActivityExternalEventListener $eventHandler)
Определения restactivity.php:258
static generateToken($workflowId, $activityName, $eventId)
Определения restactivity.php:928
const REST_ACTIVITY_ID
Определения restactivity.php:16
unsubscribe(IBPActivityExternalEventListener $eventHandler)
Определения restactivity.php:274
$eventId
Определения restactivity.php:20
reInitialize()
Определения restactivity.php:92
static & FindActivityByName(&$arWorkflowTemplate, $activityName)
Определения workflowtemplateloader.php:964
$data['IS_AVAILABLE']
Определения .description.php:13
bx popup label bx width30 PAGE_NEW_MENU_NAME text width
Определения file_new.php:677
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$auth
Определения get_user.php:29
if($request->isPost() && $currentAction !==null &&check_bitrix_sessid()) $currentValues
Определения options.php:198
$errors
Определения iblock_catalog_edit.php:74
onExternalEvent($arEventParameters=array())
Определения interface.php:4
endif
Определения csv_new_setup.php:990
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$application
Определения bitrix.php:23
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
$name
Определения menu_edit.php:35
$map
Определения config.php:5
$value
Определения Param.php:39
$user
Определения mysql_to_pgsql.php:33
$message
Определения payment.php:8
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
Определения prolog_main_admin.php:255
if(empty($signedUserToken)) $key
Определения quickway.php:257
font style
Определения invoice.php:442
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
text align
Определения template.php:556
case callback
Определения wrapper_popup.php:31
$dbRes
Определения yandex_detail.php:168