src/MetaModel.php
public function getIdsFromFilter($objFilter, $strSortBy = '', $intOffset = 0, $intLimit = 0, $strSortOrder = 'ASC')
    {
        if ([] === $arrFilteredIds = array_filter($this->getMatchingIds($objFilter))) {
            return [];
        }

        // If desired, sort the entries.
        if ('' !== $strSortBy) {
            if ($objSortAttribute = $this->getAttribute($strSortBy)) {
                $arrFilteredIds = $objSortAttribute->sortIds($arrFilteredIds, $strSortOrder);
            } elseif ('id' === $strSortBy) {
                asort($arrFilteredIds);
            } elseif (in_array($strSortBy, array('pid', 'tstamp', 'sorting'))) {
                // Build the right key for the cache.
                $sortKey = \sprintf('%s-%s', $strSortBy, \strtolower($strSortOrder));
                // Used the cached ID list, and make a list of wanted ID's with the sorting of the cache.
                if (!isset($this->existingIds[$sortKey])) {
                    $this->existingIds[$sortKey] = [];
                }
                $cacheResult = array_intersect($this->existingIds[$sortKey], $arrFilteredIds);
                // Check if we have all ID's or if we have one missing, now we are using the order of the MM Filter.
                if (array_intersect($arrFilteredIds, $cacheResult) === $arrFilteredIds) {
                    if ($intOffset > 0 || $intLimit > 0) {
                        return array_values(array_slice($cacheResult, $intOffset, $intLimit ?: null));
                    }
                    return array_values($cacheResult);
                }

                // Merge the already known and the new one.
                $fullIdList = array_merge((array) $this->existingIds[$sortKey], $arrFilteredIds);
                $fullIdList = \array_keys(\array_flip($fullIdList));

                // Sort by database values.
                $builder = $this->getConnection()->createQueryBuilder();

                $arrSortedFilteredIds = $builder
                    ->select('id')
                    ->from($this->getTableName())
                    ->where($builder->expr()->in('id', ':values'))
                    ->setParameter('values', $arrFilteredIds, Connection::PARAM_STR_ARRAY)
                    ->orderBy($strSortBy, $strSortOrder)
                    ->execute()
                    ->fetchAll(\PDO::FETCH_COLUMN);

                // Add the new sorted Id's to the cache and use only the wanted.
                $this->existingIds[$sortKey] = $arrSortedFilteredIds;
                $arrFilteredIds              = array_intersect($arrSortedFilteredIds, $arrFilteredIds);
            } elseif ($strSortBy == 'random') {
                shuffle($arrFilteredIds);
            }
        }

        // Apply limiting then.
        if ($intOffset > 0 || $intLimit > 0) {
            $arrFilteredIds = array_slice($arrFilteredIds, $intOffset, $intLimit ?: null);
        }
        return array_values($arrFilteredIds);
    }
public function getIdsFromFilter($objFilter, $strSortBy = '', $intOffset = 0, $intLimit = 0, $strSortOrder = 'ASC')
    {
        if ([] === $arrFilteredIds = array_filter($this->getMatchingIds($objFilter))) {
            return [];
        }

        // If desired, sort the entries.
        if ('' !== $strSortBy) {
            if ($objSortAttribute = $this->getAttribute($strSortBy)) {
                $arrFilteredIds = $objSortAttribute->sortIds($arrFilteredIds, $strSortOrder);
            } elseif ('id' === $strSortBy) {
                asort($arrFilteredIds);
            } elseif (in_array($strSortBy, array('pid', 'tstamp', 'sorting'))) {
                // Build the right key for the cache.
                $sortKey = \sprintf('%s-%s', $strSortBy, \strtolower($strSortOrder));
                // Used the cached ID list, and make a list of wanted ID's with the sorting of the cache.
                if (!isset($this->existingIds[$sortKey])) {
                    $this->existingIds[$sortKey] = [];
                }
                $cacheResult = array_intersect($this->existingIds[$sortKey], $arrFilteredIds);
                // Check if we have all ID's or if we have one missing, now we are using the order of the MM Filter.
                if (array_intersect($arrFilteredIds, $cacheResult) === $arrFilteredIds) {
                    if ($intOffset > 0 || $intLimit > 0) {
                        return array_values(array_slice($cacheResult, $intOffset, $intLimit ?: null));
                    }
                    return array_values($cacheResult);
                }

                // Merge the already known and the new one.
                $fullIdList = array_merge((array) $this->existingIds[$sortKey], $arrFilteredIds);
                $fullIdList = \array_keys(\array_flip($fullIdList));

                // Sort by database values.
                $builder = $this->getConnection()->createQueryBuilder();

                $arrSortedFilteredIds = $builder
                    ->select('id')
                    ->from($this->getTableName())
                    ->where($builder->expr()->in('id', ':values'))
                    ->setParameter('values', $arrFilteredIds, Connection::PARAM_STR_ARRAY)
                    ->orderBy($strSortBy, $strSortOrder)
                    ->execute()
                    ->fetchAll(\PDO::FETCH_COLUMN);

                // Add the new sorted Id's to the cache and use only the wanted.
                $this->existingIds[$sortKey] = $arrSortedFilteredIds;
                $arrFilteredIds              = array_intersect($arrSortedFilteredIds, $arrFilteredIds);
            } elseif ($strSortBy == 'random') {
                shuffle($arrFilteredIds);
            }
        }

        // Apply limiting then.
        if ($intOffset > 0 || $intLimit > 0) {
            $arrFilteredIds = array_slice($arrFilteredIds, $intOffset, $intLimit ?: null);
        }
        return array_values($arrFilteredIds);
    }
{@inheritdoc}

@SuppressWarnings(PHPMD.CyclomaticComplexity)