- Модуль: report
- Путь к файлу: ~/bitrix/modules/report/lib/visualconstructor/internal/model.php
- Класс: BitrixReportVisualConstructorInternalModel
- Вызов: Model::setAttributes
private function setAttributes(array $attributes, $parentEntity)
{
foreach ($attributes as $key => $value)
{
if ($value === null)
{
unset($attributes[$key]);
}
}
if (!$parentEntity)
{
$mapAttributes = static::getMapAttributes();
foreach ($attributes as $key => $value)
{
if (!empty($mapAttributes[$key]))
{
$this->{$mapAttributes[$key]} = $value;
$this->currentDbState[$key] = $value;
unset($attributes[$key]);
}
}
$parentEntity = $this;
}
if (empty($attributes))
{
return $parentEntity;
}
$subEntitiesMapAttributes = static::getMapReferenceAttributes();
$subEntitiesKeys = array_keys($subEntitiesMapAttributes);
$subEntityAttributes = array();
$loadedSubEntitiesKeys = array();
foreach ($attributes as $key => $value)
{
$delimiter = self::ATTRIBUTE_SLICE_DELIMITER;
$selectedAttributeParts = explode($delimiter, $key);
if (count($selectedAttributeParts) == 2 && in_array($selectedAttributeParts[0], $subEntitiesKeys))
{
$loadedSubEntitiesKeys[$selectedAttributeParts[0]] = $selectedAttributeParts[0];
$subEntityAttributes[$selectedAttributeParts[0]][$selectedAttributeParts[1]] = $value;
}
elseif (count($selectedAttributeParts) >= 2)
{
$nestedEntityParentKey = array_shift($selectedAttributeParts);
$nestedElementKey = implode(self::ATTRIBUTE_SLICE_DELIMITER, $selectedAttributeParts);
$subEntityAttributes[$nestedEntityParentKey][$nestedElementKey] = $value;
}
}
foreach ($subEntityAttributes as $key => $validAttributes)
{
if (!empty($subEntitiesMapAttributes[$key]))
{
/** @var static $targetEntityClass */
$targetEntityClass = $subEntitiesMapAttributes[$key]['targetEntity'];
if ($subEntitiesMapAttributes[$key]['type'] != Common::MANY_TO_ONE)
{
if (!isset($parentEntity->{$key}[$validAttributes['ID']]))
{
$subEntity = $targetEntityClass::buildFromArray($validAttributes);
$nestedEntityReferenceMap = $subEntity::getMapReferenceAttributes();
/**
* If connection type is one to many we can map to nested parent entity automatically
*/
if ($subEntitiesMapAttributes[$key]['type'] == Common::ONE_TO_MANY)
{
if (!empty($nestedEntityReferenceMap[$subEntitiesMapAttributes[$key]['mappedBy']]))
{
$subEntity->{$subEntitiesMapAttributes[$key]['mappedBy']} = $parentEntity;
}
}
$parentEntity->{$key}[$subEntity->id] = $subEntity;
}
else
{
$targetEntityClass::buildFromArray($validAttributes, $parentEntity->{$key}[$validAttributes['ID']]);
}
}
else
{
$subEntity = $targetEntityClass::buildFromArray($validAttributes);
$parentEntity->{$key} = $subEntity;
}
}
}
return $parentEntity;
}