Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
tpl.php
1<?php
3
5use CBPWorkflowTemplateLoader;
6
7class Tpl extends Entity\EO_WorkflowTemplate
8{
9 protected $tpl;
10
11 public function getRootActivity()
12 {
13 return $this->getActivities()[0];
14 }
15
16 public function findActivity($activityName)
17 {
18 return CBPWorkflowTemplateLoader::FindActivityByName($this->getActivities(), $activityName);
19 }
20
21 public function getDocumentComplexType()
22 {
23 return [$this->getModuleId(), $this->getEntity(), $this->getDocumentType()];
24 }
25
26 public function getActivities()
27 {
28 return $this->getTemplate();
29 }
30
35 public function collectUsages()
36 {
38 if ($this->getId())
39 {
40 $rootActivity = CBPWorkflowTemplateLoader::GetLoader()->LoadWorkflow($this->getId())[0];
41 }
42 else
43 {
44 $rootActivity = CBPWorkflowTemplateLoader::GetLoader()->loadWorkflowFromArray([
45 'ID' => '0',
46 'TEMPLATE' => $this->getTemplate(),
47 'VARIABLES' => $this->getVariables(),
48 'PARAMETERS' => $this->getParameters(),
49 ])[0];
50 }
51
52 $rootActivity->SetProperties($this->getParameters());
53 $rootActivity->SetVariablesTypes($this->getVariables());
54
55 $usages = new Collection\Usages();
56 $this->findActivityUsagesRecursive($rootActivity, $usages);
57
58 return $usages;
59 }
60
61 public function findUsedSourceKeys($sourceType)
62 {
63 if (!SourceType::isType($sourceType))
64 {
65 throw new ArgumentException('Incorrect $sourceType', 'sourceType');
66 }
67
68 $usages = $this->collectUsages();
69 return array_unique(array_column($usages->getBySourceType($sourceType), 1));
70 }
71
72 private function findActivityUsagesRecursive(\CBPActivity $activity, Collection\Usages $usages)
73 {
74 $sources = $activity->collectUsages();
75 $usages->addOwnerSources($activity->GetName(), $sources);
76
77 $children = $activity->CollectNestedActivities();
78 if (is_array($children))
79 {
80 foreach ($children as $child)
81 {
82 $this->findActivityUsagesRecursive($child, $usages);
83 }
84 }
85 return $usages;
86 }
87
88 public function getUsedActivityTypes()
89 {
90 return array_unique($this->getActivityTypes($this->getTemplate()));
91 }
92
93 private function getActivityTypes(array $activities)
94 {
95 $types = [];
96 foreach ($activities as $activity)
97 {
98 $types[] = $activity['Type'];
99
100 if (!empty($activity['Children']))
101 {
102 $types = array_merge($types, $this->getActivityTypes($activity['Children']));
103 }
104 }
105 return $types;
106 }
107}