Apply criteria to select.

@param Criteria     $criteria
@param QueryBuilder $qb
@param string       $prefix

@return Composite
511633
private function applyCriteriaToQueryBuilder(Criteria $criteria, QueryBuilder $qb, $prefix)
    {
        if ($criteria->getMode() === Criteria::MODE_OR) {
            $expr = $qb->expr()->orX();
        } else {
            $expr = $qb->expr()->andX();
        }
        foreach ($criteria as $criterium) {
            if ($criterium instanceof Criteria) {
                $expr->add(
                    $this->applyCriteriaToQueryBuilder($criterium, $qb, $prefix)
                );
            } else {
                $this->applyCriteriumToQueryBuilder($criterium, $qb, $expr, $prefix);
            }
        }

        return $expr;
    }
1229984
public function matching(Criteria $criteria)
    {
        $persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName);

        return new LazyCriteriaCollection($persister, $criteria);
    }
479866
protected function setModelRegistryStatusCriteria($prefix)
    {
        $criteria_status = $this->query->getModelRegistry('criteria_status', '');

        if (trim($criteria_status) === '' || trim($criteria_status) === '0') {
        } else {
            $this->query->where('column', $prefix . '.status', 'IN', 'string', $criteria_status);
        }

        return $this;
    }
203627
public function applyFilters(QueryBuilder $qb)
    {
        foreach ($this->getFilters() as $filter) {

            $type = null;
            $placeholder = $filter['valuePlaceholder'];
            if (is_array($filter['value'])) {
                $type = Connection::PARAM_STR_ARRAY;
                $filter['valuePlaceholder'] = '(' . $placeholder . ')';
            }

            $qb->andWhere($filter['column'] .' '. $filter['operator'] .' '. $filter['valuePlaceholder'])
                ->setParameter($placeholder, $filter['value'], $type);
        }

        return $qb;
    }
362713
protected function select(array $fields, array $criteria = array(), array $operators = array(), array $conditions = array())
    {
        $sql = "";
        $stringConditions = array();
        
        if ((!empty($criteria) && !empty($operators)) && !empty($conditions)) {
            if ((count($criteria) == count($operators) && (count($criteria) - 1) == count($conditions)) 
                && ((count($operators) -1) != count($conditions) && count($criteria) > 1)) {
                throw new \Exception("The number of Criteria, Operators and Conditions are not equals.");
            }
            
            $criteriaFields = array_keys($criteria);
            
            $stringConditions[] = "$criteriaFields[0] $operators[0] ?";
            
            for ($i = 1; $i < count($criteriaFields); $i++) {
                $j = $i - 1;
                $stringConditions[] = "$conditions[$j] $criteriaFields[$i] $operators[$i] ?";
            }
            
            $sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table " 
                . "WHERE " . implode(' ', $stringConditions);
        } elseif ((!empty($criteria) && !empty($operators)) && count($criteria) > 1) {
            if (count($criteria) != count($operators)) {
                throw new \Exception("The number of Criteria and Operators are not equals.");
            }
            
            $criteriaFields = array_keys($criteria);
            
            for ($i = 0; $i < count($criteriaFields); $i++) {
                $stringConditions[] = "$criteriaFields[$i] $operators[$i] ?";
            }
            
            $sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table " 
                . "WHERE " . implode(' AND ', $stringConditions);
        } elseif (!empty($criteria)) {
            foreach ($criteria as $field => $value) {
                $stringConditions[] = "$field = ?";
            }
            
            $sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table " 
                . "WHERE " . implode(' AND ', $stringConditions);
        } elseif (!empty($fields)) {
            $sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table";
        }
        
        $pdos = $this->_pdo->prepare($sql);
        $pdos->execute(array_values($criteria));
        
        return $pdos->fetchAll();
    }
