Example #1
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;
 }
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);
 }
 /**
  * Executes the query, applying the source, the constraint of documents being of the phpcr:class of
  * this kind of document and builds an array of retrieved documents.
  *
  * @param array $params        doesn't have any effect
  * @param mixed $hydrationMode doesn't have any effect
  *
  * @return array of documents
  *
  * @throws \Exception if $this->sortOrder is not ASC or DESC
  */
 public function execute(array $params = array(), $hydrationMode = null)
 {
     if ($this->getSortBy()) {
         switch ($this->sortOrder) {
             case 'DESC':
                 $this->qb->orderBy()->desc()->field($this->alias . '.' . $this->sortBy);
                 break;
             case 'ASC':
                 $this->qb->orderBy()->asc()->field($this->alias . '.' . $this->sortBy);
                 break;
             default:
                 throw new \Exception('Unsupported sort order direction: ' . $this->sortOrder);
         }
     }
     if ($this->root) {
         $this->qb->andWhere()->descendant($this->root, $this->alias);
     }
     return $this->qb->getQuery()->execute();
 }