Get sorted arrays of content IDs, which should be returned.

@param Criterion $filter
@param array $sort
@param mixed $offset
@param mixed $limit
@param array $languageFilter

@return int[]
963536
protected function getContentInfoList(
        Criterion $filter,
        $sort,
        $offset,
        $limit,
        array $languageFilter
    ) {
        $query = $this->handler->createSelectQuery();
        $query->selectDistinct(
            'ezcontentobject.*',
            $this->handler->aliasedColumn($query, 'main_node_id', 'main_tree')
        );

        if ($sort !== null) {
            $this->sortClauseConverter->applySelect($query, $sort);
        }

        $query->from(
            $this->handler->quoteTable('ezcontentobject')
        )->innerJoin(
            'ezcontentobject_version',
            'ezcontentobject.id',
            'ezcontentobject_version.contentobject_id'
        )->leftJoin(
            $this->handler->alias(
                $this->handler->quoteTable('ezcontentobject_tree'),
                $this->handler->quoteIdentifier('main_tree')
            ),
            $query->expr->lAnd(
                $query->expr->eq(
                    $this->handler->quoteColumn('contentobject_id', 'main_tree'),
                    $this->handler->quoteColumn('id', 'ezcontentobject')
                ),
                $query->expr->eq(
                    $this->handler->quoteColumn('main_node_id', 'main_tree'),
                    $this->handler->quoteColumn('node_id', 'main_tree')
                )
            )
        );

        if ($sort !== null) {
            $this->sortClauseConverter->applyJoin($query, $sort, $languageFilter);
        }

        $query->where(
            $this->getQueryCondition($filter, $query, $languageFilter)
        );

        if ($sort !== null) {
            $this->sortClauseConverter->applyOrderBy($query);
        }

        $query->limit($limit, $offset);

        $statement = $query->prepare();
        $statement->execute();

        return $statement->fetchAll(PDO::FETCH_ASSOC);
    }
418930
public function findBy(array $criteria = [], array $orders = [], $limit = null, $offset = null): array
    {
        $queryCriteria = Criteria::create();

        foreach ($criteria as $prop => $value) {
            $queryCriteria->andWhere(Criteria::expr()->eq($prop, $value));
        }

        $queryCriteria->orderBy($orders);

        if ($limit !== null) {
            $queryCriteria->setMaxResults($limit);
        }

        if ($offset !== null) {
            $queryCriteria->setFirstResult($offset);
        }

        return $this->matching($queryCriteria);
    }
801610
public function getList(int $page, int $limit, Context $context, array $requestFilters, array $sort): array
    {
        --$page;
        $metaData = $this->getSetMetaData($context);

        $isoList = $this->createIsoList($metaData);
        $languageFiles = $this->getSnippetFilesByIso($isoList);

        $fileSnippets = $this->getFileSnippets($languageFiles, $isoList);
        $dbSnippets = $this->databaseSnippetsToArray($this->findSnippetInDatabase(new Criteria(), $context), $fileSnippets);

        $snippets = array_replace_recursive($fileSnippets, $dbSnippets);
        $snippets = $this->fillBlankSnippets($snippets, $isoList);

        foreach ($requestFilters as $requestFilterName => $requestFilterValue) {
            $snippets = $this->snippetFilterFactory->getFilter($requestFilterName)->filter($snippets, $requestFilterValue);
        }

        $snippets = $this->sortSnippets($sort, $snippets);

        $total = 0;
        foreach ($snippets as $setId => &$set) {
            $total = $total > 0 ? $total : count($set['snippets']);
            $set['snippets'] = array_chunk($set['snippets'], $limit, true)[$page] ?? [];
        }

        return [
            'total' => $total,
            'data' => $this->mergeSnippetsComparison($snippets),
        ];
    }
1079709
private function filterAndSortByEncryptedField(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $encryptedSort = $this->orderByHasEncryptedField($orderBy);

        $encryptedFields = $this->getEncryptedFields();
        $notEncryptedCriteria = array_diff_key($criteria, $encryptedFields);
        $notEncryptedOrderBy = !$encryptedSort ? $orderBy : null;

        // Get the result of the filter by not encrypted fields
        $result = $this->wrapped->findBy($notEncryptedCriteria, $notEncryptedOrderBy);

        $encryptedCriteria = array_intersect_key($criteria, $encryptedFields);
        if (!empty($result) && !empty($encryptedCriteria)) {
            $result = $this->filterWithEncryptedCriteria($result, $encryptedCriteria);
        }

        if ($encryptedSort && !empty($orderBy)) {
            $result = $this->sortWithEncryptedOrderBy($result, $orderBy);
        }

        if ($limit) {
            $offset = $offset ? $offset : 0;

            $result = array_slice($result, $offset, $limit);
        }

        return $result;
    }
