/** * Replaces all having clauses and resets DQL's having part * * @param Query\Expr\Andx $having * @param ColumnCollection $columns * @param QueryBuilder $queryBuilder */ protected function replaceHaving(Query\Expr\Andx $having, ColumnCollection $columns, QueryBuilder $queryBuilder) { foreach ($having->getParts() as $part) { $this->replaceSingleHavingClause($part, $columns, $queryBuilder); } $queryBuilder->resetDQLPart('having'); }
/** * @param string $alias * @return Expr\Andx|Expr\Comparison|Expr\Composite|null */ public function getWhere($alias) { $expr = new Expr\Andx(); foreach ($this->criteria as $key => $value) { $expr->add(new Expr\Comparison(sprintf("%s.%s", $alias, $key), Expr\Comparison::EQ, $value)); } return $expr->count() != 0 ? $expr : null; }
protected function applySpecifications(QueryBuilder $queryBuilder, $alias) { $andX = new Query\Expr\Andx(); foreach ($this->specifications as $specification) { array_map([$andX, 'add'], array_filter((array) $specification->match($queryBuilder, $alias))); } if ($andX->count() > 0) { $queryBuilder->andWhere($andX); } }
/** * @param string $alias * @return Expr\Andx|Expr\Comparison|Expr\Composite|null */ public function getWhere($alias) { $expr = new Expr\Andx(); foreach ($this->fits as $fit) { if ($fit instanceof WhereFitInterface) { $expr->add($fit->getWhere($alias)); } } return $expr->count() != 0 ? $expr : null; }
/** * {@inheritdoc} */ public function addAndExpression(Andx $andExpr, QueryBuilder $pivot, $searchField, $searchValue, &$i) { list($_dateStart, $_dateEnd) = explode(' - ', $searchValue); $dateStart = new \DateTime($_dateStart); $dateEnd = new \DateTime($_dateEnd); $dateEnd->setTime(23, 59, 59); $k = $i + 1; $andExpr->add($pivot->expr()->between($searchField, '?' . $i, '?' . $k)); $pivot->setParameter($i, $dateStart->format('Y-m-d H:i:s')); $pivot->setParameter($k, $dateEnd->format('Y-m-d H:i:s')); $i += 2; return $andExpr; }
public function createGridQueryBuilder($entityClass, $params) { $qb = $this->em->createQueryBuilder(); $qb->from($entityClass, 'o'); $this->_addJoinEntity($qb, $params); $searches = array(); if (isset($params['search']['value'])) { $searches = explode(" ", trim($params['search']['value'])); for ($index = 0; $index < count($searches); $index++) { $qb->setParameter('main_search_' . $index, '%' . $searches[$index] . '%'); } } $fieldsSearch = new Expr\Andx(); $globalSearch = new Expr\Orx(); if (isset($params['columns'])) { foreach ($params['columns'] as $columns) { if ($columns['name'] && substr($columns['name'], 0, 1) != '_') { $field = $this->_getFieldName($columns['name']); $fieldAlias = str_replace(".", "_", $columns['name']); for ($index = 0; $index < count($searches); $index++) { $globalSearch->add($qb->expr()->like($field, ':main_search_' . $index)); } if ($columns['search']['value']) { $fieldsSearch->add($qb->expr()->like($field, ':' . $fieldAlias . '_search')); $qb->setParameter($fieldAlias . '_search', '%' . $columns['search']['value'] . '%'); } } } } $searchWhere = new Expr\Andx(); if (isset($fieldsSearch)) { $searchWhere->add($fieldsSearch); } if (isset($globalSearch)) { $searchWhere->add($globalSearch); } if ($searchWhere->count()) { $qb->andWhere($searchWhere); } return $qb; }
/** * @param \Doctrine\ORM\QueryBuilder $query * @return \Doctrine\ORM\QueryBuilder */ public function generateWhere(QueryBuilder $query) { $orxSearch = new Expr\Orx(); $andxIndv = new Expr\Andx(); $parameters = new ArrayCollection(); foreach ($this->getClauses() as $key => $value) { if (isset($value['indv'])) { $andxIndv->add($value['indv']['clause']); $this->createParameters($value['indv']['params'], $parameters); } if (isset($value['search'])) { $orxSearch->add($value['search']['clause']); $this->createParameters($value['search']['params'], $parameters); } } $andxIndv->add($orxSearch); $query->where($andxIndv); $p = $parameters->toArray(); foreach ($p as $param) { $query->setParameter($param->getName(), $param->getValue(), $param->getType()); } return $query; }
/** * @group DDC-1686 */ public function testExpressionGetter() { // Andx $andx = new Expr\Andx(array('1 = 1', '2 = 2')); $this->assertEquals(array('1 = 1', '2 = 2'), $andx->getParts()); // Comparison $comparison = new Expr\Comparison('foo', Expr\Comparison::EQ, 'bar'); $this->assertEquals('foo', $comparison->getLeftExpr()); $this->assertEquals('bar', $comparison->getRightExpr()); $this->assertEquals(Expr\Comparison::EQ, $comparison->getOperator()); // From $from = new Expr\From('Foo', 'f', 'f.id'); $this->assertEquals('f', $from->getAlias()); $this->assertEquals('Foo', $from->getFrom()); $this->assertEquals('f.id', $from->getIndexBy()); // Func $func = new Expr\Func('MAX', array('f.id')); $this->assertEquals('MAX', $func->getName()); $this->assertEquals(array('f.id'), $func->getArguments()); // GroupBy $group = new Expr\GroupBy(array('foo DESC', 'bar ASC')); $this->assertEquals(array('foo DESC', 'bar ASC'), $group->getParts()); // Join $join = new Expr\Join(Expr\Join::INNER_JOIN, 'f.bar', 'b', Expr\Join::ON, 'b.bar_id = 1', 'b.bar_id'); $this->assertEquals(Expr\Join::INNER_JOIN, $join->getJoinType()); $this->assertEquals(Expr\Join::ON, $join->getConditionType()); $this->assertEquals('b.bar_id = 1', $join->getCondition()); $this->assertEquals('b.bar_id', $join->getIndexBy()); $this->assertEquals('f.bar', $join->getJoin()); $this->assertEquals('b', $join->getAlias()); // Literal $literal = new Expr\Literal(array('foo')); $this->assertEquals(array('foo'), $literal->getParts()); // Math $math = new Expr\Math(10, '+', 20); $this->assertEquals(10, $math->getLeftExpr()); $this->assertEquals(20, $math->getRightExpr()); $this->assertEquals('+', $math->getOperator()); // OrderBy $order = new Expr\OrderBy('foo', 'DESC'); $this->assertEquals(array('foo DESC'), $order->getParts()); // Andx $orx = new Expr\Orx(array('foo = 1', 'bar = 2')); $this->assertEquals(array('foo = 1', 'bar = 2'), $orx->getParts()); // Select $select = new Expr\Select(array('foo', 'bar')); $this->assertEquals(array('foo', 'bar'), $select->getParts()); }
/** * @param Andx $andExpr * @param QueryBuilder $pivot * @param string $searchField * @param mixed $from * @param mixed $to * @param integer $i * * @return Andx */ protected function getBetweenAndExpression(Andx $andExpr, QueryBuilder $pivot, $searchField, $from, $to, $i) { $k = $i + 1; $andExpr->add($pivot->expr()->between($searchField, '?' . $i, '?' . $k)); $pivot->setParameter($i, $from); $pivot->setParameter($k, $to); return $andExpr; }
/** * Add a condition. * * @param Andx $andExpr * @param QueryBuilder $pivot * @param string $searchType * @param string $searchField * @param string $searchValue * @param integer $i * * @return Andx */ private function addCondition(Andx $andExpr, QueryBuilder $pivot, $searchType, $searchField, $searchValue, $i) { switch ($searchType) { case 'like': $andExpr->add($pivot->expr()->like($searchField, '?' . $i)); $pivot->setParameter($i, '%' . $searchValue . '%'); break; case 'notLike': $andExpr->add($pivot->expr()->notLike($searchField, '?' . $i)); $pivot->setParameter($i, '%' . $searchValue . '%'); break; case 'eq': $andExpr->add($pivot->expr()->eq($searchField, '?' . $i)); $pivot->setParameter($i, $searchValue); break; case 'neq': $andExpr->add($pivot->expr()->neq($searchField, '?' . $i)); $pivot->setParameter($i, $searchValue); break; case 'lt': $andExpr->add($pivot->expr()->lt($searchField, '?' . $i)); $pivot->setParameter($i, $searchValue); break; case 'lte': $andExpr->add($pivot->expr()->lte($searchField, '?' . $i)); $pivot->setParameter($i, $searchValue); break; case 'gt': $andExpr->add($pivot->expr()->gt($searchField, '?' . $i)); $pivot->setParameter($i, $searchValue); break; case 'gte': $andExpr->add($pivot->expr()->gte($searchField, '?' . $i)); $pivot->setParameter($i, $searchValue); break; case 'in': $andExpr->add($pivot->expr()->in($searchField, '?' . $i)); $pivot->setParameter($i, explode(',', $searchValue)); break; case 'notIn': $andExpr->add($pivot->expr()->notIn($searchField, '?' . $i)); $pivot->setParameter($i, explode(",", $searchValue)); break; case 'isNull': $andExpr->add($pivot->expr()->isNull($searchField)); break; case 'isNotNull': $andExpr->add($pivot->expr()->isNull($searchField)); break; } return $andExpr; }
/** * @param array $entities * @param $alias * @param string $conditionType * @param int $type * @param array $mapping * @return \Carrooi\Doctrine\Queries\Tree\Condition */ protected function createNestedTreeSearchCondition(array $entities, $alias, $conditionType = SearchType::CONDITION_OR, $type = SearchType::SEARCH_EVERYWHERE, array $mapping = []) { if ($conditionType === null) { $conditionType = SearchType::CONDITION_OR; } if ($type === null) { $type = SearchType::SEARCH_EVERYWHERE; } $mapping = $this->getMappingConfiguration($mapping); $condition = ['condition' => [], 'parameters' => []]; foreach ($entities as $entity) { $entityCondition = $this->createConditionForEntity($type, $entity, $alias, $mapping); $condition['condition'][] = $entityCondition['condition']; $condition['parameters'] = array_merge($condition['parameters'], $entityCondition['parameters']); } switch ($conditionType) { case SearchType::CONDITION_OR: $expr = new Orx(); break; case SearchType::CONDITION_AND: $expr = new Andx(); break; default: throw new InvalidArgumentException('Unknown condition type ' . $conditionType . '.'); break; } $condition['condition'] = $expr->addMultiple($condition['condition']); return new Condition($condition['condition'], $condition['parameters']); }
/** * {@inheritdoc} */ public function addAndExpression(Andx $andExpr, QueryBuilder $pivot, $searchField, $searchValue, &$i) { if (true === $this->range) { $array = explode(',', $searchValue); list($searchMin, $searchMax) = $array; } else { $searchMin = $this->min; $searchMax = $searchValue; } $k = $i + 1; $andExpr->add($pivot->expr()->between($searchField, '?' . $i, '?' . $k)); $pivot->setParameter($i, $searchMin); $pivot->setParameter($k, $searchMax); $i += 2; return $andExpr; }
public function testIsApplicableVisitTwice() { $config = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datagrid\\Common\\DatagridConfiguration')->disableOriginalConstructor()->getMock(); $config->expects($this->any())->method('offsetGetByPath')->will($this->returnValueMap([['[name]', null, ConfigurationProvider::GRID_PREFIX . '1'], [Builder::DATASOURCE_TYPE_PATH, null, OrmDatasource::TYPE]])); $this->marketingListHelper->expects($this->any())->method('getMarketingListIdByGridName')->with(ConfigurationProvider::GRID_PREFIX . '1')->will($this->returnValue(1)); $this->marketingListHelper->expects($this->any())->method('getMarketingList')->with(1)->will($this->returnValue(new MarketingList())); $this->assertTrue($this->extension->isApplicable($config)); $qb = $this->getQbMock(); $dataSource = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\OrmDatasource')->disableOriginalConstructor()->getMock(); $condition = new Andx(); $condition->add('argument'); $qb->expects($this->once())->method('getDQLParts')->will($this->returnValue(['where' => $condition])); $dataSource->expects($this->once())->method('getQueryBuilder')->will($this->returnValue($qb)); $this->extension->visitDatasource($config, $dataSource); $this->assertFalse($this->extension->isApplicable($config)); }
public function __construct($args = array()) { $this->allowedClasses[] = 'PerfectWeb\\Cassandra\\ORM\\Query\\Expr\\Andx'; parent::__construct($args); }