Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
templatesscheme.php
1<?php
2
4
8
9abstract class TemplatesScheme
10{
11 public const ERROR_CODE_MISSING_TEMPLATE_ERROR = 'TEMPLATES_SCHEME_ERROR_CODE_TEMPLATE_ERROR';
12 public const ERROR_CODE_GETTING_TEMPLATE_ERROR = 'TEMPLATES_SCHEME_ERROR_CODE_TEMPLATE_ERROR';
13
15 private $scheme = [];
16
17 public function isAutomationAvailable(array $complexDocumentType): bool
18 {
19 return true;
20 }
21
22 public function addTemplate(TemplateScope $scope)
23 {
24 $this->scheme[$scope->getId()] = $scope;
25 }
26
27 public function getTemplate(TemplateScope $scope): ?Template
28 {
29 if ($this->hasTemplate($scope))
30 {
31 return new Template($scope->getComplexDocumentType(), $scope->getStatusId());
32 }
33
34 return null;
35 }
36
37 public function toArray(): array
38 {
39 $scheme = [];
40 foreach ($this->scheme as $scopeId => $scope)
41 {
42 $scheme[$scopeId] = $scope->toArray();
43 }
44
45 return $scheme;
46 }
47
48 protected function hasTemplate(TemplateScope $scope): bool
49 {
50 return isset($this->scheme[$scope->getId()]);
51 }
52
53 public function createTemplatesTunnel(TemplateScope $srcScope, TemplateScope $dstScope): Result
54 {
55 $result = new Result();
56 if (!$this->hasTemplate($srcScope) || !$this->hasTemplate($dstScope))
57 {
58 $errorMessage = Loc::getMessage('BIZPROC_AUTOMATION_SCHEME_TEMPLATE_ERROR');
59 $result->addError(new Error($errorMessage, self::ERROR_CODE_MISSING_TEMPLATE_ERROR));
60 }
61
62 $srcTemplate = $srcScope->getTemplate();
63 $dstTemplate = $dstScope->getTemplate();
64
65 if (
66 is_null($srcTemplate)
67 || is_null($dstTemplate)
68 )
69 {
70 $errorMessage = Loc::getMessage('BIZPROC_AUTOMATION_SCHEME_TEMPLATE_ERROR');
71 $result->addError(new Error($errorMessage, self::ERROR_CODE_GETTING_TEMPLATE_ERROR));
72 }
73 elseif ($result->isSuccess())
74 {
75 $result->setData(['templatesTunnel' => new TemplatesTunnel($srcTemplate, $dstTemplate)]);
76 }
77
78 return $result;
79 }
80
81 abstract public function build(): void;
82}
createTemplatesTunnel(TemplateScope $srcScope, TemplateScope $dstScope)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29