private function resolveArgument($arg, DoctrineQueryBuilderParametersBinder $binder) { if (':' == $arg[0]) { // a field is being referenced return $this->exprMgr->getDqlPropertyName(substr($arg, 1)); } else { return '?' . ($binder->bind($arg) - 1); } }
private function processFilter(ExpressionManager $expressionManager, Expr\Composite $compositeExpr, QueryBuilder $qb, DoctrineQueryBuilderParametersBinder $binder, Filter $filter) { $name = $filter->getProperty(); $fieldName = $expressionManager->getDqlPropertyName($name); if (in_array($filter->getComparator(), array(Filter::COMPARATOR_IS_NULL, Filter::COMPARATOR_IS_NOT_NULL))) { // these are sort of 'special case' $compositeExpr->add($qb->expr()->{$filter->getComparator()}($fieldName)); } else { $value = $filter->getValue(); $comparatorName = $filter->getComparator(); if (!$this->isUsefulInFilter($filter->getComparator(), $filter->getValue()) || !$this->isUsefulFilter($expressionManager, $name, $value)) { return; } // when "IN" is used in conjunction with TO_MANY type of relation, // then we will treat it in a special way and generate "MEMBER OF" queries // instead $isAdded = false; if ($expressionManager->isAssociation($name)) { $mapping = $expressionManager->getMapping($name); if (in_array($comparatorName, array(Filter::COMPARATOR_IN, Filter::COMPARATOR_NOT_IN)) && in_array($mapping['type'], array(CMI::ONE_TO_MANY, CMI::MANY_TO_MANY))) { $statements = array(); foreach ($value as $id) { $statements[] = sprintf((Filter::COMPARATOR_NOT_IN == $comparatorName ? 'NOT ' : '') . '?%d MEMBER OF %s', $binder->getNextIndex(), $expressionManager->getDqlPropertyName($name)); $binder->bind($this->convertValue($expressionManager, $name, $id)); } if (Filter::COMPARATOR_IN == $comparatorName) { $compositeExpr->add(call_user_func_array(array($qb->expr(), 'orX'), $statements)); } else { $compositeExpr->addMultiple($statements); } $isAdded = true; } } if (!$isAdded) { if (is_array($value) && count($value) != count($value, \COUNT_RECURSIVE)) { // must be "OR-ed" ( multi-dimensional array ) $orStatements = array(); foreach ($value as $orFilter) { if (!$this->isUsefulInFilter($orFilter['comparator'], $orFilter['value']) || !$this->isUsefulFilter($expressionManager, $name, $orFilter['value'])) { continue; } if (in_array($orFilter['comparator'], array(Filter::COMPARATOR_IN, Filter::COMPARATOR_NOT_IN))) { $orStatements[] = $qb->expr()->{$orFilter['comparator']}($fieldName); } else { $orStatements[] = $qb->expr()->{$orFilter['comparator']}($fieldName, '?' . $binder->getNextIndex()); } $binder->bind($orFilter['value']); } $compositeExpr->add(call_user_func_array(array($qb->expr(), 'orX'), $orStatements)); } else { $compositeExpr->add($qb->expr()->{$comparatorName}($fieldName, '?' . $binder->getNextIndex())); $binder->bind($this->convertValue($expressionManager, $name, $value)); } } } }