Neos\Flow\Persistence\Doctrine\Query::setOrderings PHP Method

setOrderings() public method

Sets the property names to order the result by. Expected like this: array( 'foo' => \Neos\Flow\Persistence\QueryInterface::ORDER_ASCENDING, 'bar' => \Neos\Flow\Persistence\QueryInterface::ORDER_DESCENDING )
public setOrderings ( array $orderings ) : Neos\Flow\Persistence\QueryInterface
$orderings array The property names to order by
return Neos\Flow\Persistence\QueryInterface
    public function setOrderings(array $orderings)
    {
        $this->orderings = $orderings;
        $this->queryBuilder->resetDQLPart('orderBy');
        foreach ($this->orderings as $propertyName => $order) {
            $this->queryBuilder->addOrderBy($this->getPropertyNameWithAlias($propertyName), $order);
        }
        return $this;
    }

Usage Example

 /**
  * Returns a query for objects of this repository
  *
  * @return Query
  * @api
  */
 public function createQuery()
 {
     $query = new Query($this->objectType);
     if ($this->defaultOrderings) {
         $query->setOrderings($this->defaultOrderings);
     }
     return $query;
 }