| @@ 269-299 (lines=31) @@ | ||
| 266 | * @param Sorting $sorting |
|
| 267 | * @return static |
|
| 268 | */ |
|
| 269 | public function sort(Sorting $sorting) |
|
| 270 | { |
|
| 271 | if (is_callable($sorting->getSortCallback())) { |
|
| 272 | call_user_func( |
|
| 273 | $sorting->getSortCallback(), |
|
| 274 | $this->data_source, |
|
| 275 | $sorting->getSort() |
|
| 276 | ); |
|
| 277 | ||
| 278 | return $this; |
|
| 279 | } |
|
| 280 | ||
| 281 | $sort = $sorting->getSort(); |
|
| 282 | ||
| 283 | if (!empty($sort)) { |
|
| 284 | $this->data_source->getSqlBuilder()->setOrder([], []); |
|
| 285 | ||
| 286 | foreach ($sort as $column => $order) { |
|
| 287 | $this->data_source->order("$column $order"); |
|
| 288 | } |
|
| 289 | } else { |
|
| 290 | /** |
|
| 291 | * Has the statement already a order by clause? |
|
| 292 | */ |
|
| 293 | if (!$this->data_source->getSqlBuilder()->getOrder()) { |
|
| 294 | $this->data_source->order($this->primary_key); |
|
| 295 | } |
|
| 296 | } |
|
| 297 | ||
| 298 | return $this; |
|
| 299 | } |
|
| 300 | ||
| 301 | } |
|
| 302 | ||
| @@ 307-335 (lines=29) @@ | ||
| 304 | * @param Sorting $sorting |
|
| 305 | * @return static |
|
| 306 | */ |
|
| 307 | public function sort(Sorting $sorting) |
|
| 308 | { |
|
| 309 | if (is_callable($sorting->getSortCallback())) { |
|
| 310 | call_user_func( |
|
| 311 | $sorting->getSortCallback(), |
|
| 312 | $this->data_source, |
|
| 313 | $sorting->getSort() |
|
| 314 | ); |
|
| 315 | ||
| 316 | return $this; |
|
| 317 | } |
|
| 318 | ||
| 319 | $sort = $sorting->getSort(); |
|
| 320 | ||
| 321 | if (!empty($sort)) { |
|
| 322 | foreach ($sort as $column => $order) { |
|
| 323 | $this->data_source->addOrderBy($this->checkAliases($column), $order); |
|
| 324 | } |
|
| 325 | } else { |
|
| 326 | /** |
|
| 327 | * Has the statement already a order by clause? |
|
| 328 | */ |
|
| 329 | if (!$this->data_source->getDQLPart('orderBy')) { |
|
| 330 | $this->data_source->orderBy($this->checkAliases($this->primary_key)); |
|
| 331 | } |
|
| 332 | } |
|
| 333 | ||
| 334 | return $this; |
|
| 335 | } |
|
| 336 | ||
| 337 | ||
| 338 | /** |
|