/** * Order data * @param array $sorting * @return self */ public function sort(array $sorting) { if ($sorting) { $this->data_source->getSqlBuilder()->setOrder([], []); foreach ($sorting as $column => $sort) { $this->data_source->order("{$column} {$sort}"); } } else { /** * Has the statement already a order by clause? */ if (!$this->data_source->getSqlBuilder()->getOrder()) { $this->data_source->order($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; }