42 'data_type' =>
'integer',
44 'autocomplete' =>
true,
47 'data_type' =>
'string',
48 'title' => Loc::getMessage(
'MAIN_USER_FIELD_TABLE_ENTITY_ID_TITLE'),
50 'FIELD_NAME' =>
array(
51 'data_type' =>
'string',
52 'title' => Loc::getMessage(
'MAIN_USER_FIELD_TABLE_FIELD_NAME_TITLE'),
54 'USER_TYPE_ID' =>
array(
55 'data_type' =>
'string',
56 'title' => Loc::getMessage(
'MAIN_USER_FIELD_TABLE_USER_TYPE_ID_TITLE'),
59 'data_type' =>
'string',
62 'data_type' =>
'integer',
63 'title' => Loc::getMessage(
'MAIN_USER_FIELD_TABLE_SORT_TITLE'),
66 'data_type' =>
'boolean',
67 'values' =>
array(
'N',
'Y'),
68 'title' => Loc::getMessage(
'MAIN_USER_FIELD_TABLE_MULTIPLE_TITLE'),
71 'data_type' =>
'boolean',
72 'values' =>
array(
'N',
'Y'),
73 'title' => Loc::getMessage(
'MAIN_USER_FIELD_TABLE_MANDATORY_TITLE'),
75 'SHOW_FILTER' =>
array(
76 'data_type' =>
'boolean',
77 'values' =>
array(
'N',
'Y'),
78 'title' => Loc::getMessage(
'MAIN_USER_FIELD_TABLE_SHOW_FILTER_TITLE'),
80 'SHOW_IN_LIST' =>
array(
81 'data_type' =>
'boolean',
82 'values' =>
array(
'N',
'Y'),
83 'title' => Loc::getMessage(
'MAIN_USER_FIELD_TABLE_SHOW_IN_LIST_TITLE'),
85 'EDIT_IN_LIST' =>
array(
86 'data_type' =>
'boolean',
87 'values' =>
array(
'N',
'Y'),
88 'title' => Loc::getMessage(
'MAIN_USER_FIELD_TABLE_EDIT_IN_LIST_TITLE'),
90 'IS_SEARCHABLE' =>
array(
91 'data_type' =>
'boolean',
92 'values' =>
array(
'N',
'Y'),
93 'title' => Loc::getMessage(
'MAIN_USER_FIELD_TABLE_IS_SEARCHABLE_TITLE'),
96 'data_type' =>
'text',
98 'title' => Loc::getMessage(
'MAIN_USER_FIELD_TABLE_SETTINGS_TITLE'),
107 $referenceName =
'LABELS';
111 '=this.ID' =>
'ref.USER_FIELD_ID',
121 UserFieldLangTable::class,
142 $referenceName =
'LABELS';
146 foreach(static::getLabelFields() as $labelField)
148 $result[$labelField] = $referenceName .
'.' . $labelField;
156 $labelFields = static::getLabelFields();
158 $list = static::getList([
164 static::getLabelsReference(),
167 foreach($list as
$data)
173 $field[
'LANGUAGE_ID'],
174 $field[
'EDIT_FORM_LABEL'],
175 $field[
'LIST_COLUMN_LABEL'],
176 $field[
'LIST_FILTER_LABEL'],
177 $field[
'ERROR_MESSAGE'],
178 $field[
'HELP_MESSAGE'],
183 foreach($labelFields as $labelField)
185 $field[$labelField][
$data[
'LANGUAGE_ID']] =
$data[$labelField];
194 if($field[
'USER_TYPE_ID'] ===
'enumeration')
197 $enumEntity = new \CUserFieldEnum();
198 $enumList = $enumEntity->GetList(
202 'USER_FIELD_ID' => $field[
'ID'],
205 while($enum = $enumList->Fetch())
207 $field[
'ENUM'][] = $enum;
243 public static function delete($primary)
259 $utsFields =
array();
260 $utsFieldNames =
array();
262 $utmFields =
array();
263 $utmFieldNames =
array();
269 if ($field[
'MULTIPLE'] ===
'Y')
271 $utmFields[] = $field;
272 $utmFieldNames[$field[
'FIELD_NAME']] =
true;
276 $utsFields[] = $field;
277 $utsFieldNames[$field[
'FIELD_NAME']] =
true;
281 if (!empty($utsFields) || !empty($utmFields))
284 $utsEntity = static::createUtsEntity(
$entity, $utsFields, $utmFields, $ufId);
287 $utsReference =
new ORM\Fields\Relations\Reference(
'UTS_OBJECT', $utsEntity->getDataClass(),
array(
288 '=this.ID' =>
'ref.VALUE_ID'
291 $entity->addField($utsReference);
294 foreach (
$fields as $userfield)
296 $utsFieldName = $userfield[
'FIELD_NAME'];
299 $utsField = $utsEntity->getField($utsFieldName);
301 $aliasField =
new ORM\Fields\UserTypeField(
304 'UTS_OBJECT.'.$utsFieldName,
305 array(
'data_type' => get_class($utsField))
308 $aliasField->configureValueField($utsField);
310 if ($userfield[
'MULTIPLE'] ==
'Y')
312 $aliasField->configureMultiple();
315 $entity->addField($aliasField);
319 if (!empty($utsFields))
321 foreach ($utsFields as $utsField)
324 $utsEntityField = $utsEntity->getField($utsField[
'FIELD_NAME']);
326 foreach (
$USER_FIELD_MANAGER->getEntityReferences($utsField, $utsEntityField) as $reference)
329 $referenceDesc = static::rewriteUtsReference($reference->getReference());
331 $aliasReference =
new ORM\Fields\Relations\Reference(
332 $reference->getName(),
333 $reference->getRefEntityName(),
337 $entity->addField($aliasReference);
342 if (!empty($utmFields))
345 $utmEntity = static::createUtmEntity(
$entity, $utmFields, $ufId);
348 foreach ($utmFieldNames as $utmFieldName => $true)
351 $utmField = $utmEntity->getField($utmFieldName);
353 $aliasField =
new ORM\Fields\ExpressionField(
354 $utmFieldName.
'_SINGLE',
356 $utmEntity->getFullName().
':PARENT_'.$utmFieldName.
'.'.$utmField->getColumnName(),
357 array(
'data_type' => get_class($utmField))
360 $entity->addField($aliasField);
376 protected static function createUtsEntity(ORM\Entity $srcEntity,
array $utsFields,
array $utmFields, $ufId =
null)
382 $utsClassFull = static::getUtsEntityClassNameBySrcEntity($srcEntity);
383 $utsClassPath = explode(
'\\', ltrim($utsClassFull,
'\\'));
385 $utsNamespace = join(
'\\', array_slice($utsClassPath, 0, -1));
386 $utsClass = end($utsClassPath);
389 $utsTable = static::getUtsEntityTableNameBySrcEntity($srcEntity, $ufId);
394 'data_type' =>
'integer',
398 'data_type' => $srcEntity->getDataClass(),
399 'reference' =>
array(
400 '=this.VALUE_ID' =>
'ref.ID'
406 if (class_exists($utsNamespace.
"\\".$utsClass))
408 ORM\Entity::destroy($utsNamespace.
"\\".$utsClass);
409 $entity = ORM\Entity::getInstance($utsNamespace.
"\\".$utsClass);
411 foreach ($fieldsMap as $fieldName => $field)
413 $entity->addField($field, $fieldName);
418 $entity = ORM\Entity::compileEntity($utsClass, $fieldsMap,
array(
419 'namespace' => $utsNamespace,
'table_name' => $utsTable
423 foreach ($utsFields as $utsField)
434 foreach ($utmFields as $utmFieldMeta)
440 $cacheField = (
new ORM\Fields\UserTypeUtsMultipleField($utmField->getName()))
441 ->configureUtmField($utmField);
443 static::setMultipleFieldSerialization($cacheField, $utmField);
444 $entity->addField($cacheField);
469 $entityField->configureSerializeCallback([__CLASS__,
'serializeMultipleDatetime']);
470 $entityField->configureUnserializeCallback([__CLASS__,
'unserializeMultipleDatetime']);
474 $entityField->addSaveDataModifier([__CLASS__,
'serializeMultipleDatetime']);
475 $entityField->addFetchDataModifier([__CLASS__,
'unserializeMultipleDatetime']);
482 $entityField->configureSerializeCallback([__CLASS__,
'serializeMultipleDate']);
483 $entityField->configureUnserializeCallback([__CLASS__,
'unserializeMultipleDate']);
487 $entityField->addSaveDataModifier([__CLASS__,
'serializeMultipleDate']);
488 $entityField->addFetchDataModifier([__CLASS__,
'unserializeMultipleDate']);
495 $entityField->configureSerializationPhp();
499 $entityField->setSerialized();
508 foreach ($referenceDesc as
$k => $v)
512 $new[
$k] = static::rewriteUtsReference($v);
516 $k = str_replace(
'this.',
'this.UTS_OBJECT.',
$k);
526 return $srcEntity->getFullName().
'UtsTable';
531 return 'b_uts_'.mb_strtolower($ufId ?: $srcEntity->getUfId());
543 protected static function createUtmEntity(
ORM\
Entity $srcEntity,
array $utmFields, $ufId =
null)
548 $utmClassFull = static::getUtmEntityClassNameBySrcEntity($srcEntity);
549 $utmClassPath = explode(
'\\', ltrim($utmClassFull,
'\\'));
551 $utmNamespace = join(
'\\', array_slice($utmClassPath, 0, -1));
552 $utmClass = end($utmClassPath);
555 $utmTable = static::getUtmEntityTableNameBySrcEntity($srcEntity, $ufId);
560 'data_type' =>
'integer',
562 'autocomplete' =>
true
565 'data_type' =>
'integer',
569 'data_type' => $srcEntity->getDataClass(),
570 'reference' =>
array(
571 '=this.VALUE_ID' =>
'ref.ID'
575 'data_type' =>
'integer'
580 'data_type' =>
'text'
582 'VALUE_INT' =>
array(
583 'data_type' =>
'integer'
585 'VALUE_DOUBLE' =>
array(
586 'data_type' =>
'float'
588 'VALUE_DATE' =>
array(
589 'data_type' =>
'datetime'
594 if (class_exists($utmNamespace.
"\\".$utmClass))
599 foreach ($fieldsMap as $fieldName => $field)
601 $entity->addField($field, $fieldName);
606 $entity = ORM\Entity::compileEntity($utmClass, $fieldsMap,
array(
607 'namespace' => $utmNamespace,
'table_name' => $utmTable
612 foreach ($utmFields as $utmField)
616 if ($field instanceof ORM\Fields\IntegerField)
618 $columnName =
'VALUE_INT';
620 elseif ($field instanceof ORM\Fields\FloatField)
622 $columnName =
'VALUE_DOUBLE';
624 elseif ($field instanceof ORM\Fields\DateField)
626 $columnName =
'VALUE_DATE';
630 $columnName =
'VALUE';
633 $field->setColumnName($columnName);
643 $refField =
new ORM\Fields\Relations\Reference(
644 'PARENT_'.$utmField[
'FIELD_NAME'],
645 $srcEntity->getDataClass(),
646 array(
'=this.VALUE_ID' =>
'ref.ID',
'=this.FIELD_ID' =>
array(
'?i', $utmField[
'ID']))
657 return $srcEntity->getFullName().
'UtmTable';
662 return 'b_utm_'.mb_strtolower($ufId ?: $srcEntity->getUfId());
670 public static function serializeMultipleDatetime($value)
672 if (is_array($value) || $value instanceof \Traversable)
676 foreach ($value as
$k => $singleValue)
679 $tmpValue[
$k] = $singleValue->format(static::MULTIPLE_DATETIME_FORMAT);
682 return serialize($tmpValue);
698 $value = unserialize($value, [
"allowed_classes" =>
false]);
700 foreach($value as &$singleValue)
705 $singleValue =
new Type\DateTime($singleValue, static::MULTIPLE_DATETIME_FORMAT);
723 public static function serializeMultipleDate($value)
725 if (is_array($value) || $value instanceof \Traversable)
729 foreach ($value as
$k => $singleValue)
732 $tmpValue[
$k] = $singleValue->format(static::MULTIPLE_DATE_FORMAT);
735 return serialize($tmpValue);
751 $value = unserialize($value, [
"allowed_classes" =>
false]);
753 foreach($value as &$singleValue)
758 $singleValue =
new Type\Date($singleValue, static::MULTIPLE_DATE_FORMAT);
763 $singleValue =
new Type\Date($singleValue);
static getLabelsReference(string $referenceName=null, string $languageId=null)
static setMultipleFieldSerialization(ORM\Fields\Field $entityField, $fieldAsType)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)