52 if(!static::$instance)
54 static::$instance =
new static();
56 return static::$instance;
103 if($fieldInfo[
'USER_TYPE_ID'] === \CUserTypeEnum::USER_TYPE_ID)
108 $addFieldInfo = array(
109 'ENTITY_ID' => $fieldInfo[
'ENTITY_ID'],
110 'FIELD' => $fieldInfo[
'FIELD'],
111 'CONTEXT' => $fieldInfo[
'CONTEXT'] ??
null,
114 $addFieldInfo[
'SIGNATURE'] = $this->
getSignature($addFieldInfo);
116 $this->
storeFieldSignature($addFieldInfo[
'ENTITY_ID'], $addFieldInfo[
'FIELD'], $addFieldInfo[
'SIGNATURE']);
131 $currentFieldInfo = $this->
getUserFieldInfo($fieldInfo[
'ENTITY_ID'], $fieldInfo[
'FIELD']);
136 if($currentFieldInfo[
'USER_TYPE_ID'] === \CUserTypeEnum::USER_TYPE_ID)
143 $addFieldInfo = array(
144 'ENTITY_ID' => $fieldInfo[
'ENTITY_ID'],
145 'ENTITY_VALUE_ID' => $fieldInfo[
'ENTITY_VALUE_ID'],
146 'FIELD' => $fieldInfo[
'FIELD'],
147 'VALUE' => $fieldInfo[
'VALUE'],
148 'CONTEXT' => $fieldInfo[
'CONTEXT'],
151 $addFieldInfo[
'SIGNATURE'] = $this->
getSignature($addFieldInfo);
153 $this->
storeFieldSignature($addFieldInfo[
'ENTITY_ID'], $addFieldInfo[
'FIELD'], $addFieldInfo[
'SIGNATURE']);
169 $userFieldInfo = $this->
getUserFieldInfo($fieldInfo[
'ENTITY_ID'], $fieldInfo[
'FIELD']);
173 $this->
addError(
'Field not found', $fieldInfo[
'FIELD']);
177 $userTypeEntity = new \CUserTypeEntity();
178 $deleteResult = $userTypeEntity->delete($userFieldInfo[
'ID']);
197 $userFieldInfo = $this->
getUserFieldInfo($fieldInfo[
'ENTITY_ID'], $fieldInfo[
'FIELD']);
201 $this->
addError(
'Field not found', $fieldInfo[
'FIELD']);
205 if(!isset($this->validateFieldList[$fieldInfo[
'ENTITY_ID']]))
207 $this->validateFieldList[$fieldInfo[
'ENTITY_ID']] = array();
210 if(!isset($this->validateFieldList[$fieldInfo[
'ENTITY_ID']][$fieldInfo[
'ENTITY_VALUE_ID']]))
212 $this->validateFieldList[$fieldInfo[
'ENTITY_ID']][$fieldInfo[
'ENTITY_VALUE_ID']] = array();
215 $this->validateFieldList[$fieldInfo[
'ENTITY_ID']][$fieldInfo[
'ENTITY_VALUE_ID']][$fieldInfo[
'FIELD']] = $fieldInfo[
'VALUE'];
219 protected function processValidate()
221 global $APPLICATION, $USER_FIELD_MANAGER;
223 foreach($this->validateFieldList as $entityId => $entityFields)
225 foreach($entityFields as $entityValueId =>
$fieldList)
227 $validateResult = $USER_FIELD_MANAGER->CheckFields($entityId, $entityValueId,
$fieldList);
231 $e = $APPLICATION->GetException();
235 $errorMessages = $e->GetMessages();
237 foreach($errorMessages as $message)
239 $this->
addError($message[
'text'], $message[
'id']);
245 $this->result = array_merge($this->result, $this->getValidateErrorList());
251 $userTypeEntity = new \CUserTypeEntity();
252 $fieldId = $userTypeEntity->add(array(
253 'ENTITY_ID' => $fieldInfo[
'ENTITY_ID'],
254 'FIELD_NAME' => $fieldInfo[
'FIELD'],
255 'USER_TYPE_ID' => $fieldInfo[
'USER_TYPE_ID'],
256 'MULTIPLE' => $fieldInfo[
'MULTIPLE'],
257 'MANDATORY' => $fieldInfo[
'MANDATORY'],
258 'SHOW_FILTER' => $fieldInfo[
'SHOW_FILTER'] ??
null,
259 'SHOW_IN_LIST' => $fieldInfo[
'SHOW_IN_LIST'] ??
null,
260 'EDIT_IN_LIST' => $fieldInfo[
'EDIT_IN_LIST'] ??
null,
261 'IS_SEARCHABLE' => $fieldInfo[
'IS_SEARCHABLE'] ??
null,
262 'SETTINGS' => $fieldInfo[
'SETTINGS'] ??
null,
263 'EDIT_FORM_LABEL' => $this->
checkLabel($fieldInfo[
'EDIT_FORM_LABEL'] ??
null),
264 'LIST_COLUMN_LABEL' => $this->
checkLabel($fieldInfo[
'LIST_COLUMN_LABEL'] ??
null),
265 'LIST_FILTER_LABEL' => $this->
checkLabel($fieldInfo[
'LIST_FILTER_LABEL'] ??
null),
266 'ERROR_MESSAGE' => $this->
checkLabel($fieldInfo[
'ERROR_MESSAGE'] ??
null),
267 'HELP_MESSAGE' => $this->
checkLabel($fieldInfo[
'HELP_MESSAGE'] ??
null),
268 'CONTEXT_PARAMS' => $fieldInfo[
'CONTEXT_PARAMS'] ??
null,
281 $userFieldInfo = $this->
getUserFieldInfo($fieldInfo[
'ENTITY_ID'], $fieldInfo[
'FIELD']);
283 if(is_array($userFieldInfo))
285 $updateField = array();
287 if(array_key_exists(
'MANDATORY', $fieldInfo))
289 $updateField[
'MANDATORY'] = $fieldInfo[
'MANDATORY'];
292 if(array_key_exists(
'SHOW_FILTER', $fieldInfo))
294 $updateField[
'SHOW_FILTER'] = $fieldInfo[
'SHOW_FILTER'];
297 if(array_key_exists(
'SHOW_IN_LIST', $fieldInfo))
299 $updateField[
'SHOW_IN_LIST'] = $fieldInfo[
'SHOW_IN_LIST'];
302 if(array_key_exists(
'EDIT_IN_LIST', $fieldInfo))
304 $updateField[
'EDIT_IN_LIST'] = $fieldInfo[
'EDIT_IN_LIST'];
307 if(array_key_exists(
'IS_SEARCHABLE', $fieldInfo))
309 $updateField[
'IS_SEARCHABLE'] = $fieldInfo[
'IS_SEARCHABLE'];
312 if(array_key_exists(
'EDIT_FORM_LABEL', $fieldInfo))
314 $updateField[
'EDIT_FORM_LABEL'] = $this->
checkLabel($fieldInfo[
'EDIT_FORM_LABEL']);
317 if(array_key_exists(
'LIST_COLUMN_LABEL', $fieldInfo))
319 $updateField[
'LIST_COLUMN_LABEL'] = $this->
checkLabel($fieldInfo[
'LIST_COLUMN_LABEL']);
322 if(array_key_exists(
'LIST_FILTER_LABEL', $fieldInfo))
324 $updateField[
'LIST_FILTER_LABEL'] = $this->
checkLabel($fieldInfo[
'LIST_FILTER_LABEL']);
327 if(array_key_exists(
'ERROR_MESSAGE', $fieldInfo))
329 $updateField[
'ERROR_MESSAGE'] = $this->
checkLabel($fieldInfo[
'ERROR_MESSAGE']);
332 if(array_key_exists(
'HELP_MESSAGE', $fieldInfo))
334 $updateField[
'HELP_MESSAGE'] = $this->
checkLabel($fieldInfo[
'HELP_MESSAGE']);
337 if(array_key_exists(
'SETTINGS', $fieldInfo) && is_array($fieldInfo[
'SETTINGS']))
339 $updateField[
'SETTINGS'] = array_merge($userFieldInfo[
'SETTINGS'], $fieldInfo[
'SETTINGS']);
342 if(!empty($updateField))
344 $userTypeEntity = new \CUserTypeEntity();
345 $updateResult = $userTypeEntity->update($userFieldInfo[
'ID'], $updateField);
355 return $userFieldInfo[
'ID'];
360 if(array_key_exists(
'ENUM', $fieldInfo) && is_array($fieldInfo[
'ENUM']))
362 $enumValuesManager = new \CUserFieldEnum();
364 $enum = array_values($fieldInfo[
'ENUM']);
365 $enumValues = array();
366 foreach($enum as $key => $valueDescription)
368 if(is_array($valueDescription))
370 $enumValues[
'n'.$key] = array(
371 'XML_ID' => $valueDescription[
'XML_ID'],
372 'VALUE' => $valueDescription[
'VALUE'],
373 'DEF' => $valueDescription[
'DEF'] ===
'Y' ?
'Y' :
'N',
374 'SORT' => $valueDescription[
'SORT'],
378 $setEnumResult = $enumValuesManager->setEnumValues($fieldId, $enumValues);
389 array_key_exists(
'ENUM', $fieldInfo) && is_array($fieldInfo[
'ENUM']))
391 $currentFieldInfo = $this->
getUserFieldInfo($fieldInfo[
'ENTITY_ID'], $fieldInfo[
'FIELD']);
393 $deletedEnum = array();
394 $storedEnum = array();
395 $updatedEnum = array();
397 if(is_array($currentFieldInfo[
'ENUM']))
399 foreach($currentFieldInfo[
'ENUM'] as $enumItem)
401 $storedEnum[$enumItem[
'ID']] = $enumItem;
402 $deletedEnum[$enumItem[
'ID']] =
true;
407 foreach($fieldInfo[
'ENUM'] as $enumItem)
409 if(is_array($enumItem))
411 if(array_key_exists(
'ID', $enumItem))
413 if(empty($enumItem[
'XML_ID']))
415 $enumItem[
'XML_ID'] = $storedEnum[$enumItem[
'ID']][
'XML_ID'];
418 unset($deletedEnum[$enumItem[
'ID']]);
420 $itemKey = $enumItem[
'ID'] > 0
422 :
'n'.($countAdded++);
424 $itemDescription = array(
425 'VALUE' => $enumItem[
'VALUE'],
426 'DEF' => $enumItem[
'DEF'] ===
'Y' ?
'Y' :
'N',
427 'SORT' => $enumItem[
'SORT'],
430 if($enumItem[
'XML_ID'] <>
'')
432 $itemDescription[
'XML_ID'] = $enumItem[
'XML_ID'];
435 if(intval($enumItem[
'SORT']) > 0)
437 $itemDescription[
'SORT'] = $enumItem[
'SORT'];
440 $updatedEnum[$itemKey] = $itemDescription;
444 foreach($deletedEnum as $deletedId => $t)
446 $updatedEnum[$deletedId] = array(
452 $enumValuesManager = new \CUserFieldEnum();
453 $setEnumResult = $enumValuesManager->setEnumValues($fieldId, $updatedEnum);
466 $ex = $APPLICATION->GetException();
469 $this->
addError($ex->GetString(), $fieldInfo[
'FIELD']);
475 return is_array($label) ? $label : array($this->languageId => $label);
480 $this->storedFieldSignature[$entityId.
'|'.$field] = $signature;
485 return $this->storedFieldSignature[$entityId.
'|'.$field] ??
null;
504 $this->fieldList[] = $field;
529 $this->assetCollectior->startAssetCollection();
531 if(!empty($this->validateFieldList))
533 $this->processValidate();
536 foreach($this->fieldList as $fieldInfo)
542 'FIELD' => $this->result,
543 'ERROR' => $this->getErrorList(),
544 'ASSET' => $this->assetCollectior->getCollectedAssets(),
583 if(!$this->signatureManager)
620 $userFieldInfo = $this->
getUserFieldInfo($fieldInfo[
'ENTITY_ID'], $fieldInfo[
'FIELD']);
629 if(isset($fieldInfo[
'ENTITY_VALUE_ID']))
631 $userFieldInfo[
'ENTITY_VALUE_ID'] = $fieldInfo[
'ENTITY_VALUE_ID'];
634 if(isset($fieldInfo[
'VALUE']))
636 $userFieldInfo[
'VALUE'] = $fieldInfo[
'VALUE'];
640 unset($userFieldInfo[
'VALUE']);
643 if(isset($fieldInfo[
'CONTEXT']))
645 $userFieldInfo[
'CONTEXT'] = $fieldInfo[
'CONTEXT'];
650 $view->setField($userFieldInfo);
652 if (!empty($fieldInfo[
'ADDITIONAL']) && is_array($fieldInfo[
'ADDITIONAL']))
654 foreach ($fieldInfo[
'ADDITIONAL'] as $paramName => $paramValue)
656 $view->setAdditionalParameter($paramName, $paramValue);
660 $this->result[$fieldInfo[
'FIELD']] = [
661 'HTML' =>
$view->display(),
676 $this->fieldList = array();
677 $this->result = array();
678 $this->errorCollection->clear();
690 $this->errorCollection->setError(
new Error($message, $field));
698 protected function getErrorList()
701 if(!$this->errorCollection->isEmpty())
706 foreach($this->errorCollection->toArray() as $error)
708 if($error->getCode())
710 $result[] = $error->getCode().
': '.$error->getMessage();
714 $result[] = $error->getMessage();
722 protected function getValidateErrorList()
725 if(!$this->errorCollection->isEmpty())
730 foreach($this->errorCollection->toArray() as $error)
732 if($error->getCode())
734 $result[$error->getCode()] = $error->getMessage();
738 $result[] = $error->getMessage();
748 $this->errorCollection->clear();
760 if(!is_array($fieldInfo))
764 elseif(empty($fieldInfo[
'FIELD']))
768 elseif(empty($fieldInfo[
'ENTITY_ID']))
790 global $USER_FIELD_MANAGER;
792 if(!array_key_exists($entityId, $this->userFieldList))
794 $this->userFieldList[$entityId] = $USER_FIELD_MANAGER->GetUserFields($entityId, 0, $this->languageId);
798 isset($this->userFieldList[$entityId][$field])
799 && $this->userFieldList[$entityId][$field][
'USER_TYPE_ID'] === \CUserTypeEnum::USER_TYPE_ID
800 && !isset($this->userFieldList[$entityId][$field][
'ENUM'])
803 $this->userFieldList[$entityId][$field][
'ENUM'] = array();
805 $enumValuesManager = new \CUserFieldEnum();
806 $dbRes = $enumValuesManager->GetList(array(), array(
'USER_FIELD_ID' => $this->userFieldList[$entityId][$field][
'ID']));
808 while($enumValue = $dbRes->fetch())
810 $this->userFieldList[$entityId][$field][
'ENUM'][] = array(
811 'ID' => $enumValue[
'ID'],
812 'VALUE' => $enumValue[
'VALUE'],
813 'DEF' => $enumValue[
'DEF'],
814 'SORT' => $enumValue[
'SORT'],
815 'XML_ID' => $enumValue[
'XML_ID'],
820 return $this->userFieldList[$entityId][$field];
830 unset($this->userFieldList[$entityId]);
843 'ID' => $userField[
'ID'],
844 'USER_TYPE_ID' => $userField[
'USER_TYPE_ID'],
845 'ENTITY_ID' => $userField[
'ENTITY_ID'],
846 'ENTITY_VALUE_ID' => $userField[
'ENTITY_VALUE_ID'] ?? 0,
847 'MANDATORY' => $userField[
'MANDATORY'],
848 'MULTIPLE' => $userField[
'MULTIPLE'],
849 'FIELD' => $userField[
'FIELD_NAME'],
850 'EDIT_FORM_LABEL' => $userField[
'EDIT_FORM_LABEL'],
851 'LIST_COLUMN_LABEL' => $userField[
'LIST_COLUMN_LABEL'],
852 'LIST_FILTER_LABEL' => $userField[
'LIST_FILTER_LABEL'],
853 'HELP_MESSAGE' => $userField[
'HELP_MESSAGE'],
854 'SETTINGS' => $userField[
'SETTINGS'],
855 'SHOW_FILTER' => $userField[
'SHOW_FILTER'],
856 'SHOW_IN_LIST' => $userField[
'SHOW_IN_LIST'],
857 'SORT' => $userField[
'SORT'],
858 'CONTEXT_PARAMS' => $userField[
'CONTEXT_PARAMS'] ?? [],
861 if($userField[
'USER_TYPE_ID'] === \CUserTypeEnum::USER_TYPE_ID && is_array($userField[
'ENUM']))
863 $fieldInfo[
'ENUM'] = $userField[
'ENUM'];
869 $fieldInfo[
'SIGNATURE'] = $storedSignature;
static getMessage($code, $replace=null, $language=null)
storeFieldSignature($entityId, $field, $signature)
validateField($fieldInfo)
getErrorFromApplicationException($fieldInfo)
reloadUserFieldInfo($entityId)
validateFieldChangeRequest($fieldInfo)
getSignature(array $fieldParam)
setDefaultSignatureManager()
getStoredFieldSignature($entityId, $field)
createNewField(array $fieldInfo)
getCreateSignature(array $fieldParam)
checkFieldDescription($fieldInfo)
updateField(array $fieldInfo)
addError($message, $field=0)
createNewFieldEnumValues($fieldId, $fieldInfo)
getResultFieldInfo(array $userField)
updateFieldEnumValues($fieldId, $fieldInfo)
setSignatureManager(SignatureManager $signatureManager)
getUserFieldInfo($entityId, $field)
processField(array $fieldInfo)
static validateSignature(SignatureManager $signatureManager, array $fieldParam, $signature)
static getSignature(SignatureManager $signatureManager, array $fieldParam)