Nextras\Orm\Mapper\Dbal\DbalCollection::orderBy PHP Method

orderBy() public method

public orderBy ( $column, $direction = ICollection::ASC )
    public function orderBy($column, $direction = ICollection::ASC)
    {
        $collection = clone $this;
        $parser = $collection->getParser();
        if (is_array($column)) {
            foreach ($column as $col => $direction) {
                $parser->processOrderByExpression($col, $direction, $collection->queryBuilder);
            }
        } else {
            $parser->processOrderByExpression($column, $direction, $collection->queryBuilder);
        }
        return $collection;
    }

Usage Example

示例#1
0
 /**
  * Sort data
  * @param  Sorting $sorting
  * @return static
  */
 public function sort(Sorting $sorting)
 {
     if (is_callable($sorting->getSortCallback())) {
         call_user_func($sorting->getSortCallback(), $this->data_source, $sorting->getSort());
         return $this;
     }
     $sort = $sorting->getSort();
     if (!empty($sort)) {
         foreach ($sort as $column => $order) {
             $this->data_source = $this->data_source->orderBy($column, $order);
         }
     } else {
         /**
          * Has the statement already a order by clause?
          */
         $order = $this->data_source->getQueryBuilder()->getClause('order');
         if (ArraysHelper::testEmpty($order)) {
             $this->data_source = $this->data_source->orderBy($this->primary_key);
         }
     }
     return $this;
 }