Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
templatescope.php
1<?php
2
4
5use Bitrix\Bizproc\WorkflowTemplateTable;
9
11{
13 private $complexDocumentType;
15 private $documentCategoryId;
17 private $documentStatus;
18
20 private $categoryName;
22 private $statusName;
24 private $statusColor;
25
26 public function __construct(array $documentType, $categoryId, string $status)
27 {
28 $this->complexDocumentType = $documentType;
29 $this->documentCategoryId = $categoryId;
30 $this->documentStatus = $status;
31 }
32
33 public function getTemplate(): ?Template
34 {
35 try
36 {
37 $template = new Template($this->complexDocumentType, $this->documentStatus);
38 }
39 catch (\Exception $exception)
40 {
41 $template = null;
42 }
43
44 return $template;
45 }
46
47 public function setNames(?string $categoryName, ?string $statusName): self
48 {
49 $this->categoryName = $categoryName;
50 $this->statusName = $statusName;
51
52 return $this;
53 }
54
55 public function setStatusColor(string $color): self
56 {
57 $this->statusColor = $color;
58
59 return $this;
60 }
61
62 public function getId(): string
63 {
64 return "{$this->getModuleId()}_{$this->getDocumentType()}_{$this->getCategoryId()}_{$this->getStatusId()}";
65 }
66
67 public function getModuleId(): string
68 {
69 return $this->getComplexDocumentType()[0];
70 }
71
72 public function getEntity(): string
73 {
74 return $this->getComplexDocumentType()[1];
75 }
76
77 public function getDocumentType(): string
78 {
79 return $this->getComplexDocumentType()[2];
80 }
81
82 public function getComplexDocumentType(): array
83 {
84 return $this->complexDocumentType;
85 }
86
87 public function getCategoryId()
88 {
89 return $this->documentCategoryId;
90 }
91
92 public function getStatusId(): string
93 {
94 return $this->documentStatus;
95 }
96
97 public function toArray(): array
98 {
99 $documentService = \CBPRuntime::GetRuntime(true)->getDocumentService();
100
101 return [
102 'DocumentType' => [
103 'Type' => $this->getComplexDocumentType(),
104 'Name' => $documentService->getDocumentTypeName($this->complexDocumentType),
105 ],
106 'Category' => [
107 'Id' => $this->getCategoryId(),
108 'Name' => $this->categoryName,
109 ],
110 'Status' => [
111 'Id' => $this->getStatusId(),
112 'Name' => $this->statusName,
113 'Color' => $this->statusColor,
114 ],
115 ];
116 }
117
118 public static function fromArray(array $rawScope): ?TemplateScope
119 {
120 if (
121 is_array($rawScope['DocumentType'] ?? null)
122 && is_array($rawScope['Category'] ?? null)
123 && is_array($rawScope['Status'] ?? null)
124 )
125 {
126 $scope = new static(
127 $rawScope['DocumentType']['Type'] ?? [],
128 $rawScope['Category']['Id'] ?? null,
129 $rawScope['Status']['Id'] ?? '',
130 );
131 $scope->setNames(
132 $rawScope['Category']['Name'] ?? null,
133 $rawScope['Status']['Name'] ?? null
134 );
135
136 if (isset($rawScope['Status']['Color']) && is_string($rawScope['Status']['Color']))
137 {
138 $scope->setStatusColor($rawScope['Status']['Color']);
139 }
140
141 return $scope;
142 }
143
144 return null;
145 }
146}
setNames(?string $categoryName, ?string $statusName)
__construct(array $documentType, $categoryId, string $status)