Find messages by criteria.

@param Criteria $criteria
@param array    $order
@param int      $limit
@param int      $offset

@return Filter
160607
public function findByCriteria(Criteria $criteria, $order = null, $limit = null, $offset = 0)
    {
        $qb = $this->createCriteriaQueryBuilder($criteria, 'm');

        if ($order) {
            foreach ($order as $field => $dir) {
                $qb->orderBy("m.$field", $dir);
            }
        }
        if ($limit) {
            $qb->setMaxResults($limit);
        }
        if ($offset) {
            $qb->setFirstResult($offset);
        }

        return $qb->getQuery()->getResult();
    }
391723
protected function createPaginatedQueryBuilder(array $criteria = [], $indexBy = null, array $orderBy = null)
    {
        $qb = new PaginatedQueryBuilder($this->_em);
        $qb->from($this->_entityName, $this->getEntityAlias(), $indexBy);

        $this->processCriteria($qb, $criteria);

        return $qb;
    }
759732
public function find(array $criteria = [], array $orderBy = null, $limit = null, $offset = null)
    {
        // @todo implement these
        if ($orderBy !== null || $limit !== null || $offset !== null) {
            throw new \Exception('orderBy, limit and offset not yet implemented');
        }

        if (empty($criteria)) {
            return $this->getConfigs();
        }

        return $this->search($criteria);
    }
1008714
public function applyFilter(Criteria $criteria, $filter)
    {
        if (!is_array($filter) || !is_array($this->filterable)) {
            return $criteria;
        }

        foreach ($this->filterable as $field) {
            if (array_key_exists($field, $filter)) {
                $this->processEqualFilter($criteria, $field, $filter[$field]);
                $this->processBetweenFilter($criteria, $field, $filter[$field]);
                $this->processOperatorFilter($criteria, $field, $filter[$field]);
            }
        }

        return $criteria;
    }
358439
public function getMatchCypher(array $criteria = [], $orderBy = null, $limit = null, $offset = null)
    {
        $identifier = $this->_classMetadata->getEntityAlias();
        $classLabel = $this->_classMetadata->getLabel();
        $cypher = 'MATCH ('.$identifier.':'.$classLabel.') ';

        $filter_cursor = 0;
        $params = [];

        foreach ($criteria as $key => $criterion) {
            $key = (string) $key;
            $clause = $filter_cursor === 0 ? 'WHERE' : 'AND';
            $cypher .= sprintf('%s %s.%s = {%s} ', $clause, $identifier, $key, $key);
            $params[$key] = $criterion;
            ++$filter_cursor;
        }

        $cypher .= 'RETURN '.$identifier;

        if (is_array($orderBy) && count($orderBy) > 0) {
            $cypher .= PHP_EOL;
            $i = 0;
            foreach ($orderBy as $property => $order) {
                $cypher .= $i === 0 ? 'ORDER BY ' : ', ';
                $cypher .= sprintf('%s.%s %s', $identifier, $property, $order);
                ++$i;
            }
        }

        if (is_int($offset) && is_int($limit)) {
            $cypher .= PHP_EOL;
            $cypher .= sprintf('SKIP %d', $offset);
        }

        if (is_int($limit)) {
            $cypher .= PHP_EOL;
            $cypher .= sprintf('LIMIT %d', $limit);
        }

        return Statement::create($cypher, $params);
    }
298767
public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array
    {
        $table = $this->getTable();

        $this->logger->info(
            'model: find rows within table {table} with criteria {criteria}',
            ['table' => $table, 'criteria' => $criteria, 'orderBy' => $orderBy, 'limit' => $limit, 'offset' => $offset]
        );

        $qb = $this->connection->createQueryBuilder()
            ->select('*')
            ->from($table)
            ->setFirstResult($offset)
            ->setMaxResults($limit)
        ;

        $this->addCriteriaToQueryBuilder($qb, $criteria);
        $this->addOrderByToQueryBuilder($qb, $orderBy);

        $rows = $qb->execute()->fetchAll(\PDO::FETCH_ASSOC);

        if ([] === $rows) {
            return [];
        }

        $models = [];
        foreach ($rows as $row) {
            $this->storageCache->set($row['id'], $row);

            $models[] = $this->fromPersistence($row);
        }

        return $models;
    }
506524
public function getEntitiesBy(array $criteria = [], array $orders = [], $limit = null, $offset = null): array
    {
        $entities = $this->getRepository()->findBy($criteria, $orders, $limit, $offset);
        $this->prepareEntitesForGet($entities);

        return $entities;
    }
993764
public function complexFindOneBy(array $criteria, array $orderBy = [])
    {
        $qb = $this->createQueryBuilder("p");

        foreach($criteria as $c => $v){
            $qb->andWhere("p.$c $v");
        }
        foreach($orderBy as $c => $v){
            $qb->addOrderBy("p.".$c,$v);
        }
        $qb->setMaxResults(1);
        return $qb->getQuery()->getResult()[0] ?? null;
    }
