| @@ 274-304 (lines=31) @@ | ||
| 271 | * @param Sorting $sorting |
|
| 272 | * @return static |
|
| 273 | */ |
|
| 274 | public function sort(Sorting $sorting) |
|
| 275 | { |
|
| 276 | if (is_callable($sorting->getSortCallback())) { |
|
| 277 | call_user_func( |
|
| 278 | $sorting->getSortCallback(), |
|
| 279 | $this->data_source, |
|
| 280 | $sorting->getSort() |
|
| 281 | ); |
|
| 282 | ||
| 283 | return $this; |
|
| 284 | } |
|
| 285 | ||
| 286 | $sort = $sorting->getSort(); |
|
| 287 | ||
| 288 | if (!empty($sort)) { |
|
| 289 | $this->data_source->getSqlBuilder()->setOrder([], []); |
|
| 290 | ||
| 291 | foreach ($sort as $column => $order) { |
|
| 292 | $this->data_source->order("$column $order"); |
|
| 293 | } |
|
| 294 | } else { |
|
| 295 | /** |
|
| 296 | * Has the statement already a order by clause? |
|
| 297 | */ |
|
| 298 | if (!$this->data_source->getSqlBuilder()->getOrder()) { |
|
| 299 | $this->data_source->order($this->primary_key); |
|
| 300 | } |
|
| 301 | } |
|
| 302 | ||
| 303 | return $this; |
|
| 304 | } |
|
| 305 | ||
| 306 | ||
| 307 | /** |
|
| @@ 350-378 (lines=29) @@ | ||
| 347 | * @param Sorting $sorting |
|
| 348 | * @return static |
|
| 349 | */ |
|
| 350 | public function sort(Sorting $sorting) |
|
| 351 | { |
|
| 352 | if (is_callable($sorting->getSortCallback())) { |
|
| 353 | call_user_func( |
|
| 354 | $sorting->getSortCallback(), |
|
| 355 | $this->data_source, |
|
| 356 | $sorting->getSort() |
|
| 357 | ); |
|
| 358 | ||
| 359 | return $this; |
|
| 360 | } |
|
| 361 | ||
| 362 | $sort = $sorting->getSort(); |
|
| 363 | ||
| 364 | if (!empty($sort)) { |
|
| 365 | foreach ($sort as $column => $order) { |
|
| 366 | $this->data_source->addOrderBy($this->checkAliases($column), $order); |
|
| 367 | } |
|
| 368 | } else { |
|
| 369 | /** |
|
| 370 | * Has the statement already a order by clause? |
|
| 371 | */ |
|
| 372 | if (!$this->data_source->getDQLPart('orderBy')) { |
|
| 373 | $this->data_source->orderBy($this->checkAliases($this->primary_key)); |
|
| 374 | } |
|
| 375 | } |
|
| 376 | ||
| 377 | return $this; |
|
| 378 | } |
|
| 379 | ||
| 380 | ||
| 381 | /** |
|