1058131
public function filter($filter)
    {
        preg_match_all("/(#\w+)/", $filter, $entityNames);
        preg_match_all("/(:\w+)/", $filter, $positions);

        $entityName = is_array($entityNames[0]) && isset($entityNames[0][0]) ? ltrim($entityNames[0][0], '#') : null;
        $position   = is_array($positions[0]) && isset($positions[0][0]) ? $positions[0][0] : null;

        $i = 0;

        $filtered = [];

        foreach ($this->entities as $name => $entity) {
            if ($i === 0 && ($entityName === $name || $entityName === null) && ($position === ':first' || $position === ':highest' || $position === null)) {
                $filtered[] = $entity;
            }

            if ($position === ':any' && ($entityName === $name || $entityName === null)) {
                $filtered[] = $entity;
            }

            if ($i + 1 === $this->entities->count() && ($entityName === $name || $entityName === null) && ($position === ':last' || $position === ':lowest')) {
                $filtered[] = $entity;
            }

            $i++;
        }

        $this->filtered = $filtered;

        return $this;
    }
635942
public function &getPresentationRoleRefs( $filter = array(), $sort = true )
	{
		// Make sure the filter is initialized and contains lowercase values
		if ( ! is_array( $filter ) ) $filter = array();
		$filter = array_flip( array_map( 'strtolower', $filter ) );

		/**
		 * @var array $refs
		 */
		$refs = $this->context->presentationRoleRefs;
		/**
		 * @var array $result
		 */
		$result = array();

		foreach ( $refs as $refKey => $ref )
		{
			// Apply the filter if one is provided
			if ( count( $filter ) && ! isset( $filter[ strtolower( $refKey ) ] ) ) continue;

			// The presentation hierarchy may be implemented in another taxonomy
			if ( isset( $ref['hierarchy'] ) )
			{
				$result[ $refKey ]  = $ref;
			}
			else
			{
				$result[ $refKey ] = $this->context->presentationRoleRefs[ $refKey ];
			}

			$result[ $refKey ]['text'] = $this->getPresentationLinkRoleDescription( $ref );
		}

		if ( $sort )
		{
			$this->sortRoleRefs( $result );
		}

		return $result;
	}
42693
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        return $this->contentRepository->findBy($criteria, $orderBy, $limit, $offset);
    }
933269
public function getHeaders( $sort = SORTDATE, $reverse = TRUE, $limit = 0, $offset = 0 )
	{
		$list	= array();
		$sort	= imap_sort( $this->connection->getStream(), $sort, (int) $reverse, SE_UID );
		$sort	= array_slice( $sort, $offset, $limit );
		foreach( $sort as $uid )
		{
			$list[$uid]	= $this->getHeadersByUid( $uid );
		}
		return $list;
	}
394408
public function globalFeed($filter = array(), $orderBy = 'ID DESC', $since = null, $number = 10, $markViewed = true) {
		$number = (int) $number;
		
		if (!count($filter)) {
			$filter = array('ParentID' => 0);
		}
		$filter['Deleted'] = 0;

		$items = MicroPost::get()->filter($filter)->sort($orderBy);
		
		if ($since) {
			$since = (int) $since;
			$items = $items->filter('ID:GreaterThan', $since);
		}

		if ($markViewed) {
			$this->recordUserAction();
		}
		$items = $this->updatePostList($items);
		return $items->limit($number)->restrict();
	}
