부터: 1.0
상속: extends Doctrine\MongoDB\Query\Builder
 function it_hydrates_a_result_record(Builder $builder, Query $query, ProductInterface $product, Association $association, AssociationType $associationType, ProductInterface $associatedProduct1, ProductInterface $associatedProduct2, DocumentManager $documentManager, \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $metadata, Collection $collection, ArrayIterator $arrayIterator)
 {
     $options = ['locale_code' => 'en_US', 'scope_code' => 'print', 'current_group_id' => null, 'attributes_configuration' => [], 'association_type_id' => 1, 'current_product' => $product];
     $builder->getQuery()->willReturn($query);
     $builder->hydrate(false)->willReturn($builder);
     $associatedProduct1->getId()->willReturn('550ae6b98ead0ed7778b46bb');
     $associatedProduct2->getId()->willReturn('550ae6b98abd0ec8778b46bb');
     $product->getAssociations()->willReturn([$association]);
     $association->getAssociationType()->willReturn($associationType);
     $associationType->getId()->willReturn(1);
     $association->getProducts()->willReturn([$associatedProduct1, $associatedProduct2]);
     $queryDefinition = ['type' => 1, 'sort' => ['normalizedData.is_associated' => -1, '_id' => 1], 'limit' => 10, 'skip' => 0, 'query' => ['_id' => ['$ne' => \MongoId::__set_state(['$id' => '550ae6b98ead0ee8778b46bb'])]], 'newObj' => []];
     $query->getQuery()->willReturn($queryDefinition);
     $query->getDocumentManager()->willReturn($documentManager);
     $documentManager->getDocumentCollection(Argument::any())->willReturn($collection);
     $documentManager->getClassMetadata(Argument::any())->willReturn($metadata);
     $metadata->getFieldNames()->willReturn(['id', 'created', 'updated', 'locale', 'scope', 'values', 'indexedValues', 'indexedValuesOutdated', 'family', 'familyId', 'categories', 'categoryIds', 'enabled', 'groups', 'groupIds', 'associations', 'completenesses', 'normalizedData']);
     $pipeline = [['$match' => ['_id' => ['$ne' => \MongoId::__set_state(['$id' => '550ae6b98ead0ee8778b46bb'])]]], ['$project' => ['id' => 1, 'created' => 1, 'updated' => 1, 'locale' => 1, 'scope' => 1, 'values' => 1, 'indexedValues' => 1, 'indexedValuesOutdated' => 1, 'family' => 1, 'familyId' => 1, 'categories' => 1, 'categoryIds' => 1, 'enabled' => 1, 'groups' => 1, 'groupIds' => 1, 'associations' => 1, 'completenesses' => 1, 'normalizedData' => 1, 'is_associated' => ['$cond' => [['$or' => [['$eq' => ['$_id', \MongoId::__set_state(['$id' => '550ae6b98ead0ed7778b46bb'])]], ['$eq' => ['$_id', \MongoId::__set_state(['$id' => '550ae6b98abd0ec8778b46bb'])]]]], 1, 0]]]], ['$sort' => ['is_associated' => -1]], ['$skip' => 0], ['$limit' => 10]];
     $collection->aggregate($pipeline)->willReturn($arrayIterator);
     $fixture = ['_id' => \MongoId::__set_state(['$id' => '550ae6b98ead0ee8778b46bb']), 'normalizedData' => [], 'sku' => ['attribute' => ['code' => 'sku', 'attributeType' => 'text', 'backendType' => 'text'], 'locale' => null, 'scope' => null, 'value' => 'mysku'], 'name' => ['attribute' => ['code' => 'name', 'attributeType' => 'text', 'backendType' => 'text'], 'locale' => 'fr_FR', 'scope' => null], 'desc' => ['attribute' => ['code' => 'desc', 'attributeType' => 'text', 'backendType' => 'text'], 'locale' => 'fr_FR', 'scope' => 'print'], 'is_associated' => 1];
     $arrayIterator->toArray()->willReturn([$fixture]);
     $rows = $this->hydrate($builder, $options);
     $rows->shouldHaveCount(1);
     $firstResult = $rows[0];
     $firstResult->shouldBeAnInstanceOf('\\Oro\\Bundle\\DataGridBundle\\Datasource\\ResultRecord');
 }
 /**
  * @param Builder                $queryBuilder
  * @param ConditionNodeInterface $node
  * @return Expr
  */
 protected function computeExpression(Builder $queryBuilder, ConditionNodeInterface $node)
 {
     if (count($node->getFields()) == 0 && count($node->getChildren()) == 0) {
         return null;
     }
     $method = $node->getOperator() == ConditionNodeInterface::EXPR_AND ? 'addAnd' : 'addOr';
     $expression = $queryBuilder->expr();
     // create a new expression object
     $expressionsCount = 0;
     foreach ($node->getFields() as $condition) {
         if (null !== $condition) {
             /** @var ConditionInterface $condition */
             $expression->{$method}($condition->getExpression());
             $expressionsCount++;
         }
     }
     foreach ($node->getChildren() as $child) {
         $subExpr = $this->computeExpression($queryBuilder, $child);
         if (null !== $subExpr) {
             $expression->{$method}($subExpr);
             $expressionsCount++;
         }
     }
     return $expressionsCount > 0 ? $expression : null;
 }
 function it_creates_a_cursor(Builder $queryBuilder, Query $query, Cursor $cursor)
 {
     $queryBuilder->getQuery()->shouldBeCalled()->willReturn($query);
     $query->execute()->shouldBeCalled()->willReturn($cursor);
     $cursor = $this->createCursor($queryBuilder);
     $cursor->shouldBeAnInstanceOf('Akeneo\\Component\\StorageUtils\\Cursor\\CursorInterface');
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeSorter(AttributeInterface $attribute, $direction, $locale = null, $scope = null)
 {
     $sortField = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
     $this->qb->sort(ProductQueryUtility::NORMALIZED_FIELD . '.' . $sortField, $direction);
     $this->qb->sort('_id');
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldSorter($field, $direction, $locale = null, $scope = null)
 {
     $field = sprintf("%s.%s", ProductQueryUtility::NORMALIZED_FIELD, $field);
     $this->qb->sort($field, $direction);
     $this->qb->sort('_id');
     return $this;
 }
 function it_hydrates_a_result_record(Builder $builder, Query $query)
 {
     $options = ['locale_code' => 'en_US', 'scope_code' => 'print', 'current_group_id' => null, 'attributes_configuration' => [], 'association_type_id' => null, 'current_product' => null];
     $builder->getQuery()->willReturn($query);
     $builder->hydrate(false)->willReturn($builder);
     $query->execute()->willReturn([]);
     $this->hydrate($builder, $options);
 }
 /**
  * @param QueryBuilder $qb
  * @param Criteria $criteria
  */
 protected function buildWhereClause(Builder $qb, Criteria $criteria)
 {
     foreach ($criteria as $key => $value) {
         if ($this->metadata->hasField($key) || $this->metadata->hasAssociation($key)) {
             $qb->field($key)->equals($value);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function getProductsSkus(Builder $qb, $identifierCode)
 {
     $results = $qb->hydrate(false)->getQuery()->execute()->toArray();
     $skus = [];
     foreach ($results as $result) {
         $skus[] = $result['normalizedData'][$identifierCode];
     }
     return $skus;
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldSorter($field, $direction, $locale = null, $scope = null)
 {
     if (null === $locale || null === $scope) {
         throw new \InvalidArgumentException('Cannot prepare condition on completenesses without locale and scope');
     }
     $field = sprintf("%s.%s.%s-%s", ProductQueryUtility::NORMALIZED_FIELD, 'completenesses', $scope, $locale);
     $this->qb->sort($field, $direction);
     $this->qb->sort('_id');
     return $this;
 }
예제 #10
0
 public function addFilter(Builder &$qb, $id, $data)
 {
     switch ($data['comparator']) {
         case self::COMP_BEFORE:
             $qb->field($this->field)->lte($data['value']);
             break;
         case self::COMP_AFTER:
             $qb->field($this->field)->gte($data['value']);
             break;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value)
 {
     $field = '_id';
     $value = is_array($value) ? $value : [$value];
     if ($operator === 'NOT IN') {
         $this->qb->field($field)->notIn($value);
     } else {
         $this->qb->field($field)->in($value);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value)
 {
     $field = sprintf("%s.%s.%s-%s", ProductQueryUtility::NORMALIZED_FIELD, 'completenesses', $this->context->getScopeCode(), $this->context->getLocaleCode());
     $value = intval($value);
     if ($operator === '=') {
         $this->qb->field($field)->equals($value);
     } else {
         $this->qb->field($field)->lt($value);
     }
     return $this;
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function addFieldSorter($field, $direction, $locale = null, $scope = null)
 {
     if (null === $locale) {
         throw new \InvalidArgumentException('Cannot prepare condition on family sorter without locale');
     }
     $fieldLabel = sprintf("%s.%s.label.%s", ProductQueryUtility::NORMALIZED_FIELD, $field, $locale);
     $fieldCode = sprintf("%s.%s.code", ProductQueryUtility::NORMALIZED_FIELD, $field);
     $this->qb->sort($fieldLabel, $direction);
     $this->qb->sort($fieldCode, $direction);
     $this->qb->sort('_id');
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value)
 {
     $value = is_array($value) ? $value : [$value];
     $value = array_map('intval', $value);
     $field = 'groupIds';
     if ($operator === 'NOT IN') {
         $this->qb->field($field)->notIn($value);
     } else {
         $this->qb->field($field)->in($value);
     }
     return $this;
 }
예제 #15
0
 /**
  * Give a cursor and create it if necessary
  *
  * @return CursorMongoDB
  */
 protected function getCursor()
 {
     if (null === $this->cursor) {
         $this->cursor = $this->queryBuilder->getQuery()->execute();
         if (null !== $this->batchSize) {
             $this->cursor->batchSize($this->batchSize);
         }
         // MongoDB Cursor are not positioned on first element (whereas ArrayIterator is)
         // as long as getNext() hasn't be called
         $this->cursor->getNext();
     }
     return $this->cursor;
 }
예제 #16
0
 /**
  * @param $params
  * @param \Doctrine\ODM\MongoDB\Query\Builder $queryBuilder
  *
  * @return mixed
  */
 public function createQuery($params, $queryBuilder)
 {
     if (!empty($params['text'])) {
         $queryBuilder->text($params['text']);
     }
     $queryBuilder->field('isDraft')->equals(false);
     if (isset($params['sort'])) {
         foreach (explode(",", $params['sort']) as $sort) {
             $queryBuilder->sort($this->filterSort($sort));
         }
     }
     return $queryBuilder;
 }
예제 #17
0
 /**
  * @param Parameters $params
  * @param Builder $queryBuilder
  *
  * @return Builder
  */
 public function createQuery($params, $queryBuilder)
 {
     $this->value = $params->toArray();
     /*
      * search jobs by keywords
      */
     if (isset($this->value['params']['search']) && !empty($this->value['params']['search'])) {
         $search = strtolower($this->value['params']['search']);
         $expression = $queryBuilder->expr()->operator('$text', ['$search' => $search]);
         $queryBuilder->field(null)->equals($expression->getQuery());
     }
     if (isset($this->value['params']['status']) && !empty($this->value['params']['status'])) {
         if ($this->value['params']['status'] != 'all') {
             $queryBuilder->field('status.name')->equals($this->value['params']['status']);
         }
     } else {
         $queryBuilder->field('status.name')->equals(Status::CREATED);
     }
     if (isset($this->value['params']['companyId']) && !empty($this->value['params']['companyId'])) {
         $queryBuilder->field('organization')->equals(new \MongoId($this->value['params']['companyId']));
     }
     if (isset($this->value['sort'])) {
         foreach (explode(",", $this->value['sort']) as $sort) {
             $queryBuilder->sort($this->filterSort($sort));
         }
     }
     return $queryBuilder;
 }
예제 #18
0
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value)
 {
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     if ('EMPTY' === $operator) {
         $this->qb->field($field)->exists(false);
     } elseif ('IN' === $operator) {
         $this->qb->field($field)->in($value);
     } else {
         if (strpos($value, '/') !== false) {
             $value = new \MongoRegex($value);
         }
         $this->qb->field($field)->equals($value);
     }
     return $this;
 }
 function it_adds_a_filter_with_codes_to_the_query($attrValidatorHelper, $idResolver, Builder $qb, AttributeInterface $attribute, Expr $expr)
 {
     $attrValidatorHelper->validateLocale($attribute, Argument::any())->shouldBeCalled();
     $attrValidatorHelper->validateScope($attribute, Argument::any())->shouldBeCalled();
     $attribute->getId()->willReturn(42);
     $attribute->isLocalizable()->willReturn(false);
     $attribute->isScopable()->willReturn(false);
     $attribute->getBackendType()->willReturn('reference_data_option');
     $attribute->getCode()->willReturn('color');
     $attribute->getReferenceDataName()->willReturn('ref_data_color');
     $idResolver->resolve('ref_data_color', ['red', 'blue'])->willReturn([118, 270]);
     $qb->expr()->willReturn($expr);
     $expr->field('normalizedData.color.id')->shouldBeCalled()->willReturn($expr);
     $expr->in([118, 270])->shouldBeCalled()->willReturn($expr);
     $qb->addAnd($expr)->shouldBeCalled();
     $this->addAttributeFilter($attribute, 'IN', ['red', 'blue'], null, null, ['field' => 'color.code']);
 }
예제 #20
0
 /**
  * {@inheritdoc}
  */
 public function setParameters($parameters)
 {
     $this->parameters += $parameters;
     if ($this->qb instanceof QueryBuilder) {
         $this->qb->setParameters($this->parameters);
     }
     return $this;
 }
예제 #21
0
 public function addFilter(Builder &$qb, $id, $data)
 {
     switch ($data['comparator']) {
         case self::COMP_EQUALS:
             $qb->field($this->field)->equals($data['value']);
             break;
         case self::COMP_DOESNOTEQUAL:
             $qb->field($this->field)->notEqual($data['value']);
             break;
         case self::COMP_CONTAINS:
             $mongoregex = new \MongoRegex("/.*" . $data['value'] . ".*/i");
             $qb->field($this->field)->equals($mongoregex);
             break;
         case self::COMP_DOESNOTCONTAIN:
             $mongoregex = new \MongoRegex("/.*" . $data['value'] . ".*/i");
             $qb->field($this->field)->not($mongoregex);
             break;
         case self::COMP_STARTSWITH:
             $mongoregex = new \MongoRegex("/^" . $data['value'] . "/i");
             $qb->field($this->field)->equals($mongoregex);
             break;
         case self::COMP_ENDSWITH:
             $mongoregex = new \MongoRegex("/.*" . $data['value'] . "\$/i");
             $qb->field($this->field)->equals($mongoregex);
             break;
     }
 }
예제 #22
0
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AbstractAttribute $attribute, $operator, $value)
 {
     list($data, $currency) = explode(' ', $value);
     $data = (double) $data;
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $this->context);
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $field = sprintf('%s.%s', $field, $currency);
     $fieldData = sprintf('%s.data', $field);
     switch ($operator) {
         case '<':
             $this->qb->field($fieldData)->lt($data);
             break;
         case '<=':
             $this->qb->field($fieldData)->lte($data);
             break;
         case '>':
             $this->qb->field($fieldData)->gt($data);
             break;
         case '>=':
             $this->qb->field($fieldData)->gte($data);
             break;
         case 'EMPTY':
             $this->qb->field($fieldData)->equals(null);
             break;
         default:
             $this->qb->field($fieldData)->equals($data);
     }
     return $this;
 }
예제 #23
0
 /**
  * Returns the document class from the query
  *
  * @return string class name
  */
 private function getDocumentClassName()
 {
     // find our class name
     $documentName = $this->builder->getQuery()->getClass()->getName();
     if (!class_exists($documentName)) {
         throw new \LogicException('Could not determine class name from RQL query.');
     }
     return $documentName;
 }
예제 #24
0
 public function testCreateDataSourceWithAllOption()
 {
     $this->queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($query = $this->createQueryMock()));
     $query->expects($this->once())->method('getIterator')->will($this->returnValue($iterator = $this->createIteratorMock()));
     $iterator->expects($this->once())->method('toArray')->will($this->returnValue($values = [new \stdClass()]));
     $dataSource = $this->builder->createDataSource(['all' => true]);
     $this->assertInstanceOf(ArrayDataSource::class, $dataSource);
     $this->assertSame($values, iterator_to_array($dataSource));
 }
예제 #25
0
 public function testNotBetween()
 {
     $this->queryBuilder->expects($this->exactly(3))->method('expr')->willReturnOnConsecutiveCalls($gteExpr = $this->createExprMock(), $lteExpr = $this->createExprMock(), $expr = $this->createExprMock());
     $gteExpr->expects($this->once())->method('field')->with($this->identicalTo($value = 'property'))->will($this->returnSelf());
     $gteExpr->expects($this->once())->method('lt')->with($this->identicalTo($x = 'from'))->will($this->returnSelf());
     $lteExpr->expects($this->once())->method('field')->with($this->identicalTo($value))->will($this->returnSelf());
     $lteExpr->expects($this->once())->method('gt')->with($this->identicalTo($y = 'to'))->will($this->returnSelf());
     $expr->expects($this->exactly(2))->method('addOr')->withConsecutive([$gteExpr], [$lteExpr]);
     $this->assertSame($expr, $this->expressionBuilder->notBetween($value, $x, $y));
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value)
 {
     $value = is_array($value) ? $value : [$value];
     if ($operator === 'NOT IN') {
         $this->qb->field($field)->notIn($value);
     } else {
         if (in_array('empty', $value)) {
             unset($value[array_search('empty', $value)]);
             $expr = new Expr();
             $expr = $expr->field($field)->exists(false);
             $this->qb->addOr($expr);
         }
         if (count($value) > 0) {
             $expr = new Expr();
             $expr->field($field)->in($value);
             $this->qb->addOr($expr);
         }
     }
     return $this;
 }
 /**
  * Converts a composite expression into the target query language output.
  *
  * @see ExpressionVisitor::walkCompositeExpression()
  * @param CompositeExpression $expr
  * @return \Doctrine\ODM\MongoDB\Query\Expr
  */
 public function walkCompositeExpression(CompositeExpression $compositeExpr)
 {
     if (!isset(self::$compositeMethods[$compositeExpr->getType()])) {
         throw new \RuntimeException('Unknown composite ' . $compositeExpr->getType());
     }
     $method = self::$compositeMethods[$compositeExpr->getType()];
     $expr = $this->builder->expr();
     foreach ($compositeExpr->getExpressionList() as $child) {
         $expr->{$method}($this->dispatch($child));
     }
     return $expr;
 }
예제 #28
0
 /**
  * Creates a query for filtering organizations
  *
  * @see \Core\Repository\Filter\AbstractPaginationQuery::createQuery()
  * @param $params
  * @param \Doctrine\ODM\MongoDB\Query\Builder $queryBuilder
  * @return mixed
  */
 public function createQuery($params, $queryBuilder)
 {
     $userID = $this->auth->getUser()->getId();
     if ($params instanceof Parameters) {
         $value = $params->toArray();
     } else {
         $value = $params;
     }
     if (isset($params['text']) && $params['text']) {
         $queryBuilder->text($params['text']);
     }
     /*
      * We only show organizations to which the user has view permissions.
      */
     $queryBuilder->field('permissions.view')->equals($userID);
     if (!isset($value['sort'])) {
         $value['sort'] = '-date';
     }
     $queryBuilder->sort($this->filterSort($value['sort']));
     return $queryBuilder;
 }
예제 #29
0
 /**
  * @param   array $params
  * @param   QueryBuilder $queryBuilder
  * @return  mixed
  */
 public function createQuery($params, $queryBuilder)
 {
     if (isset($params['search']) && !empty($params['search'])) {
         $search = strtolower($params['search']);
         $expr = $queryBuilder->expr()->operator('$text', ['$search' => $search]);
         $queryBuilder->field(null)->equals($expr->getQuery());
     }
     if (isset($params['location']) && isset($params['location']->coordinates)) {
         $coordinates = $params['location']->coordinates->getCoordinates();
         $queryBuilder->field('preferredJob.desiredLocations.coordinates')->geoWithinCenter($coordinates[0], $coordinates[1], (double) $params['d'] / 100);
     }
     $queryBuilder->addOr($queryBuilder->expr()->field('permissions.view')->equals($this->user->getId()))->addOr($queryBuilder->expr()->field('status.name')->equals(Status::PUBLIC_TO_ALL));
     //$q = $queryBuilder->getQuery()->debug();
     return $queryBuilder;
 }
예제 #30
0
 /**
  * @param DocumentManager                      $dm
  * @param string                               $documentName
  * @param SpecificationVisitorFactoryInterface $specificationVisitorFactory
  * @param ComparatorVisitorFactoryInterface    $comparatorVisitorFactory
  */
 public function __construct(DocumentManager $dm, $documentName = null, SpecificationVisitorFactoryInterface $specificationVisitorFactory = null, ComparatorVisitorFactoryInterface $comparatorVisitorFactory = null)
 {
     parent::__construct($dm, $documentName);
     if ($specificationVisitorFactory === null) {
         $specificationVisitorFactory = new SpecificationVisitorFactory();
     }
     if ($comparatorVisitorFactory === null) {
         $comparatorVisitorFactory = new ComparatorVisitorFactory();
     }
     $this->specificationVisitorFactory = $specificationVisitorFactory;
     $this->comparatorVisitorFactory = $comparatorVisitorFactory;
     $this->factory = Delegate::fromClosure(function () use($dm, $documentName) {
         return new static($dm, $documentName);
     });
 }