/**
  * {@inheritdoc}
  */
 public function addFieldSorter($field, $direction, $locale = null, $scope = null)
 {
     $this->qb->addOrderBy($field, $direction);
     $idField = $this->qb->getRootAlias() . '.id';
     $this->qb->addOrderBy($idField);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldSorter($field, $direction, $locale = null, $scope = null)
 {
     $alias = 'inGroupSorter';
     $inGroupExpr = 'CASE WHEN :currentGroup MEMBER OF p.groups THEN true ELSE false END';
     $this->qb->addSelect(sprintf('%s AS %s', $inGroupExpr, $alias))->addOrderBy($alias, $direction);
     $idField = $this->qb->getRootAlias() . '.id';
     $this->qb->addOrderBy($idField);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldSorter($field, $direction, $locale = null, $scope = null)
 {
     $alias = 'sorterCompleteness';
     $util = new CompletenessJoin($this->qb);
     $util->addJoins($alias, $locale, $scope);
     $this->qb->addOrderBy($alias . '.ratio', $direction);
     $idField = $this->qb->getRootAlias() . '.id';
     $this->qb->addOrderBy($idField);
     return $this;
 }
 /**
  * Add completeness joins to query builder
  *
  * @param string $completenessAlias the join alias
  * @param string $locale            the locale
  * @param sting  $scope             the scope
  *
  * @return CompletenessJoin
  */
 public function addJoins($completenessAlias, $locale, $scope)
 {
     $rootAlias = $this->qb->getRootAlias();
     $localeAlias = $completenessAlias . 'Locale';
     $channelAlias = $completenessAlias . 'Channel';
     $rootEntity = current($this->qb->getRootEntities());
     $completenessMapping = $this->qb->getEntityManager()->getClassMetadata($rootEntity)->getAssociationMapping('completenesses');
     $completenessClass = $completenessMapping['targetEntity'];
     $this->qb->leftJoin('PimCatalogBundle:Locale', $localeAlias, 'WITH', $localeAlias . '.code = :cLocaleCode')->leftJoin('PimCatalogBundle:Channel', $channelAlias, 'WITH', $channelAlias . '.code = :cScopeCode')->leftJoin($completenessClass, $completenessAlias, 'WITH', $completenessAlias . '.locale = ' . $localeAlias . '.id AND ' . $completenessAlias . '.channel = ' . $channelAlias . '.id AND ' . $completenessAlias . '.product = ' . $rootAlias . '.id')->setParameter('cLocaleCode', $locale)->setParameter('cScopeCode', $scope);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldSorter($field, $direction)
 {
     $rootAlias = $this->qb->getRootAlias();
     $prefix = 'sorter';
     $field = $prefix . 'familyLabel';
     $family = $prefix . 'family';
     $trans = $prefix . 'familyTranslations';
     $this->qb->leftJoin($rootAlias . '.family', $family)->leftJoin($family . '.translations', $trans, 'WITH', $trans . '.locale = :dataLocale');
     $this->qb->addSelect('COALESCE(' . $trans . '.label, CONCAT(\'[\', ' . $family . '.code, \']\')) as ' . $field);
     $this->qb->addOrderBy($field, $direction);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AbstractAttribute $attribute, $operator, $value)
 {
     $joinAlias = 'filter' . $attribute->getCode() . $this->aliasCounter++;
     $backendField = sprintf('%s.%s', $joinAlias, $attribute->getBackendType());
     if ($operator === 'EMPTY') {
         $this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias));
         $this->qb->andWhere($this->prepareCriteriaCondition($backendField, $operator, $value));
     } else {
         $condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias);
         $condition .= ' AND ' . $this->prepareCriteriaCondition($backendField, $operator, $value);
         $this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeSorter(AttributeInterface $attribute, $direction, $locale = null, $scope = null)
 {
     $aliasPrefix = 'sorter';
     $joinAlias = $aliasPrefix . 'V' . $attribute->getCode();
     $backendType = $attribute->getBackendType();
     // join to value
     $condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope);
     $this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
     $joinAliasMetric = $aliasPrefix . 'M' . $attribute->getCode();
     $this->qb->leftJoin($joinAlias . '.' . $backendType, $joinAliasMetric);
     $this->qb->addOrderBy($joinAliasMetric . '.baseData', $direction);
     $idField = $this->qb->getRootAlias() . '.id';
     $this->qb->addOrderBy($idField);
     return $this;
 }
Example #8
0
 /**
  * Sets sorting.
  * @param array $sorting
  */
 public function sort(array $sorting)
 {
     foreach ($sorting as $key => $value) {
         $column = isset($this->sortMapping[$key]) ? $this->sortMapping[$key] : $this->qb->getRootAlias() . '.' . $key;
         $this->qb->addOrderBy($column, $value);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function entityJoin(array $associationMappings)
 {
     $alias = $this->queryBuilder->getRootAlias();
     $newAlias = 's';
     $joinedEntities = $this->queryBuilder->getDQLPart('join');
     foreach ($associationMappings as $associationMapping) {
         // Do not add left join to already joined entities with custom query
         foreach ($joinedEntities as $joinExprList) {
             foreach ($joinExprList as $joinExpr) {
                 $newAliasTmp = $joinExpr->getAlias();
                 if (sprintf('%s.%s', $alias, $associationMapping['fieldName']) === $joinExpr->getJoin()) {
                     $this->entityJoinAliases[] = $newAliasTmp;
                     $alias = $newAliasTmp;
                     continue 3;
                 }
             }
         }
         $newAlias .= '_' . $associationMapping['fieldName'];
         if (!in_array($newAlias, $this->entityJoinAliases)) {
             $this->entityJoinAliases[] = $newAlias;
             $this->queryBuilder->leftJoin(sprintf('%s.%s', $alias, $associationMapping['fieldName']), $newAlias);
         }
         $alias = $newAlias;
     }
     return $alias;
 }
 /**
  * {@inheritdoc}
  */
 private function getFieldName($field)
 {
     if (false === strpos($field, '.')) {
         return $this->queryBuilder->getRootAlias() . '.' . $field;
     }
     return $field;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeSorter(AbstractAttribute $attribute, $direction)
 {
     $aliasPrefix = 'sorter';
     $joinAlias = $aliasPrefix . 'V' . $attribute->getCode() . $this->aliasCounter++;
     $backendType = $attribute->getBackendType();
     // join to value and sort on
     $condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias);
     // Remove current join in order to put the orderBy related join
     // at first place in the join queue for performances reasons
     $joinsSet = $this->qb->getDQLPart('join');
     $this->qb->resetDQLPart('join');
     $this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
     $this->qb->addOrderBy($joinAlias . '.' . $backendType, $direction);
     // Reapply previous join after the orderBy related join
     $this->applyJoins($joinsSet);
     return $this;
 }
 /**
  * @param \Doctrine\ORM\QueryBuilder $qb
  * @param string $searchfield search field for IN query, uses rootAlias.id by default [optional]
  */
 public function __construct(QueryBuilder $qb, $searchfield = null)
 {
     $this->qb = $qb;
     if (null !== $searchfield) {
         $this->searchfield = $searchfield;
     } else {
         $this->searchfield = $qb->getRootAlias() . '.id';
     }
 }
 private function aliasExists($alias, QueryBuilder $qb)
 {
     $aliases = [];
     foreach ($qb->getDqlPart('join') as $joins) {
         foreach ($joins as $join) {
             $aliases[] = $join->getAlias();
         }
     }
     $aliases[] = $qb->getRootAlias();
     return in_array($alias, $aliases);
 }
 function it_adds_a_like_filter_in_the_query(QueryBuilder $queryBuilder, AbstractAttribute $sku)
 {
     $sku->getId()->willReturn(42);
     $sku->getCode()->willReturn('sku');
     $sku->getBackendType()->willReturn('varchar');
     $sku->isLocalizable()->willReturn(false);
     $sku->isScopable()->willReturn(false);
     $queryBuilder->expr()->willReturn(new Expr());
     $queryBuilder->getRootAlias()->willReturn('p');
     $condition = "filtersku1.attribute = 42 AND filtersku1.varchar LIKE 'My Sku'";
     $queryBuilder->innerJoin('p.values', 'filtersku1', 'WITH', $condition)->shouldBeCalled();
     $this->addAttributeFilter($sku, 'LIKE', 'My Sku');
 }
 function it_adds_empty_filter_in_the_query($attrValidatorHelper, QueryBuilder $queryBuilder, AttributeInterface $number)
 {
     $attrValidatorHelper->validateLocale($number, Argument::any())->shouldBeCalled();
     $attrValidatorHelper->validateScope($number, Argument::any())->shouldBeCalled();
     $number->getId()->willReturn(42);
     $number->getCode()->willReturn('number');
     $number->getBackendType()->willReturn('varchar');
     $number->isLocalizable()->willReturn(false);
     $number->isScopable()->willReturn(false);
     $queryBuilder->expr()->willReturn(new Expr());
     $queryBuilder->getRootAlias()->willReturn('p');
     $queryBuilder->leftJoin('p.values', Argument::any(), 'WITH', Argument::any())->shouldBeCalled();
     $queryBuilder->andWhere(Argument::any())->shouldBeCalled();
     $this->addAttributeFilter($number, 'EMPTY', 12);
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeSorter(AttributeInterface $attribute, $direction, $locale = null, $scope = null)
 {
     $aliasPrefix = 'sorter';
     $joinAlias = $aliasPrefix . 'V' . $attribute->getCode();
     $backendType = $attribute->getBackendType();
     if (null === $locale) {
         throw new \InvalidArgumentException(sprintf('Cannot prepare condition on type "%s" without locale', $attribute->getAttributeType()));
     }
     // join to value
     $condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope);
     $this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
     // then to option and option value to sort on
     $joinAliasOpt = $aliasPrefix . 'O' . $attribute->getCode();
     $condition = $joinAliasOpt . ".attribute = " . $attribute->getId();
     $this->qb->leftJoin($joinAlias . '.' . $backendType, $joinAliasOpt, 'WITH', $condition);
     $joinAliasOptVal = $aliasPrefix . 'OV' . $attribute->getCode();
     $condition = $joinAliasOptVal . '.locale = ' . $this->qb->expr()->literal($locale);
     $this->qb->leftJoin($joinAliasOpt . '.optionValues', $joinAliasOptVal, 'WITH', $condition);
     $this->qb->addOrderBy($joinAliasOpt . '.code', $direction);
     $this->qb->addOrderBy($joinAliasOptVal . '.value', $direction);
     $idField = $this->qb->getRootAlias() . '.id';
     $this->qb->addOrderBy($idField);
     return $this;
 }
 function it_adds_a_sorter_in_the_query(QueryBuilder $queryBuilder, AbstractAttribute $sku)
 {
     $sku->getId()->willReturn(42);
     $sku->getCode()->willReturn('sku');
     $sku->getBackendType()->willReturn('varchar');
     $sku->isLocalizable()->willReturn(false);
     $sku->isScopable()->willReturn(false);
     $queryBuilder->expr()->willReturn(new Expr());
     $queryBuilder->getRootAlias()->willReturn('p');
     $queryBuilder->getDQLPart('join')->willReturn([]);
     $queryBuilder->resetDQLPart('join')->shouldBeCalled();
     $condition = "sorterVsku1.attribute = 42";
     $queryBuilder->leftJoin('p.values', 'sorterVsku1', 'WITH', $condition)->shouldBeCalled();
     $queryBuilder->addOrderBy('sorterVsku1.varchar', 'DESC')->shouldBeCalled();
     $this->addAttributeSorter($sku, 'DESC');
 }
 function it_adds_not_equal_filter_in_the_query($attrValidatorHelper, QueryBuilder $queryBuilder, AttributeInterface $number, Expr $expr, Expr\Comparison $comp, Expr\Literal $literal)
 {
     $attrValidatorHelper->validateLocale($number, Argument::any())->shouldBeCalled();
     $attrValidatorHelper->validateScope($number, Argument::any())->shouldBeCalled();
     $number->getId()->willReturn(42);
     $number->getCode()->willReturn('number');
     $number->getBackendType()->willReturn('varchar');
     $number->isLocalizable()->willReturn(false);
     $number->isScopable()->willReturn(false);
     $queryBuilder->expr()->willReturn($expr);
     $queryBuilder->getRootAlias()->willReturn('p');
     $expr->literal(12)->willReturn($literal);
     $expr->neq(Argument::any(), $literal)->shouldBeCalled()->willReturn($comp);
     $literal->__toString()->willReturn('12');
     $comp->__toString()->willReturn('filtercode.backend_type <> 12');
     $queryBuilder->innerJoin('p.values', Argument::any(), 'WITH', Argument::containingString('.attribute = 42 AND filtercode.backend_type <> 12'))->shouldBeCalled();
     $this->addAttributeFilter($number, '!=', 12);
 }
 /**
  * Recreate query builder and set state again.
  *
  * @return void
  */
 public function __wakeup()
 {
     if ($this->constraint !== NULL) {
         $this->queryBuilder->where($this->constraint);
     }
     if (is_array($this->orderings)) {
         foreach ($this->orderings as $propertyName => $order) {
             $this->queryBuilder->addOrderBy($this->queryBuilder->getRootAlias() . '.' . $propertyName, $order);
         }
     }
     if (is_array($this->joins)) {
         foreach ($this->joins as $joinAlias => $join) {
             $this->queryBuilder->leftJoin($join, $joinAlias);
         }
     }
     $this->queryBuilder->setFirstResult($this->offset);
     $this->queryBuilder->setMaxResults($this->limit);
     $this->queryBuilder->setParameters($this->parameters);
     unset($this->parameters);
 }
 function it_adds_a_filter_on_a_field_in_the_query(QueryBuilder $qb, Expr $expr, EntityManager $em, ClassMetadata $cm, Expr\Comparison $comparison)
 {
     $qb->expr()->willReturn($expr);
     $qb->getRootAlias()->willReturn('p');
     $qb->getRootEntities()->willReturn([]);
     $qb->getEntityManager()->willReturn($em);
     $em->getClassMetadata(false)->willReturn($cm);
     $comparison->__toString()->willReturn('filterCompleteness.ratio < 100');
     $cm->getAssociationMapping('completenesses')->willReturn(['targetEntity' => 'test']);
     $expr->literal('100')->willReturn('100');
     $expr->lt(Argument::any(), '100')->willReturn($comparison);
     $this->setQueryBuilder($qb);
     $qb->leftJoin('PimCatalogBundle:Locale', Argument::any(), 'WITH', Argument::any())->willReturn($qb);
     $qb->leftJoin('PimCatalogBundle:Channel', Argument::any(), 'WITH', Argument::any())->willReturn($qb);
     $qb->leftJoin('test', Argument::any(), 'WITH', Argument::any())->willReturn($qb);
     $qb->setParameter('cLocaleCode', Argument::any())->willReturn($qb);
     $qb->setParameter('cScopeCode', Argument::any())->willReturn($qb);
     $qb->andWhere('filterCompleteness.ratio < 100')->shouldBeCalled();
     $this->addFieldFilter('completeness', '<', 100, 'en_US', 'mobile');
 }
Example #21
0
 /**
  * @param QueryBuilder $qb
  * @param Criteria     $criteria
  */
 public static function addCriteria(QueryBuilder $qb, Criteria $criteria)
 {
     $rootAlias = $qb->getRootAlias();
     $visitor = new QueryExpressionVisitor($rootAlias);
     if ($whereExpression = $criteria->getWhereExpression()) {
         $qb->andWhere($visitor->dispatch($whereExpression));
         foreach ($visitor->getParameters() as $parameter) {
             $qb->getParameters()->add($parameter);
         }
     }
     if ($criteria->getOrderings()) {
         foreach ($criteria->getOrderings() as $sort => $order) {
             $qb->addOrderBy($rootAlias . '.' . $sort, $order);
         }
     }
     // Overwrite limits only if they was set in criteria
     if (($firstResult = $criteria->getFirstResult()) !== null) {
         $qb->setFirstResult($firstResult);
     }
     if (($maxResults = $criteria->getMaxResults()) !== null) {
         $qb->setMaxResults($maxResults);
     }
 }
 function it_adds_a_greater_than_filter_on_an_attribute_to_the_query(AttributeInterface $attribute, $attrValidatorHelper, QueryBuilder $qb, Expr $expr, Expr\Comparison $comparison)
 {
     $attrValidatorHelper->validateLocale($attribute, Argument::any())->shouldBeCalled();
     $attrValidatorHelper->validateScope($attribute, Argument::any())->shouldBeCalled();
     $qb->getRootAlias()->willReturn('p');
     $attribute->getBackendType()->willReturn('backend_type');
     $attribute->getCode()->willReturn('code');
     $attribute->getId()->willReturn(42);
     $attribute->isLocalizable()->willReturn(false);
     $attribute->isScopable()->willReturn(false);
     $qb->expr()->willReturn($expr);
     $expr->literal('2014-03-15')->willReturn('code');
     $expr->literal('en_US')->willReturn('code');
     $expr->literal('mobile')->willReturn('code');
     $expr->gt(Argument::any(), 'code')->willReturn($comparison)->shouldBeCalledTimes(2);
     $comparison->__toString()->willReturn();
     $qb->innerJoin('p.values', Argument::any(), 'WITH', Argument::any())->shouldBeCalledTimes(2);
     $this->addAttributeFilter($attribute, '>', '2014-03-15');
     $this->addAttributeFilter($attribute, '>', new \DateTime('2014-03-15'));
 }
 /**
  * Return categories ids provided by the categoryQb or by the provided category
  *
  * @param CategoryInterface $category
  * @param OrmQueryBuilder   $categoryQb
  *
  * @return array $categoryIds
  */
 protected function getCategoryIds(CategoryInterface $category, OrmQueryBuilder $categoryQb = null)
 {
     $categoryIds = array();
     if (null !== $categoryQb) {
         $categoryAlias = $categoryQb->getRootAlias();
         $categories = $categoryQb->select('PARTIAL ' . $categoryAlias . '.{id}')->getQuery()->getArrayResult();
     } else {
         $categories = array(array('id' => $category->getId()));
     }
     foreach ($categories as $category) {
         $categoryIds[] = $category['id'];
     }
     return $categoryIds;
 }
 /**
  * Paginate given $qb based on $request
  * accepts $options for customization for filters and sorters
  *
  * @param QueryBuilder $qb
  * @param Request $request
  * @param array $options
  */
 public function __construct(QueryBuilder $qb, Request $request, array $options = [])
 {
     extract(array_merge(self::$defaults, $options));
     $params = array_merge($request->query->all(), $request->attributes->all());
     foreach ($params as $key => $param) {
         if (substr($key, 0, 1) == '_') {
             unset($params[$key]);
         }
     }
     // only one sorter may be used, from params or default
     $params['sorters'] = isset($params['sorters']) ? $params['sorters'] : $sorters;
     // merge default filters
     $params['filters'] = array_merge($filters, isset($params['filters']) ? $params['filters'] : []);
     $paginator = clone $qb;
     $this->applyFilters($paginator, $params['filters'], $applyFilter);
     $this->applySorters($paginator, $params['sorters'], $applySorter);
     $counter = clone $paginator;
     $counter->resetDQLPart('orderBy');
     if (array_key_exists('resetGroupByForCount', $options) && $options['resetGroupByForCount']) {
         $counter->resetDQLPart('groupBy');
     }
     $counter->select($qb->expr()->countDistinct($qb->getRootAlias()));
     // again, this annoying dependency on the Request. if options are deliberately given we R-E-S-T-E-C-P them.
     if (array_key_exists('page', $options)) {
         $this->page = $options['page'];
     } else {
         $this->page = max(abs(intval(isset($params['page']) ? $params['page'] : 1)), 1);
     }
     if (array_key_exists('limit', $options)) {
         $this->limit = $options['limit'];
     } else {
         $this->limit = abs(intval(isset($params['limit']) ? $params['limit'] : $limit));
         // ensure upper bound
         $this->limit = min($this->limit, self::$maxPerPage);
     }
     $countQuery = $counter->getQuery();
     if (array_key_exists('gedmoTranslation', $options) && $options['gedmoTranslation']) {
         $countQuery->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
     }
     $this->count = intval($countQuery->getSingleScalarResult());
     // Set page to last one if query is more than total
     $this->page = max(min(intval(ceil($this->count / $this->limit)), $this->page), 1);
     $paginator->setFirstResult(($this->page - 1) * $this->limit);
     $paginator->setMaxResults($this->limit);
     $this->route = $request->attributes->get('_route');
     $this->query = $params;
     $this->pagination = $this->buildPagination($this->page, $range);
     $paginationQuery = $paginator->getQuery();
     if (array_key_exists('gedmoTranslation', $options) && $options['gedmoTranslation']) {
         $paginationQuery->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
     }
     parent::__construct($paginationQuery->getResult());
 }
 function it_adds_an_empty_filter_in_the_query($currencyManager, QueryBuilder $queryBuilder, AttributeInterface $price, Expr $expr, Comparison $comparison)
 {
     $price->getId()->willReturn(42);
     $price->getCode()->willReturn('price');
     $price->getBackendType()->willReturn('prices');
     $price->isLocalizable()->willReturn(false);
     $price->isScopable()->willReturn(false);
     $queryBuilder->expr()->willReturn(new Expr());
     $queryBuilder->getRootAlias()->willReturn('p');
     $value = ['data' => null, 'currency' => 'EUR'];
     $currencyManager->getActiveCodes()->willReturn(['EUR', 'USD']);
     $queryBuilder->leftJoin('p.values', Argument::any(), 'WITH', Argument::any())->shouldBeCalled();
     $queryBuilder->leftJoin(Argument::any(), Argument::any())->shouldBeCalled();
     $queryBuilder->expr()->willReturn($expr);
     $expr->literal('EUR')->willReturn('EUR');
     $expr->eq(Argument::any(), 'EUR')->willReturn($comparison);
     $expr->isNull(Argument::any())->willReturn('filterPprice.data IS NULL');
     $expr->isNull(Argument::any())->willReturn('filterPprice.id IS NULL');
     $expr->orX(Argument::any(), Argument::any())->shouldBeCalled();
     $queryBuilder->andWhere(null)->shouldBeCalled();
     $this->addAttributeFilter($price, 'EMPTY', $value);
 }
Example #26
0
 /**
  * Adds additional condition to the query for checking if product has available membership
  *
  * @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder object
  * @param string                     $alias        Entity alias OPTIONAL
  *
  * @return void
  */
 protected function addMembershipCondition(\Doctrine\ORM\QueryBuilder $queryBuilder, $alias = null)
 {
     if (!\XLite::isAdminZone()) {
         $alias = $alias ?: $queryBuilder->getRootAlias();
         $membership = \XLite\Core\Auth::getInstance()->getMembershipId();
         $queryBuilder->linkLeft($alias . '.memberships', 'membership');
         if ($membership) {
             $queryBuilder->andWhere('membership.membership_id = :membershipId OR membership.membership_id IS NULL')->setParameter('membershipId', \XLite\Core\Auth::getInstance()->getMembershipId());
         } else {
             $queryBuilder->andWhere('membership.membership_id IS NULL');
         }
     }
 }
Example #27
0
 /**
  * Set the query options
  *
  * @param \Doctrine\ORM\QueryBuilder $qb
  * @param array $criteria
  * @param array $orderBy
  */
 protected function setQueryBuilderOptions(\Doctrine\ORM\QueryBuilder $qb, array $criteria = null, array $orderBy = null)
 {
     if ($criteria) {
         foreach ($criteria as $key => $value) {
             $paramName = 'qo_' . $key;
             $qb->andWhere(sprintf('%s.%s = :%s', $qb->getRootAlias(), $key, $paramName));
             $qb->setParameter($paramName, $value);
         }
     }
     if ($orderBy) {
         foreach ($orderBy as $column => $direction) {
             $qb->addOrderBy(sprintf('%s.%s', $qb->getRootAlias(), $column), $direction);
         }
     }
 }
 function it_adds_a_not_equal_attribute_filter_in_the_query($attrValidatorHelper, QueryBuilder $queryBuilder, AttributeInterface $sku, Expr $expr, Expr\Comparison $comp, Expr\Literal $literal)
 {
     $attrValidatorHelper->validateLocale($sku, Argument::any())->shouldBeCalled();
     $attrValidatorHelper->validateScope($sku, Argument::any())->shouldBeCalled();
     $sku->getId()->willReturn(42);
     $sku->getCode()->willReturn('sku');
     $sku->getBackendType()->willReturn('varchar');
     $sku->isLocalizable()->willReturn(false);
     $sku->isScopable()->willReturn(false);
     $queryBuilder->expr()->willReturn($expr);
     $queryBuilder->getRootAlias()->willReturn('p');
     $expr->literal('My Sku')->willReturn($literal);
     $expr->notLike(Argument::any(), 'My Sku')->shouldBeCalled()->willReturn($comp);
     $literal->__toString()->willReturn('My Sku');
     $comp->__toString()->willReturn('filtersku.varchar NOT LIKE "My Sku"');
     $queryBuilder->innerJoin(Argument::any(), Argument::any(), 'WITH', Argument::containingString('.attribute = 42 AND filtersku.varchar NOT LIKE "My Sku"'))->shouldBeCalled();
     $this->addAttributeFilter($sku, '!=', 'My Sku', null, null, ['field' => 'sku']);
 }
Example #29
0
 /**
  * {@inheritdoc}
  */
 protected function configureQueryBuilder(QueryBuilder $queryBuilder)
 {
     $queryBuilder->select($queryBuilder->getRootAlias());
 }
 /**
  * @param array $orderBy
  * @param QueryBuilder $qb
  * @return OrderBy
  */
 protected function normalizeOrderBy(array $orderBy, QueryBuilder $qb)
 {
     $expr = new OrderBy();
     foreach ($orderBy as $field => $direction) {
         if (false === strpos($field, '.')) {
             $rootAlias = $qb->getRootAlias();
             $field = "{$rootAlias}.{$field}";
         }
         $expr->add($field, $direction);
     }
     return $expr;
 }