1289166
private function findByFiltersIds($filters, $page, $pageSize, $limit, $locale, $options = [])
    {
        $parameter = [];

        $queryBuilder = $this->createQueryBuilder('c')
            ->select('c.id')
            ->distinct()
            ->orderBy('c.id', 'ASC');

        $tagRelation = $this->appendTagsRelation($queryBuilder, 'c');
        $categoryRelation = $this->appendCategoriesRelation($queryBuilder, 'c');

        if (array_key_exists('sortBy', $filters) && is_array($filters['sortBy'])) {
            $sortMethod = array_key_exists('sortMethod', $filters) ? $filters['sortMethod'] : 'asc';
            $this->appendSortBy($filters['sortBy'], $sortMethod, $queryBuilder, 'c', $locale);

            foreach ($filters['sortBy'] as $sortColumn) {
                $queryBuilder->addSelect($sortColumn);
            }
        }

        $parameter = array_merge($parameter, $this->append($queryBuilder, 'c', $locale, $options));
        if (isset($filters['dataSource'])) {
            $includeSubFolders = $this->getBoolean($filters['includeSubFolders'] ?: false);
            $parameter = array_merge(
                $parameter,
                $this->appendDatasource($filters['dataSource'], $includeSubFolders, $queryBuilder, 'c')
            );
        }

        if (isset($filters['tags']) && !empty($filters['tags'])) {
            $parameter = array_merge(
                $parameter,
                $this->appendRelation(
                    $queryBuilder,
                    $tagRelation,
                    $filters['tags'],
                    strtolower($filters['tagOperator']),
                    'adminTags'
                )
            );
        }

        if (isset($filters['categories']) && !empty($filters['categories'])) {
            $parameter = array_merge(
                $parameter,
                $this->appendRelation(
                    $queryBuilder,
                    $categoryRelation,
                    $filters['categories'],
                    strtolower($filters['categoryOperator']),
                    'adminCategories'
                )
            );
        }

        if (isset($filters['targetGroupId']) && $filters['targetGroupId']) {
            $targetGroupRelation = $this->appendTargetGroupRelation($queryBuilder, 'c');
            $parameter = array_merge(
                $parameter,
                $this->appendRelation(
                    $queryBuilder,
                    $targetGroupRelation,
                    [$filters['targetGroupId']],
                    'and',
                    'targetGroupId'
                )
            );
        }

        if (isset($filters['websiteTags']) && !empty($filters['websiteTags'])) {
            $parameter = array_merge(
                $parameter,
                $this->appendRelation(
                    $queryBuilder,
                    $tagRelation,
                    $filters['websiteTags'],
                    strtolower($filters['websiteTagsOperator']),
                    'websiteTags'
                )
            );
        }

        if (isset($filters['websiteCategories']) && !empty($filters['websiteCategories'])) {
            $parameter = array_merge(
                $parameter,
                $this->appendRelation(
                    $queryBuilder,
                    $categoryRelation,
                    $filters['websiteCategories'],
                    strtolower($filters['websiteCategoriesOperator']),
                    'websiteCategories'
                )
            );
        }

        $query = $queryBuilder->getQuery();
        foreach ($parameter as $name => $value) {
            $query->setParameter($name, $value);
        }

        if (null !== $page && $pageSize > 0) {
            $pageOffset = ($page - 1) * $pageSize;
            $restLimit = $limit - $pageOffset;

            // if limitation is smaller than the page size then use the rest limit else use page size plus 1 to
            // determine has next page
            $maxResults = (null !== $limit && $pageSize > $restLimit ? $restLimit : ($pageSize + 1));

            if ($maxResults <= 0) {
                return [];
            }

            $query->setMaxResults($maxResults);
            $query->setFirstResult($pageOffset);
        } elseif (null !== $limit) {
            $query->setMaxResults($limit);
        }

        return array_map(
            function($item) {
                return $item['id'];
            },
            $query->getScalarResult()
        );
    }
971796
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $this->preFindBy($criteria);

        $result =  $this->doFindBy($criteria, $orderBy, $limit, $offset);
        $result = $this->postFindBy($result);

        return $result;
    }
344082
public function countSmartyFilterI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collSmartyFilterI18nsPartial && !$this->isNew();
        if (null === $this->collSmartyFilterI18ns || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collSmartyFilterI18ns) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getSmartyFilterI18ns());
            }

            $query = ChildSmartyFilterI18nQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterBySmartyFilter($this)
                ->count($con);
        }

        return count($this->collSmartyFilterI18ns);
    }