36964
public function getChildren(Criteria $criteria = null, ConnectionInterface $con = null)
    {
        if (null === $this->collNestedSetChildren || null !== $criteria) {
            if ($this->isLeaf() || ($this->isNew() && null === $this->collNestedSetChildren)) {
                // return empty collection
                $this->initNestedSetChildren();
            } else {
                $collNestedSetChildren = ChildCategoryQuery::create(null, $criteria)
                    ->childrenOf($this)
                    ->orderByBranch()
                    ->find($con);
                if (null !== $criteria) {
                    return $collNestedSetChildren;
                }
                $this->collNestedSetChildren = $collNestedSetChildren;
            }
        }

        return $this->collNestedSetChildren;
    }
1083928
public function matching(Criteria $criteria)
    {
        $clause = [];
        /** @var Comparison $whereClause */
        $whereClause = $criteria->getWhereExpression();
        if (null !== $whereClause) {
            if (Comparison::EQ !== $whereClause->getOperator()) {
                throw new \InvalidArgumentException(sprintf('Support for Selectable is limited to the EQUALS "=" operator, 
                 % given', $whereClause->getOperator()));
            }

            $clause = [$whereClause->getField() => $whereClause->getValue()->getValue()];
        }

        return $this->findBy($clause, $criteria->getOrderings(), $criteria->getMaxResults(), $criteria->getFirstResult());
    }
1332147
private function applyCriteriaToQuery(Criteria $criteria, Query $query, $prefix = '')
    {
        if (!count($criteria)) {
            return;
        }

        $query->setPostFilter($this->createFilterFromCriteria($criteria));
    }
856572
protected function applyWhere(QueryBuilder $qb, array $where): void
    {
        $whereType = $this->getContext()->getDefinition()->getArgument('where')->getType();

        /** @var InputObjectDefinition $whereDefinition */
        $whereDefinition = $this->getContext()->getEndpoint()->getType($whereType);

        /** @var ObjectDefinition $node */
        $node = $this->getContext()->getEndpoint()->getType($this->getContext()->getDefinition()->getNode());

        foreach ($where as $filterName => $condition) {
            $filterDefinition = $whereDefinition->getField($filterName);

            //TODO: load filters from services
            /** @var FilterInterface $filter */
            $filter = (new \ReflectionClass($filterDefinition->getResolver()))->newInstanceWithoutConstructor();

            $fieldName = $filterDefinition->getMeta('filter_field');
            if ($fieldName && $node->hasField($fieldName)) {
                $relatedField = $node->getField($fieldName);
                $filterContext = new FilterContext($this->getContext()->getEndpoint(), $node, $relatedField);
            } else {
                $filterContext = new FilterContext($this->getContext()->getEndpoint(), $node);
            }

            $filter($filterContext, $qb, $condition);
        }
    }
1119345
protected function applyCriteria(QueryBuilder $queryBuilder, array $criteria = [])
    {
        foreach ($criteria as $property => $value) {
            $name = $this->getPropertyName($property);
            if (null === $value) {
                $queryBuilder->andWhere($queryBuilder->expr()->isNull($name));
            } elseif (is_array($value)) {
                $queryBuilder->andWhere($queryBuilder->expr()->in($name, $value));
            } elseif ('' !== $value) {
                $parameter = str_replace('.', '_', $property);
                $queryBuilder
                    ->andWhere($queryBuilder->expr()->eq($name, ':'.$parameter))
                    ->setParameter($parameter, $value)
                ;
            }
        }
    }
1368776
public function getFilter(QueryBuilder $qb, $dqlAlias)
    {
        return (string) $qb->expr()->not($this->child->getFilter($qb, $dqlAlias));
    }
838332
protected function applyPagination(RestRequestContract $request, QueryBuilder $qb)
    {
        $qb->addCriteria(
            new Criteria(null,
                $request->getOrderBy(),
                $request->getStart(),
                $request->getLimit()
            )
        );

        return $this;
    }
1051120
protected function applyCriteriaToCursor(Criteria $criteria, MongoCursor $mongoCursor) {
		$sort   = $criteria->getSortConditions();
		$offset = $criteria->getOffset();
		$limit  = $criteria->getLimit();
				
		if (! empty($sort)) {
			$mongoCursor->sort($sort);
		}
		
		if ($offset !== null) {
			$mongoCursor->skip($offset);
		}

		if ($limit !== null) {
			$mongoCursor->limit($limit);
		}
	}
45261
public function applyToQueryBuilder(QueryBuilder $qb, &$parameterOffset = 0)
	{
		$expr = $qb->expr();

		$conditions = $this->conditions;
		foreach ($conditions as $condition) {
			$field = $condition[self::FIELD_POS];
			switch ($field) {
				case self::LEFT_FIELD:
				case self::RIGHT_FIELD:
				case self::LEVEL_FIELD:
					break;
				default:
					throw new Exception\InvalidArgument("Field $field is not recognized");
			}

			$where = null;
			$field = "e.$field";
			$parameterIndex = $parameterOffset;
			$parameterOffset++;

			$relation = $condition[self::RELATION_POS];
			$value = $condition[self::VALUE_POS];
			$valueExpr = '?' . $parameterIndex;
			
			switch ($relation) {
				case self::RELATION_EQUALS:
					$where = $expr->eq($field, $valueExpr);
					break;
				case self::RELATION_LESS_OR_EQUALS:
					$where = $expr->lte($field, $valueExpr);
					break;
				case self::RELATION_GREATER_OR_EQUALS:
					$where = $expr->gte($field, $valueExpr);
					break;
				case self::RELATION_LESS:
					$where = $expr->lt($field, $valueExpr);
					break;
				case self::RELATION_GREATER:
					$where = $expr->gt($field, $valueExpr);
					break;
				case self::RELATION_NOT_EQUALS:
					$where = $expr->neq($field, $valueExpr);
					break;
				default:
					throw new Exception\InvalidArgument("Relation $relation is not recognized");
			}

			$qb->andWhere($where)
					->setParameter($parameterIndex, $value);
		}
		
		if ( ! empty($this->additionalCondition)) {
			$qb->andWhere($this->additionalCondition);
		}
	}
733668
private function handleIndexedFields($qb, $criteria)
    {
        $criteria = (is_array($criteria)) ? $criteria : array();
        /* join indexation */
        if (empty($criteria)) {
            return;
        }
        foreach ($criteria as $criterion) {
            //ajouter test
            if (count($criterion) !== 3) {
                continue;
            }
            $criterion = (object) $criterion;
            $alias = uniqid('i'.rand());
            $qb->leftJoin('cc._indexation', $alias)
                    ->andWhere($alias.'._field = :field'.$alias)
                    ->andWhere($alias.'._value '.$criterion->op.' :value'.$alias)
                    ->setParameter('field'.$alias, $criterion->field)
                    ->setParameter('value'.$alias, $criterion->value);
        }
    }
162512
public function getPager($criteria, $page = 1)
    {
        $container = $this->getContainer();

        $paginator = $container->get('knp_paginator');

        $settings = $this->getSettings();

        $limit = $settings['articles_per_page'];

        $parameters = [];

        /** @var ArticlesRepository $repository */
        $repository = $this->getRepository();

        $qb = $repository->createQueryBuilder('p');

        $qb->select('p')->orderBy('p.publicationAt', 'DESC');

        if (!isset($criteria['enabled'])) {
            $criteria['enabled'] = true;
        }

        if (isset($criteria['enabled'])) {
            $currentTime = new \DateTime();

            $qb->andWhere('p.enabled = :enabled');
            $qb->andWhere(
                $qb->expr()->lt('p.publicationAt', ':datetime')
            );

            $parameters['datetime'] = $currentTime;
            $parameters['enabled'] = $criteria['enabled'];
        }

        $qb->setParameters($parameters);

        $pagination = $paginator->paginate(
            $qb,
            $page,
            $limit
        );

        return $pagination;
    }
418184
public function applyExprFromArray($qb, $alias, array $criteria)
	{
		$pos = 0;
		
		foreach ($criteria as $field => $exprValue) {
			$this->applyExprFromString($qb, $alias, $field, $exprValue, ':'.$field.($pos++));
		}
	}