1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
fieldtype.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\Controller;
4
5use Bitrix\Main\Engine\Response\HtmlContent;
6use Bitrix\Main\Error;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Bizproc;
9
10class FieldType extends Base
11{
12 protected function inputAndAccessCheck(
13 array &$documentType,
14 array &$type,
16 ?array $documentId = null,
17 ): bool
18 {
19 $operationParameters = [];
20
21 if (isset($documentType[3]))
22 {
23 $operationParameters['DocumentCategoryId'] = $documentType[3];
24 }
25
26 $documentType = \CBPHelper::ParseDocumentId($documentType);
28
29 $user = $this->getCurrentUser();
30
31 if ($user->isAdmin())
32 {
33 return true;
34 }
35
36 if ($operation === \CBPCanUserOperateOperation::StartWorkflow && is_array($documentId))
37 {
38 $documentId = \CBPHelper::parseDocumentId($documentId);
39 $hasAccess = \CBPDocument::canUserOperateDocument(
40 $operation,
41 $user->getId(),
42 $documentId,
43 $operationParameters
44 );
45 }
46 else
47 {
48 $hasAccess = \CBPDocument::canUserOperateDocumentType(
49 $operation,
50 $user->getId(),
51 $documentType,
52 $operationParameters
53 );
54 }
55
56 if (!$hasAccess)
57 {
58 $this->addError(new Error(Loc::getMessage('BIZPROC_ACCESS_DENIED')));
59
60 return false;
61 }
62
63 return true;
64 }
65
66 //TODO: useful?
67 private function renderControlOptionsAction(array $documentType, array $type, array $params)
68 {
69 if (!$this->inputAndAccessCheck($documentType, $type))
70 {
71 return null;
72 }
73
75 ->validateRequire('Func')
76 ->validateEnum('Func', [
77 'BPRIASwitchSubTypeControl',
78 'BWFVCSwitchSubTypeControl',
79 'WFSSwitchSubTypeControlC',
80 'WFSSwitchSubTypeControlV',
81 'WFSSwitchSubTypeControlP',
82 ])
83 ->setDefault('Value', '')
84 ->getPureValues();
85
86 $runtime = \CBPRuntime::GetRuntime();
87 $runtime->StartRuntime();
88 $documentService = $runtime->GetService("DocumentService");
89
90 return $documentService->GetFieldInputControlOptions(
91 $documentType,
92 $type,
93 $params['Func'],
94 $params['Value'],
95 );
96 }
97
99 {
100 $createInternalError = static fn ($reason) => new Error('', 0, ['reason' => $reason]);
101
102 if (!$this->request->isJson())
103 {
104 // Should add some error message?
105 $this->addError(
106 $createInternalError('Wrong request format. Expected json in request body.'),
107 );
108
109 return null;
110 }
111
112 $documentType = $this->request->getJsonList()->get('documentType');
113 $controlsData = $this->request->getJsonList()->get('controlsData');
114
115 $accessCheckOperation = \CBPCanUserOperateOperation::ViewWorkflow;
116
117 $context = $this->request->getJsonList()->get('context') ?? [];
118 $documentId = null;
119 if (isset($context['signedDocumentId']))
120 {
121 $documentId = \CBPDocument::unSignDocumentType($context['signedDocumentId']);
122 if ($documentId && isset($context['isStartWorkflow']) && $context['isStartWorkflow'] === true)
123 {
124 $accessCheckOperation = \CBPCanUserOperateOperation::StartWorkflow;
125 }
126 }
127
128 if (!is_array($documentType))
129 {
130 $this->addError(
131 $createInternalError('Wrong request format. Expected documentType in request json body.')
132 );
133 }
134 if (!is_array($controlsData))
135 {
136 $this->addError(
137 $createInternalError('Wrong request format. Expected controlsData in request json body.')
138 );
139 }
141
142 foreach ($controlsData as $data)
143 {
144 if (
145 is_array($data['property'] ?? null)
146 && is_array($data['params'] ?? null)
147 && $this->inputAndAccessCheck(
148 $documentType,
149 $data['property'],
150 $accessCheckOperation,
151 $documentId
152 )
153 )
154 {
155 $property = $this->normalizeProperty($data['property']);
156
157 $params = (new Bizproc\Validator($data['params']))
158 ->validateRequire('Field')
159 ->validateArray('Field', Bizproc\Validator::TYPE_STRING)
160 ->setPureValue('Value')
161 ->setDefault('Value', '')
162 ->validateRequire('Als')
163 ->validateNumeric('Als')
164 ->validateEnum('RenderMode', ['public', 'designer', ''])
165 ->setDefault('RenderMode', '')
166 ->getPureValues()
167 ;
168
169 $renderer->addProperty($documentType, $property, $params);
170 }
171 }
172
173 return new HtmlContent($renderer);
174 }
175
176 public function renderControlAction(array $documentType, array $property, array $params)
177 {
178 if (!$this->inputAndAccessCheck($documentType, $property))
179 {
180 return null;
181 }
182
184 ->validateRequire('Field')
185 ->validateArray('Field', Bizproc\Validator::TYPE_STRING)
186 ->setPureValue('Value')
187 ->setDefault('Value', '')
188 ->validateRequire('Als')
189 ->validateNumeric('Als')
190 ->validateEnum('RenderMode', ['public', 'designer', ''])
191 ->setDefault('RenderMode', '')
192 ->getPureValues();
193
194 $property = $this->normalizeProperty($property);
195
196 return new HtmlContent(new Response\RenderControlContent($documentType, $property, $params));
197 }
198
199 private function normalizeProperty(array $property): array
200 {
201 if (
202 isset($property['OptionsSort']) && is_array($property['OptionsSort'])
203 && isset($property['Options'])
204 && is_array($property['Options'])
205 && count($property['OptionsSort']) === count($property['Options'])
206 )
207 {
208 $sortedOptions = [];
209 $sortSuccess = true;
210 foreach ($property['OptionsSort'] as $optionKey)
211 {
212 if (!isset($property['Options'][$optionKey]))
213 {
214 $sortSuccess = false;
215 break;
216 }
217 $sortedOptions[$optionKey] = $property['Options'][$optionKey];
218 }
219 if ($sortSuccess)
220 {
221 $property['Options'] = $sortedOptions;
222 }
223 }
224
225 return $property;
226 }
227}
$type
Определения options.php:106
static addError($error)
Определения base.php:278
inputAndAccessCheck(array &$documentType, array &$type, int $operation=\CBPCanUserOperateOperation::ViewWorkflow, ?array $documentId=null,)
Определения fieldtype.php:12
renderControlCollectionAction()
Определения fieldtype.php:98
renderControlAction(array $documentType, array $property, array $params)
Определения fieldtype.php:176
static normalizeProperty($property)
Определения fieldtype.php:548
const TYPE_STRING
Определения validator.php:12
Определения error.php:15
const ViewWorkflow
Определения constants.php:211
const StartWorkflow
Определения constants.php:212
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$context
Определения csv_new_setup.php:223
$user
Определения mysql_to_pgsql.php:33
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799