493803
public function listFilesWithType(string $type, array $filter = null, array $sortOrder = null, array $limit = null) {
		$timeStamp = microtime(true);
	    $typeOpts = array('a', 'i', 'v', 'f', 'd', 'p', 's', 'c');
        if(!in_array($type, $typeOpts)){
	        throw new InvalidFileTypeException($type);
		}
        $filter[] = array(
            'glue' => ' and',
            'condition' => array(
                'column' => $this->entity['f']['alias'] . '.type',
                'comparison' => '=',
                'value' => $type)
        );
        $response = $this->listFiles($filter, $sortOrder, $limit);

		$response->stats->execution->start = $timeStamp;
		$response->stats->execution->end = microtime(true);

		return $response;
    }
1188752
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null, $indexBy = null)
    {
        $this->checkRepository();

        $data = parent::findBy($criteria, $orderBy, $limit, $offset);

        if ($data && $indexBy) {
            $data = $this->sortCollection($data, $indexBy);
        }

        return $data;
    }
797939
public function findBy(
        array $criteria,
        ?array $orderBy = null,
        ?int $limit = null,
        ?int $offset = null
    ) : array {
        $objects = [];

        foreach ($this->objects as $object) {
            $matches = true;

            foreach ($criteria as $key => $value) {
                if ($object[$key] === $value) {
                    continue;
                }

                $matches = false;
            }

            if (! $matches) {
                continue;
            }

            $objects[] = $object;
        }

        return $objects;
    }
907663
public function search(Search $entity, $limit, $offset, $sort_column, $sort_direction)
    {
        $selector = $this->selector
            ->create()
            ->addCountry($entity)
            ->addDateAdd($entity)
            ->addDateEnd($entity)
            ->addDatePremiere($entity)
            ->addGenres($entity)
            ->addLabels($entity)
            ->addName($entity)
            ->addStorage($entity)
            ->addStudio($entity)
            ->addType($entity)
            ->sort($sort_column, $sort_direction)
            ->limit($limit)
            ->offset($offset);

        return [
            'list' => $selector
                ->getQuerySelect()
                ->getQuery()
                ->getResult(),
            'total' => $selector
                ->getQueryTotal()
                ->getQuery()
                ->getSingleScalarResult(),
        ];
    }
1321994
public function getPager(array $criteria, $page, $limit = 10, array $sort = [])
    {
        if (!isset($criteria['mode'])) {
            $criteria['mode'] = 'public';
        }

        $parameters = [];
        $query = $this->getRepository()
            ->createQueryBuilder('p')
            ->select('p, t')
            ->orderBy('p.publicationDateStart', 'DESC');

        if ('admin' === $criteria['mode']) {
            $query
                ->leftJoin('p.tags', 't')
                ->leftJoin('p.author', 'a')
            ;
        } else {
            $query
                ->leftJoin('p.tags', 't', Join::WITH, 't.enabled = true')
                ->leftJoin('p.author', 'a', Join::WITH, 'a.enabled = true')
            ;
        }

        if (!isset($criteria['enabled']) && 'public' === $criteria['mode']) {
            $criteria['enabled'] = true;
        }
        if (isset($criteria['enabled'])) {
            $query->andWhere('p.enabled = :enabled');
            $parameters['enabled'] = $criteria['enabled'];
        }

        if (isset($criteria['date'], $criteria['date']['query'], $criteria['date']['params'])) {
            $query->andWhere($criteria['date']['query']);
            $parameters = array_merge($parameters, $criteria['date']['params']);
        }

        if (isset($criteria['tag'])) {
            $query
                ->leftJoin('p.tags', 't2')
                ->andWhere('t2.slug LIKE :tag');
            $parameters['tag'] = (string) $criteria['tag'];
        }

        if (isset($criteria['author'])) {
            if (!\is_array($criteria['author']) && stristr($criteria['author'], 'NULL')) {
                $query->andWhere('p.author IS '.$criteria['author']);
            } else {
                $query->andWhere(sprintf('p.author IN (%s)', implode(',', (array) $criteria['author'])));
            }
        }

        if (isset($criteria['collection']) && $criteria['collection'] instanceof CollectionInterface) {
            $query->andWhere('p.collection = :collectionid');
            $parameters['collectionid'] = $criteria['collection']->getId();
        }

        $query->setParameters($parameters);

        $pager = new Pager();
        $pager->setMaxPerPage($limit);
        $pager->setQuery(new ProxyQuery($query));
        $pager->setPage($page);
        $pager->init();

        return $pager;
    }