Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workflow.php
1<?php
3
4use Bitrix\Bizproc\Copy\Implement\WorkflowTemplate as WorkflowTemplateImplementer;
6use Bitrix\Bizproc\Copy\WorkflowTemplate as WorkflowTemplateCopier;
10
11class Workflow implements Child
12{
13 protected $iblockTypeId;
14
15 private $result;
16
17 public function __construct($iblockTypeId)
18 {
19 $this->iblockTypeId = $iblockTypeId;
20
21 $this->result = new Result();
22 }
23
30 public function copy($iblockId, $copiedIblockId): Result
31 {
32 $documentType = $this->getDocumentType($iblockId);
33 $newDocumentType = $this->getDocumentType($copiedIblockId);
34
35 $bizprocHelper = new BizprocHelper($documentType);
36 $templateIdsToCopy = $bizprocHelper->getWorkflowTemplateIds();
37
38 $implementer = $this->getImplementer($newDocumentType);
39 $copier = $this->getCopier($implementer);
40 $this->result = $copier->copy($this->getContainerCollection($templateIdsToCopy));
41
42 return $this->result;
43 }
44
45 protected function getDocumentType(int $iblockId): array
46 {
47 return ["iblock", \CIBlockDocument::class, "iblock_".$iblockId];
48 }
49
50 private function getImplementer(array $documentType)
51 {
52 return new WorkflowTemplateImplementer($documentType);
53 }
54
55 private function getCopier(WorkflowTemplateImplementer $implementer)
56 {
57 return new WorkflowTemplateCopier($implementer);
58 }
59
60 private function getContainerCollection(array $templateIdsToCopy)
61 {
62 $containerCollection = new ContainerCollection();
63
64 foreach ($templateIdsToCopy as $templateId)
65 {
66 $containerCollection[] = new Container($templateId);
67 }
68
69 return $containerCollection;
70 }
71}