@param $criteria
@param null|array $orderBy
@param null|int   $limit
@param null|int   $offset

@return Statement
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);
    }
1362978
public function getFiles(Array $criteria = array(), Array $orderBy = NULL) {
    $files = new \Psc\Data\ArrayCollection(
      $this->manager->getRepository()->findBy($criteria, $orderBy)
    );
    
    foreach ($files as $file) {
      $this->manager->attach($file);
    }
    
    return $files;
  }
143320
public function findBy(array $where, array $orderBy = null, $limit = null, $offset = null)
    {
        return $this->getRepository()->findBy($where, $orderBy, $limit, $offset);
    }
1092409
public function complexFindBy(array $criteria, array $orderBy = [], $limit = null, $offset = null)
    {
        $qb = $this->createQueryBuilder("p");

        foreach($criteria as $c => $v){
            $qb->andWhere("p.$c $v");
        }
        foreach($orderBy as $c => $v){
            $qb->addOrderBy("p.".$c,$v);
        }
        if (isset($limit)) $qb->setMaxResults($limit);
        if (isset($offset)) $qb->setFirstResult($offset);

        return $qb->getQuery()->getResult();
    }
1282679
public function addOrderBy(array $orderBy): void
    {
        if (empty($orderBy)) {
            return;
        }
        $orderByList = [];
        foreach ($orderBy as $clause) {
            $clause['key'] = $this->quoteName($clause['key']);
            array_push($orderByList, $clause['key'] . ' ' . $clause['direction']);
        }
        $pattern = ' ORDER BY %s';
        $this->statement .= sprintf($pattern, implode(', ', $orderByList));
        $this->statement .= PHP_EOL;
    }
802423
public function findBy(array $criteria, array $sorting = null, $limit = null, $offset = null)
    {
        $queryBuilder = $this->getCollectionQueryBuilder();

        $this->applyCriteria($queryBuilder, $criteria);
        $this->applySorting($queryBuilder, (array) $sorting);

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

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

        $query = $queryBuilder->getQuery();

        if (null !== $limit) {
            return $this->collectionResult($query);
        }

        return $query->getResult();
    }
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;
    }
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);
    }
1006919
private function getSearchQueryOrderBy($query, $orderBy)
	{
		foreach ($orderBy as $key => $value) {
			$query->orderBy($key, $value);
		}

		return $query;
	}
1326103
private function addOrderBy(QueryBuilder $qb, array $orderBy = [])
    {
        if (count($orderBy)) {
            $alias = $qb->getAllAliases()[0];
            foreach ($orderBy as $sortCol => $order) {
                $qb->orderBy($alias . '.' . $sortCol, $order);
            }
        }

        return $qb;
    }
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);
    }
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;
    }
1235873
public function search_records(array $searchFields, array $requiredFields, $orderBy=null, $limit=null, $offset=null) {
		$data = array();
		if(is_array($searchFields) && is_array($requiredFields)) {
			$limitOffsetStr = '';
			if(is_numeric($limit) && $limit > 0) {
				$limitOffsetStr = ' LIMIT '. $limit;
				
				//using an offset without a limit seems silly...
				if(is_numeric($limitOffsetStr) && $offset > 0) {
					$limitOffsetStr .= ' OFFSET '. $offset;
				}
			}
			
			$filterStr = '';
			$required = '';
			$params = array();
			foreach($searchFields as $f=>$v) {
				$filterStr = ToolBox::create_list($filterStr, '(lower('. $f .') LIKE :'. $f .' OR :'. $f .' IS NULL)', ' AND ');
				$params[$f] = '%'. $v .'%';
			}
			foreach($requiredFields as $f=>$v) {
				$required = ToolBox::create_list($required, $f .'=:'. $f, ', ');
				$params[$f] = $v;
			}
			
			$sql = 'SELECT * FROM '. $this->tableName .' WHERE ('. $filterStr .') AND '. $required . $orderByStr . $limitOffsetStr;
			
			$orderByStr = ' ORDER BY '. $this->pkeyField;
			if(is_string($orderBy) && strlen($orderBy)) {
				$orderByStr = ' ORDER BY '. $orderBy;
			}
			
			try {
				$data = $this->dbObj->run_query($sql, $params);
			}
			catch(Exception $e) {
				throw new Exception(__METHOD__ .': error while performing search: '. $e->getMessage());
			}
		}
		else {
			throw new Exception(__METHOD__ .': missing searchFields or requiredFields');
		}
		
		return($data);
	}
598445
public function getOneEntityBy(array $criteria = [], array $orders = [], $offset = null): ?AbstractEntity
    {
        $entity = $this->getRepository()->findOneBy($criteria, $orders, $offset);

        if ($entity instanceof AbstractEntity) {
            $this->prepareEntityForGet($entity);
        }

        return $entity;
    }
296203
public function findOne($where = null, $orderby = null)
  {
    $m = $this->getManager();
    $q = $m->getQueryBuilder()
      ->select($this->getTable())
      ->where($where)
      ->orderby($orderby)
      ->limit(1);

    return $this->fetchObject($m->query($q));
  }
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;
    }
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);

    }