MetaModels\MetaModel::fetchAdditionalAttributes PHP Method

fetchAdditionalAttributes() protected method

This method is called to retrieve the data for certain items from the database.
protected fetchAdditionalAttributes ( string[] $ids, array $result, string[] $attrOnly = [] ) : array
$ids string[] The ids of the items to retrieve the order of ids is used for sorting of the return values.
$result array The current values.
$attrOnly string[] Names of the attributes that shall be contained in the result, defaults to array() which means all attributes.
return array an array of all matched items, sorted by the id list.
    protected function fetchAdditionalAttributes($ids, $result, $attrOnly = array())
    {
        $attributes = $this->getAttributeByNames($attrOnly);
        $attributeNames = array_intersect(array_keys($attributes), array_keys(array_merge($this->getComplexAttributes(), $this->getTranslatedAttributes())));
        foreach ($attributeNames as $attributeName) {
            $attribute = $attributes[$attributeName];
            /** @var IAttribute $attribute */
            $attributeName = $attribute->getColName();
            // If it is translated, fetch the translated data now.
            if ($this->isTranslatedAttribute($attribute)) {
                /** @var ITranslated $attribute */
                $attributeData = $this->fetchTranslatedAttributeValues($attribute, $ids);
            } else {
                /** @var IComplex $attribute */
                $attributeData = $attribute->getDataFor($ids);
            }
            foreach (array_keys($result) as $id) {
                $result[$id][$attributeName] = isset($attributeData[$id]) ? $attributeData[$id] : null;
            }
        }
        return $result;
    }