Inheritance: extends Nette\Object
 /**
  * Sort data
  * @param Sorting $sorting
  * @return static
  */
 public function sort(Sorting $sorting)
 {
     if (is_callable($sorting->getSortCallback())) {
         call_user_func($sorting->getSortCallback(), $this->criteria, $sorting->getSort());
         return $this;
     }
     if ($sort = $sorting->getSort()) {
         $this->criteria->orderBy($sort);
         return $this;
     }
     $this->criteria->orderBy([$this->primary_key => 'ASC']);
     return $this;
 }
 /**
  * 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;
 }
 /**
  * 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)) {
         $this->data_source->removeClause('ORDER BY');
         $this->data_source->orderBy($sort);
     } else {
         /**
          * Has the statement already a order by clause?
          */
         $this->data_source->clause('ORDER BY');
         $reflection = new \ReflectionClass('DibiFluent');
         $cursor_property = $reflection->getProperty('cursor');
         $cursor_property->setAccessible(TRUE);
         $cursor = $cursor_property->getValue($this->data_source);
         if (!$cursor) {
             $this->data_source->orderBy($this->primary_key);
         }
     }
     return $this;
 }
 /**
  * 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)) {
         $this->data_source->getSqlBuilder()->setOrder([], []);
         foreach ($sort as $column => $order) {
             $this->data_source->order("{$column} {$order}");
         }
     } else {
         /**
          * Has the statement already a order by clause?
          */
         if (!$this->data_source->getSqlBuilder()->getOrder()) {
             $this->data_source->order($this->primary_key);
         }
     }
     return $this;
 }
Exemple #5
0
 public function sort(\Ublaboo\DataGrid\Utils\Sorting $sorting)
 {
     if (is_callable($sorting->getSortCallback())) {
         $this->result = call_user_func($sorting->getSortCallback(), $this->result, $sorting->getSort());
         if (!is_array($this->result)) {
             throw new DataGridArrayDataSourceException(_('Sorting callback has to return array'));
         }
         return $this;
     }
     $sort = $sorting->getSort();
     foreach ($sort as $column => $order) {
         $data = [];
         foreach ($this->result as $item) {
             $sort_by = (string) $item[$column];
             $data[$sort_by][] = $item;
         }
         if ($order === 'ASC') {
             ksort($data);
         } else {
             krsort($data);
         }
         $this->result = [];
         foreach ($data as $i) {
             foreach ($i as $item) {
                 $this->result[] = $item;
             }
         }
     }
     return $this;
 }
Exemple #6
0
 /**
  * Sort data
  * @param  Sorting $sorting
  * @return static
  */
 public function sort(Sorting $sorting)
 {
     if (is_callable($sorting->getSortCallback())) {
         $this->data = call_user_func($sorting->getSortCallback(), $this->data, $sorting->getSort());
         if (!is_array($this->data)) {
             throw new DataGridArrayDataSourceException('Sorting callback has to return array');
         }
         return $this;
     }
     $sort = $sorting->getSort();
     foreach ($sort as $column => $order) {
         $data = [];
         foreach ($this->data as $item) {
             if (is_object($item[$column]) && $item[$column] instanceof \DateTime) {
                 $sort_by = $item[$column]->format('Y-m-d H:i:s');
             } else {
                 $sort_by = (string) $item[$column];
             }
             $data[$sort_by][] = $item;
         }
         if ($order === 'ASC') {
             ksort($data);
         } else {
             krsort($data);
         }
         $this->data = [];
         foreach ($data as $i) {
             foreach ($i as $item) {
                 $this->data[] = $item;
             }
         }
     }
     return $this;
 }
 /**
  * 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->addOrderBy($this->checkAliases($column), $order);
         }
     } else {
         /**
          * Has the statement already a order by clause?
          */
         if (!$this->data_source->getDQLPart('orderBy')) {
             $this->data_source->orderBy($this->checkAliases($this->primary_key));
         }
     }
     return $this;
 }
 /**
  * Sort data
  *
  * @param  Sorting $sorting
  *
  * @return static
  */
 public function sort(Sorting $sorting)
 {
     if (is_callable($sorting->getSortCallback())) {
         call_user_func($sorting->getSortCallback(), $this->repository, $sorting->getSort());
         return $this;
     }
     $sort = $sorting->getSort();
     if (!empty($sort)) {
         $this->order = [];
         foreach ($sort as $column => $order) {
             $this->order[$column] = $order;
         }
     }
     return $this;
 }
 /**
  * Sort data
  * @param  Sorting $sorting
  * @return static
  */
 public function sort(Sorting $sorting)
 {
     if (is_callable($sorting->getSortCallback())) {
         call_user_func($sorting->getSortCallback(), $this->sql, $sorting->getSort());
         return $this;
     }
     $sort = $sorting->getSort();
     if (!empty($sort)) {
         foreach ($sort as $column => $order) {
             $this->sql = $this->queryHelper->orderBy($column, $order);
         }
     }
     return $this;
 }
Exemple #10
0
 /**
  * Sort data
  * @param Sorting $sorting
  * @return static
  */
 public function sort(Sorting $sorting)
 {
     /**
      * there is only one iteration
      */
     foreach ($sorting->getSort() as $column => $order) {
         $this->sort_column = $column;
         $this->order_column = $order;
     }
     return $this;
 }