Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
fieldtype.php
1<?php
2
4
9
10class FieldType extends Base
11{
12 protected function inputAndAccessCheck(array &$documentType, array &$type): bool
13 {
14 $operationParameters = [];
15
16 if (isset($documentType[3]))
17 {
18 $operationParameters['DocumentCategoryId'] = $documentType[3];
19 }
20
21 $documentType = \CBPHelper::ParseDocumentId($documentType);
22 $type = Bizproc\FieldType::normalizeProperty($type);
23
24 $user = $this->getCurrentUser();
25
26 if (
27 !$user->isAdmin()
28 && !\CBPDocument::CanUserOperateDocumentType(
29 \CBPCanUserOperateOperation::ViewWorkflow,
30 $user->getId(),
31 $documentType,
32 $operationParameters
33 )
34 )
35 {
36 $this->addError(new Error(Loc::getMessage('BIZPROC_ACCESS_DENIED')));
37
38 return false;
39 }
40
41 return true;
42 }
43
44 //TODO: useful?
45 private function renderControlOptionsAction(array $documentType, array $type, array $params)
46 {
47 if (!$this->inputAndAccessCheck($documentType, $type))
48 {
49 return null;
50 }
51
52 $params = (new Bizproc\Validator($params))
53 ->validateRequire('Func')
54 ->validateEnum('Func', [
55 'BPRIASwitchSubTypeControl',
56 'BWFVCSwitchSubTypeControl',
57 'WFSSwitchSubTypeControlC',
58 'WFSSwitchSubTypeControlV',
59 'WFSSwitchSubTypeControlP',
60 ])
61 ->setDefault('Value', '')
62 ->getPureValues();
63
64 $runtime = \CBPRuntime::GetRuntime();
65 $runtime->StartRuntime();
66 $documentService = $runtime->GetService("DocumentService");
67
68 return $documentService->GetFieldInputControlOptions(
69 $documentType,
70 $type,
71 $params['Func'],
72 $params['Value'],
73 );
74 }
75
77 {
78 if (!$this->request->isJson())
79 {
80 // Should add some error message?
81 $this->addError(
82 new Error('', 0, ['reason' => 'Wrong request format. Expected json in request body.'])
83 );
84
85 return null;
86 }
87
88 $documentType = $this->request->getJsonList()->get('documentType');
89 $controlsData = $this->request->getJsonList()->get('controlsData');
90
91 $createInternalError = static fn ($reason) => new Error('', 0, ['reason' => $reason]);
92
93 if (!is_array($documentType))
94 {
95 $this->addError(
96 $createInternalError('Wrong request format. Expected documentType in request json body.')
97 );
98 }
99 if (!is_array($controlsData))
100 {
101 $this->addError(
102 $createInternalError('Wrong request format. Expected controlsData in request json body.')
103 );
104 }
106
107 foreach ($controlsData as $data)
108 {
109 if (
110 is_array($data['property'] ?? null)
111 && is_array($data['params'] ?? null)
112 && $this->inputAndAccessCheck($documentType, $data['property'])
113 )
114 {
115 $property = $this->normalizeProperty($data['property']);
116
117 $params = (new Bizproc\Validator($data['params']))
118 ->validateRequire('Field')
119 ->validateArray('Field', Bizproc\Validator::TYPE_STRING)
120 ->setPureValue('Value')
121 ->setDefault('Value', '')
122 ->validateRequire('Als')
123 ->validateNumeric('Als')
124 ->validateEnum('RenderMode', ['public', 'designer', ''])
125 ->setDefault('RenderMode', '')
126 ->getPureValues()
127 ;
128
129 $renderer->addProperty($documentType, $property, $params);
130 }
131 }
132
133 return new HtmlContent($renderer, additionalResponseParams: $renderer->getRenderedProperties());
134 }
135
136 public function renderControlAction(array $documentType, array $property, array $params)
137 {
138 if (!$this->inputAndAccessCheck($documentType, $property))
139 {
140 return null;
141 }
142
143 $params = (new Bizproc\Validator($params))
144 ->validateRequire('Field')
145 ->validateArray('Field', Bizproc\Validator::TYPE_STRING)
146 ->setPureValue('Value')
147 ->setDefault('Value', '')
148 ->validateRequire('Als')
149 ->validateNumeric('Als')
150 ->validateEnum('RenderMode', ['public', 'designer', ''])
151 ->setDefault('RenderMode', '')
152 ->getPureValues();
153
154 $property = $this->normalizeProperty($property);
155
156 return new HtmlContent(new Response\RenderControlContent($documentType, $property, $params));
157 }
158
159 private function normalizeProperty(array $property): array
160 {
161 if (
162 isset($property['OptionsSort']) && is_array($property['OptionsSort'])
163 && isset($property['Options'])
164 && is_array($property['Options'])
165 && count($property['OptionsSort']) === count($property['Options'])
166 )
167 {
168 $sortedOptions = [];
169 $sortSuccess = true;
170 foreach ($property['OptionsSort'] as $optionKey)
171 {
172 if (!isset($property['Options'][$optionKey]))
173 {
174 $sortSuccess = false;
175 break;
176 }
177 $sortedOptions[$optionKey] = $property['Options'][$optionKey];
178 }
179 if ($sortSuccess)
180 {
181 $property['Options'] = $sortedOptions;
182 }
183 }
184
185 return $property;
186 }
187}
static addError($error)
Definition base.php:278
inputAndAccessCheck(array &$documentType, array &$type)
Definition fieldtype.php:12
renderControlAction(array $documentType, array $property, array $params)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29