public function testExecute()
 {
     $this->qb->expects($this->once())->method('getQuery')->will($this->returnValue($this->query));
     $this->query->expects($this->once())->method('execute')->will($this->returnValue('test'));
     $res = $this->pq->execute();
     $this->assertEquals('test', $res);
 }
Example #2
0
 /**
  * @param QueryBuilder $queryBuilder
  * @param array        $sorting
  */
 protected function applySorting(QueryBuilder $queryBuilder, array $sorting = array())
 {
     foreach ($sorting as $property => $order) {
         if (!empty($order)) {
             $queryBuilder->orderBy()->{$order}()->field('o.' . $property);
         }
     }
     $queryBuilder->end();
 }
Example #3
0
 function it_should_set_the_order_on_the_query_builder_as_fields_only(QueryBuilder $queryBuilder, ExpressionBuilder $expressionBuilder, OrderBy $orderBy, Ordering $ordering)
 {
     $expressionBuilder->getOrderBys()->willReturn(['foo', 'bar']);
     $queryBuilder->orderBy()->willReturn($orderBy);
     $orderBy->asc()->willReturn($ordering);
     $orderBy->asc()->willReturn($ordering);
     $ordering->field('o.foo')->shouldBeCalled();
     $ordering->field('o.bar')->shouldBeCalled();
     $this->getData(new Parameters(['page' => 1]))->shouldHaveType(Pagerfanta::class);
 }
 /**
  * {@inheritDoc}
  *
  * @param QueryBuilder $queryBuilder
  */
 public function restrictQuery($queryBuilder)
 {
     $prefixes = $this->getPrefixes();
     if (in_array('', $prefixes) || !count($prefixes)) {
         return;
     }
     $where = $queryBuilder->andWhere()->orX();
     foreach ($prefixes as $prefix) {
         $where->descendant($prefix, $queryBuilder->getPrimaryAlias());
     }
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function getData(Parameters $parameters)
 {
     $orderBy = $this->queryBuilder->orderBy();
     foreach ($this->expressionBuilder->getOrderBys() as $field => $direction) {
         if (is_int($field)) {
             $field = $direction;
             $direction = 'asc';
         }
         // todo: validate direction?
         $direction = strtolower($direction);
         $orderBy->{$direction}()->field(sprintf('%s.%s', Driver::QB_SOURCE_ALIAS, $field));
     }
     $paginator = new Pagerfanta(new DoctrineODMPhpcrAdapter($this->queryBuilder));
     $paginator->setCurrentPage($parameters->get('page', 1));
     return $paginator;
 }
 /**
  * Evaluate the query and clean the result.
  *
  * @param QueryBuilder $qb
  *
  * @return array list of result documents
  */
 private function getResult(QueryBuilder $qb)
 {
     return array_values($qb->getQuery()->execute()->toArray());
 }
Example #7
0
 /**
  * {@inheritDoc}
  */
 public function getQuery(QueryBuilder $builder)
 {
     $this->aliasWithTranslatedFields = array();
     $this->locale = $builder->getLocale();
     if (null === $this->locale && $this->dm->hasLocaleChooserStrategy()) {
         $this->locale = $this->dm->getLocaleChooserStrategy()->getLocale();
     }
     $from = $builder->getChildrenOfType(QBConstants::NT_FROM);
     if (!$from) {
         throw new RuntimeException('No From (source) node in query');
     }
     $dispatches = array(QBConstants::NT_FROM, QBConstants::NT_SELECT, QBConstants::NT_WHERE, QBConstants::NT_ORDER_BY);
     foreach ($dispatches as $dispatchType) {
         $this->dispatchMany($builder->getChildrenOfType($dispatchType));
     }
     if (count($this->sourceDocumentNodes) > 1 && null === $builder->getPrimaryAlias()) {
         throw new InvalidArgumentException('You must specify a primary alias when selecting from multiple document sources' . 'e.g. $qb->from(\'a\') ...');
     }
     // for each document source add phpcr:{class,classparents} restrictions
     foreach ($this->sourceDocumentNodes as $sourceNode) {
         $documentFqn = $this->aliasMetadata[$sourceNode->getAlias()]->getName();
         $odmClassConstraints = $this->qomf->orConstraint($this->qomf->comparison($this->qomf->propertyValue($sourceNode->getAlias(), 'phpcr:class'), QOMConstants::JCR_OPERATOR_EQUAL_TO, $this->qomf->literal($documentFqn)), $this->qomf->comparison($this->qomf->propertyValue($sourceNode->getAlias(), 'phpcr:classparents'), QOMConstants::JCR_OPERATOR_EQUAL_TO, $this->qomf->literal($documentFqn)));
         if ($this->constraint) {
             $this->constraint = $this->qomf->andConstraint($this->constraint, $odmClassConstraints);
         } else {
             $this->constraint = $odmClassConstraints;
         }
     }
     foreach (array_keys($this->aliasWithTranslatedFields) as $alias) {
         $this->translator[$alias]->alterQueryForTranslation($this->qomf, $this->from, $this->constraint, $alias, $this->locale);
     }
     $phpcrQuery = $this->qomf->createQuery($this->from, $this->constraint, $this->orderings, $this->columns);
     $query = new Query($phpcrQuery, $this->dm, $builder->getPrimaryAlias());
     if ($firstResult = $builder->getFirstResult()) {
         $query->setFirstResult($firstResult);
     }
     if ($maxResults = $builder->getMaxResults()) {
         $query->setMaxResults($maxResults);
     }
     return $query;
 }
Example #8
0
 /**
  * {@inheritDoc}
  */
 public function createQueryBuilder()
 {
     $qm = $this->session->getWorkspace()->getQueryManager();
     $qomf = $qm->getQOMFactory();
     $converter = new ConverterPhpcr($this, $qomf);
     $builder = new QueryBuilder();
     $builder->setConverter($converter);
     return $builder;
 }
 /**
  * Gets the maximum number of results to retrieve.
  *
  * @return int
  */
 public function getMaxResults()
 {
     return $this->qb->getMaxResults();
 }