1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
propertiesdialog.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\Activity;
4
5use Bitrix\Bizproc\FieldType;
6use Bitrix\Main\ArgumentException;
7
9{
10 protected string $activityFile;
11 protected string $dialogFileName = 'properties_dialog.php';
12 protected ?array $map = null; //compatible Null
13 protected $mapCallback;
14 protected ?array $documentType = null; //compatible Null
15 protected ?string $activityName = null; //compatible Null
16 protected ?array $workflowTemplate = null; //compatible Null
17 protected ?array $workflowParameters = null; //compatible Null
18 protected ?array $workflowVariables = null; //compatible Null
19 protected array $workflowConstants = [];
20 protected mixed $currentValues = null; //compatible Null
21 protected ?string $formName = null; //compatible Null
22 protected ?string $siteId = null; //compatible Null
23 protected $renderer;
24 protected array $context = [];
25
27 protected $runtimeData = [];
28
29 public function __construct($activityFile, array $data = null)
30 {
31 $this->activityFile = $activityFile;
32
33 if (is_array($data))
34 {
35 if (isset($data['documentType']) && is_array($data['documentType']))
36 {
37 $this->setDocumentType($data['documentType']);
38 }
39 if (isset($data['activityName']))
40 {
41 $this->setActivityName($data['activityName']);
42 }
43 if (isset($data['workflowTemplate']) && is_array($data['workflowTemplate']))
44 {
45 $this->setWorkflowTemplate($data['workflowTemplate']);
46 }
47 if (isset($data['workflowParameters']) && is_array($data['workflowParameters']))
48 {
49 $this->setWorkflowParameters($data['workflowParameters']);
50 }
51 if (isset($data['workflowVariables']) && is_array($data['workflowVariables']))
52 {
53 $this->setWorkflowVariables($data['workflowVariables']);
54 }
55 if (isset($data['workflowConstants']) && is_array($data['workflowConstants']))
56 {
57 $this->setWorkflowConstants($data['workflowConstants']);
58 }
59 if (isset($data['currentValues']) && is_array($data['currentValues']))
60 {
61 $this->setCurrentValues($data['currentValues']);
62 }
63 if (isset($data['formName']))
64 {
65 $this->setFormName($data['formName']);
66 }
67 if (isset($data['siteId']))
68 {
69 $this->setSiteId($data['siteId']);
70 }
71 }
72 }
73
74 public function getActivityFile(): string
75 {
77 }
78
79 public function setActivityFile(string $file): self
80 {
81 $this->activityFile = $file;
82
83 return $this;
84 }
85
89 public function getDocumentType()
90 {
92 }
93
99 {
100 $this->documentType = $documentType;
101
102 return $this;
103 }
104
110 {
111 $this->activityName = (string)$activityName;
112
113 return $this;
114 }
115
119 public function getActivityName()
120 {
121 return $this->activityName;
122 }
123
129 {
130 $this->workflowTemplate = $workflowTemplate;
131
132 return $this;
133 }
134
138 public function getWorkflowTemplate()
139 {
141 }
142
148 {
149 $this->workflowParameters = $workflowParameters;
150
151 return $this;
152 }
153
157 public function getWorkflowParameters()
158 {
160 }
161
167 {
168 $this->workflowVariables = $workflowVariables;
169
170 return $this;
171 }
172
176 public function getWorkflowVariables()
177 {
179 }
180
182 {
183 $this->workflowConstants = $workflowConstants;
184
185 return $this;
186 }
187
188 public function getWorkflowConstants(): array
189 {
191 }
192
197 public function getCurrentValues($compatible = false)
198 {
200 if (!is_array($this->currentValues))
201 {
202 // Get current values from saved activity properties.
203 $this->currentValues = [];
204 $currentActivity = \CBPWorkflowTemplateLoader::findActivityByName(
206 $this->getActivityName()
207 );
208
209 if (is_array($currentActivity) && isset($currentActivity['Properties']) && is_array($currentActivity['Properties']))
210 {
211 $map = $this->getMap();
212 foreach ($map as $id => $property)
213 {
214 if (!isset($property['FieldName']))
215 continue;
216
217 $this->currentValues[$property['FieldName']] = null;
218
219 if (isset($currentActivity['Properties'][$id]))
220 {
221 if (
222 isset($property['Getter'])
223 && is_callable($property['Getter'])
224 && $property['Getter'] instanceof \Closure
225 )
226 {
227 $getter = $property['Getter'];
228 $property['Id'] = $id;
229 $this->currentValues[$property['FieldName']] = $getter($this, $property, $currentActivity, $compatible);
230 }
231 else
232 {
233 $this->currentValues[$property['FieldName']] = $currentActivity['Properties'][$id];
234 }
235 }
236
237 if (
238 (
239 $this->currentValues[$property['FieldName']] === null
240 ||
241 $this->currentValues[$property['FieldName']] === ''
242 )
243 && isset($property['Default'])
244 )
245 {
246 $this->currentValues[$property['FieldName']] = $property['Default'];
247 }
248 }
249 }
250 }
251
252 if ($compatible && $this->currentValues)
253 {
254 $compatibleValues = $this->currentValues;
255
256 foreach ($this->getMap() as $id => $property)
257 {
258 if (!isset($property['FieldName']))
259 {
260 continue;
261 }
262
263 if (isset($property['Type']) && $property['Type'] === FieldType::USER && !isset($property['Getter']))
264 {
265 $compatibleValues[$property['FieldName']] = \CBPHelper::usersArrayToString(
266 $compatibleValues[$property['FieldName']],
268 $this->getDocumentType()
269 );
270 }
271 }
272
273 return $compatibleValues;
274 }
275
277 }
278
284 public function getCurrentValue($valueKey, $default = null)
285 {
286 if (is_array($valueKey))
287 {
288 if ($default === null && isset($valueKey['Default']))
289 {
290 $default = $valueKey['Default'];
291 }
292 $valueKey = $valueKey['FieldName'] ?? '';
293 }
294
295 $values = $this->getCurrentValues();
296
297 return (is_array($values) && isset($values[$valueKey])) ? $values[$valueKey] : $default;
298 }
299
305 {
306 $this->currentValues = $currentValues;
307
308 return $this;
309 }
310
314 public function getFormName()
315 {
316 return $this->formName;
317 }
318
323 public function setFormName($formName)
324 {
325 $this->formName = (string)$formName;
326
327 return $this;
328 }
329
333 public function getSiteId()
334 {
335 return $this->siteId;
336 }
337
341 public function setSiteId($siteId)
342 {
343 $this->siteId = (string)$siteId;
344 }
345
350 public function setMap(array $map)
351 {
352 $this->map = $map;
353
354 return $this;
355 }
356
362 public function setMapCallback($callback)
363 {
364 if (!is_callable($callback))
365 {
366 throw new ArgumentException('Wrong callable argument.');
367 }
368
369 $this->mapCallback = $callback;
370
371 return $this;
372 }
373
377 public function getMap()
378 {
379 if ($this->map === null && $this->mapCallback !== null)
380 {
381 $this->map = call_user_func($this->mapCallback, $this);
382 }
383
384 return $this->map ?? [];
385 }
386
391 public function getFieldTypeObject(array $field)
392 {
393 $runtime = \CBPRuntime::getRuntime();
394 $runtime->startRuntime();
395
397 $documentService = $runtime->getService('DocumentService');
398
399 $field = FieldType::normalizeProperty($field);
400
401 $typeClass = $documentService->getTypeClass($this->getDocumentType(), $field['Type']);
402 if ($typeClass && class_exists($typeClass))
403 {
404 return new FieldType($field, $this->getDocumentType(), $typeClass);
405 }
406
407 return null;
408 }
409
410 public function renderFieldControl($field, $value = null, $allowSelection = true, $renderMode = FieldType::RENDER_MODE_PUBLIC)
411 {
412 if (is_string($field))
413 {
414 $field = $this->getMap()[$field];
415 }
416
417 $fieldType = $field ? $this->getFieldTypeObject($field) : null;
418
419 if (!$fieldType)
420 {
421 return 'incorrect field type';
422 }
423
424 if ($value === null)
425 {
426 $value = $this->getCurrentValue($field, $field['Default'] ?? null);
427 }
428
429 return $fieldType->renderControl(
430 ['Form' => $this->getFormName(), 'Field' => $field['FieldName']],
431 $value,
432 $allowSelection,
433 $renderMode
434 );
435 }
436
437 public function setRenderer($callable)
438 {
439 if (!is_callable($callable))
440 {
441 throw new ArgumentException('Wrong callable argument.');
442 }
443
444 $this->renderer = $callable;
445 }
446
447 public function __toString()
448 {
449 if ($this->renderer !== null)
450 {
451 return (string)call_user_func($this->renderer, $this);
452 }
453
454 $runtime = \CBPRuntime::getRuntime();
455 $runtime->startRuntime();
456
457 return (string)$runtime->executeResourceFile(
458 $this->activityFile,
459 $this->dialogFileName,
460 array_merge(
461 [
462 'dialog' => $this,
463 //compatible parameters
464 'arCurrentValues' => $this->getCurrentValues($this->dialogFileName === 'properties_dialog.php'),
465 'formName' => $this->getFormName(),
466 ],
467 $this->getRuntimeData()
468 )
469 );
470 }
471
476 public function setContext(array $context)
477 {
478 $this->context = $context;
479
480 return $this;
481 }
482
486 public function getContext()
487 {
488 return $this->context;
489 }
490
496 {
498 if (!str_contains($dialogFileName, '.'))
499 {
500 $dialogFileName .= '.php';
501 }
502
503 $this->dialogFileName = $dialogFileName;
504
505 return $this;
506 }
507
511 public function getDialogFileName()
512 {
514 }
515
520 public function getRuntimeData()
521 {
522 return $this->runtimeData;
523 }
524
531 {
532 $this->runtimeData = $runtimeData;
533
534 return $this;
535 }
536
537 public function getTemplateExpressions(): array
538 {
539 return [
540 'parameters' => FieldType::normalizePropertyList($this->getWorkflowParameters() ?? []),
541 'variables' => FieldType::normalizePropertyList($this->getWorkflowVariables() ?? []),
543 'global_variables' => FieldType::normalizePropertyList($this->getGlobalVariables()),
544 'global_constants' => FieldType::normalizePropertyList($this->getGlobalConstants()),
545 'return_activities' => $this->getReturnProperties(),
546 ];
547 }
548
549 private function getGlobalConstants(): array
550 {
552 if ($documentType)
553 {
554 return \Bitrix\Bizproc\Workflow\Type\GlobalConst::getAll($documentType);
555 }
556
557 return [];
558 }
559
560 private function getGlobalVariables(): array
561 {
563 if ($documentType)
564 {
565 return \Bitrix\Bizproc\Workflow\Type\GlobalVar::getAll($documentType);
566 }
567
568 return [];
569 }
570
571 private function getReturnProperties(): array
572 {
575
576 if (!is_array($documentType) || !is_array($template))
577 {
578 return [];
579 }
580
581 $runtime = \CBPRuntime::getRuntime();
582 $activities = $runtime->searchActivitiesByType('activity', $documentType);
583 $result = [];
584 $this->extractChildProperties($template, $activities, $result);
585
586 return $result;
587 }
588
589 private function extractChildProperties(array $children, array $activities, &$result): void
590 {
591 foreach ($children as $child)
592 {
593 $childType = mb_strtolower($child["Type"]);
594 if (
595 isset($activities[$childType]['RETURN'])
596 && is_array($activities[$childType]['RETURN'])
597 && count($activities[$childType]['RETURN']) > 0
598 )
599 {
600 $childProps = [];
601 foreach ($activities[$childType]['RETURN'] as $propId => $prop)
602 {
603 $childProps[] = [
604 'Id' => $propId,
605 'Name' => $prop['NAME'],
606 'Type' => $prop['TYPE'],
607 ];
608 }
609
610 if (count($childProps) > 0)
611 {
612 $result[] = [
613 'Id' => $child['Name'],
614 'Type' => $child['Type'],
615 'Title' => $child['Properties']['Title'],
616 'Return' => $childProps,
617 ];
618 }
619 }
620 elseif (
621 isset($activities[$childType]['ADDITIONAL_RESULT'])
622 && is_array($activities[$childType]['ADDITIONAL_RESULT'])
623 )
624 {
625 $additionalProps = [];
626 foreach ($activities[$childType]['ADDITIONAL_RESULT'] as $propertyKey)
627 {
628 if (!isset($child['Properties'][$propertyKey]) || !is_array($child['Properties'][$propertyKey]))
629 {
630 continue;
631 }
632
633 foreach ($child['Properties'][$propertyKey] as $fieldId => $fieldData)
634 {
635 $additionalProps[] = [
636 'Id' => $fieldId,
637 'Name' => $fieldData['Name'],
638 'Type' => $fieldData['Type'],
639 ];
640 }
641 }
642
643 if (count($additionalProps) > 0)
644 {
645 $result[] = [
646 'Id' => $child['Name'],
647 'Type' => $child['Type'],
648 'Title' => $child['Properties']['Title'],
649 'Return' => $additionalProps,
650 ];
651 }
652 }
653
654 if (is_array($child['Children']))
655 {
656 $this->extractChildProperties($child['Children'], $activities, $result);
657 }
658 }
659 }
660}
setDialogFileName($dialogFileName)
Определения propertiesdialog.php:495
setWorkflowTemplate(array $workflowTemplate)
Определения propertiesdialog.php:128
getCurrentValues($compatible=false)
Определения propertiesdialog.php:197
setDocumentType(array $documentType)
Определения propertiesdialog.php:98
setCurrentValues($currentValues)
Определения propertiesdialog.php:304
setWorkflowConstants(array $workflowConstants)
Определения propertiesdialog.php:181
setRuntimeData(array $runtimeData)
Определения propertiesdialog.php:530
renderFieldControl($field, $value=null, $allowSelection=true, $renderMode=FieldType::RENDER_MODE_PUBLIC)
Определения propertiesdialog.php:410
setWorkflowParameters(array $workflowParameters)
Определения propertiesdialog.php:147
setWorkflowVariables(array $workflowVariables)
Определения propertiesdialog.php:166
getCurrentValue($valueKey, $default=null)
Определения propertiesdialog.php:284
__construct($activityFile, array $data=null)
Определения propertiesdialog.php:29
const USER
Определения fieldtype.php:67
static normalizePropertyList(array $props)
Определения fieldtype.php:614
const RENDER_MODE_PUBLIC
Определения fieldtype.php:92
static normalizeProperty($property)
Определения fieldtype.php:548
$children
Определения sync.php:12
$data['IS_AVAILABLE']
Определения .description.php:13
$template
Определения file_edit.php:49
</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
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</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