15 private static $instance =
null;
20 private function __construct() {}
27 if (self::$instance ===
null)
29 self::$instance =
new self();
32 return self::$instance;
45 if ($entity->getId() <= 0)
48 Main\Localization\
Loc::getMessage(
'CUSTOM_FIELDS_CONTROLLER_ERROR_INCORRECT_ENTITY_ID')
52 $dbRes = CustomFieldsTable::getList([
53 'select' => [
'ID',
'FIELD'],
55 '=ENTITY_ID' => $entity->getId(),
56 '=ENTITY_TYPE' => $entity::getRegistryEntity(),
57 '=ENTITY_REGISTRY_TYPE' => $entity::getRegistryType()
61 $customFieldArray = [];
62 while ($data = $dbRes->fetch())
64 $customFieldArray[$data[
'FIELD']] = $data;
67 foreach ($entity::getCustomizableFields() as $field)
69 if ($entity->isMarkedFieldCustom($field))
71 if (!isset($customFieldArray[$field]))
73 CustomFieldsTable::add([
74 'ENTITY_ID' => $entity->getId(),
75 'ENTITY_TYPE' => $entity::getRegistryEntity(),
76 'ENTITY_REGISTRY_TYPE' => $entity::getRegistryType(),
83 if (isset($customFieldArray[$field]))
85 CustomFieldsTable::delete($customFieldArray[$field][
'ID']);
102 if ($entity->getId() <= 0)
107 $dbRes = CustomFieldsTable::getList([
108 'select' => [
'ID',
'FIELD'],
110 '=ENTITY_ID' => $entity->getId(),
111 '=ENTITY_TYPE' => $entity::getRegistryEntity(),
112 '=ENTITY_REGISTRY_TYPE' => $entity::getRegistryType()
116 while ($data = $dbRes->fetch())
118 $entity->markFieldCustom($data[
'FIELD']);
133 $filter = $this->buildFilter($collection);
136 $dbRes = CustomFieldsTable::getList([
137 'select' => [
'FIELD',
'ENTITY_ID'],
141 while ($data = $dbRes->fetch())
143 $entity = $collection->
getItemById($data[
'ENTITY_ID']);
144 $entity->markFieldCustom($data[
'FIELD']);
159 $entityTypeList = [];
160 $entityRegistryTypeList = [];
163 foreach ($collection as $entity)
165 if ((
int)$entity->getId() === 0)
170 if (!in_array($entity->getId(), $entityIdList))
172 $entityIdList[] = $entity->getId();
175 if (!in_array($entity::getRegistryEntity(), $entityTypeList))
177 $entityTypeList[] = $entity::getRegistryEntity();
180 if (!in_array($entity::getRegistryType(), $entityRegistryTypeList))
182 $entityRegistryTypeList[] = $entity::getRegistryType();
188 || empty($entityTypeList)
189 || empty($entityRegistryTypeList)
195 $filter = $this->buildFilterForField(
'ENTITY_ID', $entityIdList);
196 $filter += $this->buildFilterForField(
'ENTITY_TYPE', $entityTypeList);
197 $filter += $this->buildFilterForField(
'ENTITY_REGISTRY_TYPE', $entityRegistryTypeList);
202 private function buildFilterForField(
string $field, array $data) : array
204 if (count($data) === 1)
206 return [
'='.$field => array_shift($data)];
209 return [
'@'.$field => $data];
static getMessage($code, $replace=null, $language=null)