MetaModels\MetaModel::getItemsWithId PHP Method

getItemsWithId() protected method

This method is called to retrieve the data for certain items from the database.
protected getItemsWithId ( int[] $arrIds, string[] $arrAttrOnly = [] ) : MetaModels\IItems
$arrIds int[] The ids of the items to retrieve the order of ids is used for sorting of the return values.
$arrAttrOnly string[] Names of the attributes that shall be contained in the result, defaults to array() which means all attributes.
return MetaModels\IItems a collection of all matched items, sorted by the id list.
    protected function getItemsWithId($arrIds, $arrAttrOnly = array())
    {
        $arrIds = array_unique(array_filter($arrIds));
        if (!$arrIds) {
            return new Items(array());
        }
        if (!$arrAttrOnly) {
            $arrAttrOnly = array_keys($this->getAttributes());
        }
        $arrResult = $this->fetchRows($arrIds, $arrAttrOnly);
        // Give simple attributes the chance for editing the "simple" data.
        foreach ($this->getSimpleAttributes() as $objAttribute) {
            // Get current simple attribute.
            $strColName = $objAttribute->getColName();
            // Run each row.
            foreach (array_keys($arrResult) as $intId) {
                // Do only skip if the key does not exist. Do not use isset() here as "null" is a valid value.
                if (!array_key_exists($strColName, $arrResult[$intId])) {
                    continue;
                }
                $value = $arrResult[$intId][$strColName];
                $value2 = $objAttribute->unserializeData($arrResult[$intId][$strColName]);
                // Deprecated fallback, attributes should deserialize themselves for a long time now.
                if ($value === $value2) {
                    $value2 = $this->tryUnserialize($value);
                    if ($value !== $value2) {
                        trigger_error(sprintf('Attribute type %s should implement method unserializeData() and  serializeData().', $objAttribute->get('type')), E_USER_DEPRECATED);
                    }
                }
                // End of deprecated fallback.
                $arrResult[$intId][$strColName] = $value2;
            }
        }
        // Determine "independent attributes" (complex and translated) and inject their content into the row.
        $arrResult = $this->fetchAdditionalAttributes($arrIds, $arrResult, $arrAttrOnly);
        $arrItems = array();
        foreach ($arrResult as $arrEntry) {
            $arrItems[] = new Item($this, $arrEntry);
        }
        $objItems = new Items($arrItems);
        return $objItems;
    }