1155268
public function applyLimit(&$sql, $offset, $limit, $criteria = null)
    {
        if (BasePeer::needsSelectAliases($criteria)) {
            $crit = clone $criteria;
            $selectSql = $this->createSelectSqlPart($crit, $params, true);
            $sql = $selectSql . substr($sql, strpos($sql, 'FROM') - 1);
        }
        $sql = 'SELECT B.* FROM ('
            . 'SELECT A.*, rownum AS PROPEL_ROWNUM FROM (' . $sql . ') A '
            . ') B WHERE ';

        if ($offset > 0) {
            $sql .= ' B.PROPEL_ROWNUM > ' . $offset;
            if ($limit > 0) {
                $sql .= ' AND B.PROPEL_ROWNUM <= ' . ($offset + $limit);
            }
        } else {
            $sql .= ' B.PROPEL_ROWNUM <= ' . $limit;
        }
    }
668904
public function getFindByQuery(array $criteria = null, array $orderBy = null, $limit = null, $offset = null)
    {
        /** @var \Doctrine\ORM\QueryBuilder $qb */
        $qb = $this->createQueryBuilder('e');

        $firstCriteria = true;
        if (!empty($criteria)) {
            foreach ($criteria as $field => $value) {
                if ($firstCriteria) {
                    if ($value === null or $value === 'null') {
                        $qb->where("e.$field IS NULL");
                    } elseif ($value === 'not null') {
                        $qb->where("e.$field IS NOT NULL");
                    } else {
                        $qb->where("e.$field = :$field");
                        $qb->setParameter($field, $value);
                    }

                    $firstCriteria = false;
                } else {
                    if ($value === null or $value === 'null') {
                        $qb->andWhere("e.$field IS NULL");
                    } elseif ($value === 'not null') {
                        $qb->andWhere("e.$field IS NOT NULL");
                    } else {
                        $qb->andWhere("e.$field = :$field");
                        $qb->setParameter($field, $value);
                    }
                }
            }
        }

        $firstOrderBy = true;
        if (!empty($orderBy)) {
            foreach ($orderBy as $field => $value) {
                if ($firstOrderBy) {
                    $qb->orderBy("e.$field", $value);
                    $firstOrderBy = false;
                } else {
                    $qb->addOrderBy("e.$field", $value);
                }
            }
        }

        if (!empty($limit)) {
            $qb->setMaxResults($limit);
        }

        if (!empty($offset)) {
            $qb->setFirstResult($offset);
        }

        return $qb->getQuery();
    }
35668
public function find(array $filter = [], array $orderBy = [], $limit = 0,
        $offset = 0, array $associate = []
    ) {
        try {

            $query = $this->query()
                ->select()
                ->associate($associate)
                ->setFilter($filter);

            foreach ($orderBy as $orderByRule) {
                $query->orderBy($orderByRule[0], $orderByRule[1]);
            }

            return $query->limit($limit)->offset($offset)->run($this->connection);
        } catch (Exception\QueryException $e) {
            throw new Exception\RepositoryException($e->getMessage());
        }
    }
868238
public function filterBy(array $criteria, array $orderBy = null, $limit = null, $offset = null, CompositeExpression $externalExpression = null)
    {
        $expressionBuilder = Criteria::expr();
        $criteriaObject = Criteria::create();
        $criteriaObject->setFirstResult($offset);
        $criteriaObject->setMaxResults($limit);
        $criteriaObject->orderBy($orderBy);


        if (array_key_exists('search', $criteria)) {
            $criteriaObject->andWhere($this->getSearchExpression($criteria['search']));
            unset($criteria['search']);
        }

        foreach ($criteria as $key => $value) {
            $expression = $expressionBuilder->andX(
                $expressionBuilder->eq($key, $value)
            );
            $criteriaObject->andWhere($expression);
        }

        if ($externalExpression) {
            $criteriaObject->andWhere($externalExpression);
        }

        return $this->getRepository()->matching($criteriaObject);
    }
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(),
        ];
    }
1229415
public function matching(Criteria $criteria)
    {
        $visitor = new QueryExpressionVisitor($this->createQueryBuilder());
        $queryBuilder = $this->createQueryBuilder();

        if ($criteria->getWhereExpression() !== null) {
            $expr = $visitor->dispatch($criteria->getWhereExpression());
            $queryBuilder->setQueryArray($expr->getQuery());
        }

        if ($criteria->getMaxResults() !== null) {
            $queryBuilder->limit($criteria->getMaxResults());
        }

        if ($criteria->getFirstResult() !== null) {
            $queryBuilder->skip($criteria->getFirstResult());
        }

        if ($criteria->getOrderings() !== null) {
            $queryBuilder->sort($criteria->getOrderings());
        }

        // @TODO: wrap around a specialized Collection for efficient count on large collections
        return new ArrayCollection($queryBuilder->getQuery()->execute()->toArray());
    }
1342389
public function findOneBy(array $criteria, array $orderBy = null)
    {
        $persister = $this->entityManager->getEntityPersister($this->className);

        return $persister->load($criteria);
    }
1032397
public function limit($offset, $limit)
	{
		$this->criteria->setFirstResult($offset)->setMaxResults($limit);

		return $this;
	}
625582
public static function find($criteria = array(), $sort = array(), $fields = array() , $limit = null , $skip = null)
    {

        self::processCriteriaWithType($criteria);


        $results =  self::connection()->find(static::$collection, $criteria, self::mapFields($fields));

        if ( ! is_null($limit)) {
            $results->limit($limit);
        }

        if ( !  is_null($skip)) {
            $results->skip($skip);
        }

        if ( ! empty($sort)) {
            $results->sort(self::mapFields($sort));
        }

        return Hydrator::hydrate(get_called_class(), $results , Hydrator::TYPE_COLLECTION , true);

    }