Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workflowtemplate.php
1<?php
3
6
8{
9 const WORKFLOW_TEMPLATE_COPY_ERROR = 'WORKFLOW_TEMPLATE_COPY_ERROR';
10
11 protected $targetDocumentType = [];
13
14 protected $result;
15
17 {
18 $this->targetDocumentType = $targetDocumentType;
19 $this->mapStatusIdsCopiedDocument = $mapStatusIdsCopiedDocument;
20
21 $this->result = new Result();
22 }
23
24 public function getFields($workflowTemplateId)
25 {
26 $queryResult = \CBPWorkflowTemplateLoader::getList([], ['ID' => $workflowTemplateId]);
27 return (($fields = $queryResult->fetch()) ? $fields : []);
28 }
29
30 public function prepareFieldsToCopy(array $fields)
31 {
32 if (isset($fields['ID']))
33 {
34 unset($fields['ID']);
35 }
36
37 if ($this->targetDocumentType)
38 {
39 $fields['DOCUMENT_TYPE'] = $this->targetDocumentType;
40 }
41
42 if (array_key_exists($fields['DOCUMENT_STATUS'], $this->mapStatusIdsCopiedDocument))
43 {
44 $fields['DOCUMENT_STATUS'] = $this->mapStatusIdsCopiedDocument[$fields['DOCUMENT_STATUS']];
45 }
46
47 return $fields;
48 }
49
50 public function add(array $fields)
51 {
52 $result = false;
53
54 if ($fields)
55 {
56 $result = \CBPWorkflowTemplateLoader::add($fields, true);
57 }
58
59 if (!$result)
60 {
61 $this->result->addError(
62 new Error('Failed to copy workflow template', self::WORKFLOW_TEMPLATE_COPY_ERROR)
63 );
64 }
65
66 return $result;
67 }
68}
__construct($targetDocumentType=[], $mapStatusIdsCopiedDocument=[])