1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
baseactivity.php
См. документацию.
1<?php
2
4
13
14abstract class BaseActivity extends \CBPActivity
15{
16 protected static $requiredModules = [];
17 protected $preparedProperties = [];
18
19 public function __get($name)
20 {
21 return $this->preparedProperties[$name] ?? parent::__get($name);
22 }
23
24 public function execute()
25 {
26 if (!static::checkModules())
27 {
28 return \CBPActivityExecutionStatus::Closed;
29 }
30 $this->prepareProperties();
31
32 $errorCollection = $this->checkProperties();
33 if ($errorCollection->isEmpty())
34 {
35 $errorCollection = $this->internalExecute();
36 }
37
38 foreach ($errorCollection as $error)
39 {
40 $this->logError($error->getMessage());
41 }
42
43 return \CBPActivityExecutionStatus::Closed;
44 }
45
46 protected function prepareProperties(): void
47 {
48 $fieldsMap = static::getPropertiesDialogMap();
49
50 foreach (array_keys($this->arProperties) as $propertyId)
51 {
52 $propertyValue = $this->getRawProperty($propertyId);
53
54 $type = '';
55 if (isset($this->arPropertiesTypes) && isset($this->arPropertiesTypes[$propertyId]))
56 {
57 $type = $this->arPropertiesTypes[$propertyId]['Type'] ?? '';
58 }
59 if (!$type && isset($fieldsMap[$propertyId]))
60 {
61 $type = $fieldsMap[$propertyId]['Type'] ?? '';
62 }
63
64 $parsedValue = $this->ParseValue($propertyValue);
65 $this->preparedProperties[$propertyId] = $this->convertPropertyValue($type, $parsedValue);
66 }
67 }
68
69 protected function convertPropertyValue(string $type, $value)
70 {
71 if ($value === null)
72 {
73 return null;
74 }
75
76 switch ($type)
77 {
78 case FieldType::INT:
79 if (is_array($value))
80 {
81 if (count($value) === 1)
82 {
83 $value = array_shift($value);
84 }
85 else
86 {
87 $value = 0;
88 // to avoid situation when casting array to int returns 1 (element with such ID can exist)
89 // and other situations when value can be ambiguous so it's impossible to cast it to int
90 }
91 }
92 return (int)$value;
93
94 case FieldType::BOOL:
95 return \CBPHelper::getBool($value);
96
98 return (double)$value;
99
100 default:
101 return $value;
102 }
103 }
104
105 protected function checkProperties(): ErrorCollection
106 {
107 return new ErrorCollection();
108 }
109
110 protected function internalExecute(): ErrorCollection
111 {
112 return new ErrorCollection();
113 }
114
115 protected function logError(string $message = '', int $userId = 0): void
116 {
118 }
119
120 protected function log(string $message = '', int $userId = 0, int $type = -1): void
121 {
122 $this->WriteToTrackingService($message, $userId, $type);
123 }
124
125 public static function getPropertiesDialog(
126 $documentType,
127 $activityName,
128 $workflowTemplate,
129 $workflowParameters,
130 $workflowVariables,
131 $currentValues = null,
132 $formName = '',
133 $popupWindow = null,
134 $siteId = ''
135 )
136 {
137 if (!static::checkModules())
138 {
139 return false;
140 }
141
142 $dialog = new \Bitrix\Bizproc\Activity\PropertiesDialog(static::getFileName(), [
143 'documentType' => $documentType,
144 'activityName' => $activityName,
145 'workflowTemplate' => $workflowTemplate,
146 'workflowParameters' => $workflowParameters,
147 'workflowVariables' => $workflowVariables,
148 'currentValues' => $currentValues,
149 'formName' => $formName,
150 'siteId' => $siteId
151 ]);
152
153 $dialog
154 ->setMapCallback([static::class, 'getPropertiesDialogMap'])
155 ->setRuntimeData(static::getRuntimeData())
156 ;
157
158 if (!static::hasRenderer())
159 {
160 $dialog->setRenderer([static::class, 'renderPropertiesDialog']);
161 }
162
163 return $dialog;
164 }
165
166 private static function hasRenderer(): bool
167 {
168 $dir = Path::getDirectory(Path::normalize(static::getFileName()));
169
170 return
171 File::isFileExists(Path::combine($dir, 'properties_dialog.php'))
172 || File::isFileExists(Path::combine($dir, 'robot_properties_dialog.php'))
173 ;
174 }
175
176 public static function renderPropertiesDialog(PropertiesDialog $dialog)
177 {
178 $propertiesDialogHtml = '';
179 $isRobot = $dialog->getDialogFileName() === 'robot_properties_dialog.php';
180 foreach ($dialog->getMap() as $field)
181 {
182 $propertiesDialogHtml .=
183 $isRobot
184 ? static::renderRobotProperty($dialog, $field)
185 : static::renderBizprocProperty($dialog, $field)
186 ;
187 }
188
189 return $propertiesDialogHtml;
190 }
191
192 protected static function renderBizprocProperty(PropertiesDialog $dialog, array $field): string
193 {
194 $controlHtml = $dialog->renderFieldControl(
195 $field,
196 $dialog->getCurrentValue($field),
197 true,
199 );
200
201 return sprintf(
202 '<tr><td align="right" width="40%%">%s:</td><td width="60%%">%s</td></tr>',
203 htmlspecialcharsbx($field['Name']),
204 $controlHtml
205 );
206 }
207
208 protected static function renderRobotProperty(PropertiesDialog $dialog, array $field): string
209 {
210 $propertyHtml = '
211 <div class="bizproc-automation-popup-settings">
212 <span class="bizproc-automation-popup-settings-title bizproc-automation-popup-settings-title-autocomplete">
213 %s:
214 </span>
215 %s
216 </div>
217 ';
218
219 return sprintf(
220 $propertyHtml,
221 htmlspecialcharsbx($field['Name']),
222 $dialog->renderFieldControl($field, $dialog->getCurrentValue($field))
223 );
224 }
225
226 public static function getPropertiesDialogValues(
227 $documentType,
228 $activityName,
229 &$workflowTemplate,
230 &$workflowParameters,
231 &$workflowVariables,
233 &$errors
234 ): bool
235 {
236 if (!static::checkModules())
237 {
238 return false;
239 }
240
241 $dialog = new PropertiesDialog(static::getFileName(), [
242 'documentType' => $documentType,
243 'activityName' => $activityName,
244 'workflowTemplate' => $workflowTemplate,
245 'workflowParameters' => $workflowParameters,
246 'workflowVariables' => $workflowVariables,
247 'currentValues' => $currentValues,
248 ]);
249
250 $extractingResult = static::extractPropertiesValues($dialog, static::getPropertiesDialogMap($dialog));
251 if (!$extractingResult->isSuccess())
252 {
253 foreach ($extractingResult->getErrors() as $error)
254 {
255 $errors[] = [
256 'code' => $error->getCode(),
257 'message' => $error->getMessage(),
258 'parameter' => $error->getCustomData(),
259 ];
260 }
261 }
262 else
263 {
264 $errors = static::ValidateProperties(
265 $extractingResult->getData(),
267 );
268 }
269
270 if ($errors)
271 {
272 return false;
273 }
274
275 $currentActivity = &\CBPWorkflowTemplateLoader::FindActivityByName(
276 $workflowTemplate,
277 $activityName
278 );
279 $currentActivity['Properties'] = $extractingResult->getData();
280
281 return true;
282 }
283
284 protected static function extractPropertiesValues(PropertiesDialog $dialog, array $fieldsMap): Result
285 {
286 $result = new Result();
287
288 $properties = [];
289 $errors = [];
290 $currentValues = $dialog->getCurrentValues();
291 $documentService = static::getDocumentService();
292
293 foreach ($fieldsMap as $propertyKey => $fieldProperties)
294 {
295 $field = $documentService->getFieldTypeObject($dialog->getDocumentType(), $fieldProperties);
296 if(!$field)
297 {
298 continue;
299 }
300
301 $properties[$propertyKey] = $field->extractValue(
302 ['Field' => $fieldProperties['FieldName']],
304 $errors
305 );
306 }
307
308 if ($errors)
309 {
310 foreach ($errors as $error)
311 {
312 $result->addError(
313 new Error(
314 $error['message'] ?? '',
315 $error['code'] ?? '',
316 $error['parameter'] ?? ''
317 )
318 );
319 }
320 }
321 else
322 {
323 $result->setData($properties);
324 }
325
326 return $result;
327 }
328
329 abstract protected static function getFileName(): string;
330
331 public static function validateProperties($testProperties = [], \CBPWorkflowTemplateUser $user = null)
332 {
333 $errors = [];
334
335 if (!static::checkModules())
336 {
337 return $errors;
338 }
339
340 foreach (static::getPropertiesDialogMap() as $propertyKey => $fieldProperties)
341 {
342 if(
343 \CBPHelper::getBool($fieldProperties['Required'] ?? null)
344 && \CBPHelper::isEmptyValue($testProperties[$propertyKey] ?? null)
345 )
346 {
347 $errors[] = [
348 'code' => 'NotExist',
349 'parameter' => 'FieldValue',
350 'message' => Loc::getMessage('BIZPROC_BA_EMPTY_PROP', ['#PROPERTY#' => $fieldProperties['Name']]),
351 ];
352 }
353 }
354
355 return array_merge($errors, parent::ValidateProperties($testProperties, $user));
356 }
357
358 protected static function checkModules(): bool
359 {
360 foreach (static::$requiredModules as $module)
361 {
362 if (!Loader::includeModule($module))
363 {
364 return false;
365 }
366 }
367
368 return true;
369 }
370
371 protected static function getDocumentService(): \CBPDocumentService
372 {
373 return \CBPRuntime::GetRuntime(true)->getDocumentService();
374 }
375
376 public static function getPropertiesDialogMap(?PropertiesDialog $dialog = null): array
377 {
378 return [];
379 }
380
381 protected static function getRuntimeData(): array
382 {
383 return [];
384 }
385}
$popupWindow
Определения access_edit.php:10
$type
Определения options.php:106
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getPropertiesDialogValues( $documentType, $activityName, &$workflowTemplate, &$workflowParameters, &$workflowVariables, $currentValues, &$errors)
Определения baseactivity.php:226
static getDocumentService()
Определения baseactivity.php:371
convertPropertyValue(string $type, $value)
Определения baseactivity.php:69
static getPropertiesDialog( $documentType, $activityName, $workflowTemplate, $workflowParameters, $workflowVariables, $currentValues=null, $formName='', $popupWindow=null, $siteId='')
Определения baseactivity.php:125
static validateProperties($testProperties=[], \CBPWorkflowTemplateUser $user=null)
Определения baseactivity.php:331
logError(string $message='', int $userId=0)
Определения baseactivity.php:115
static getPropertiesDialogMap(?PropertiesDialog $dialog=null)
Определения baseactivity.php:376
log(string $message='', int $userId=0, int $type=-1)
Определения baseactivity.php:120
static extractPropertiesValues(PropertiesDialog $dialog, array $fieldsMap)
Определения baseactivity.php:284
static renderPropertiesDialog(PropertiesDialog $dialog)
Определения baseactivity.php:176
static renderBizprocProperty(PropertiesDialog $dialog, array $field)
Определения baseactivity.php:192
static renderRobotProperty(PropertiesDialog $dialog, array $field)
Определения baseactivity.php:208
getCurrentValues($compatible=false)
Определения propertiesdialog.php:197
renderFieldControl($field, $value=null, $allowSelection=true, $renderMode=FieldType::RENDER_MODE_PUBLIC)
Определения propertiesdialog.php:410
getCurrentValue($valueKey, $default=null)
Определения propertiesdialog.php:284
const RENDER_MODE_DESIGNER
Определения fieldtype.php:77
const BOOL
Определения fieldtype.php:17
const INT
Определения fieldtype.php:42
const DOUBLE
Определения fieldtype.php:32
Определения error.php:15
Определения path.php:12
Определения loader.php:13
Определения activity.php:8
string $name
Определения activity.php:38
getRawProperty($name)
Определения activity.php:1018
const Error
Определения trackingservice.php:706
</td ></tr ></table ></td ></tr ><?endif?><? $propertyIndex=0;foreach( $arGlobalProperties as $propertyCode=> $propertyValue
Определения file_new.php:729
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if($request->isPost() && $currentAction !==null &&check_bitrix_sessid()) $currentValues
Определения options.php:198
$errors
Определения iblock_catalog_edit.php:74
$siteId
Определения ajax.php:8
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
Определения Image.php:9
$user
Определения mysql_to_pgsql.php:33
$message
Определения payment.php:8
$dir
Определения quickway.php:303
</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
$error
Определения subscription_card_product.php:20