| @@ 324-352 (lines=29) @@ | ||
| 321 | * @param Sorting $sorting |
|
| 322 | * @return static |
|
| 323 | */ |
|
| 324 | public function sort(Sorting $sorting) |
|
| 325 | { |
|
| 326 | if (is_callable($sorting->getSortCallback())) { |
|
| 327 | call_user_func( |
|
| 328 | $sorting->getSortCallback(), |
|
| 329 | $this->data_source, |
|
| 330 | $sorting->getSort() |
|
| 331 | ); |
|
| 332 | ||
| 333 | return $this; |
|
| 334 | } |
|
| 335 | ||
| 336 | $sort = $sorting->getSort(); |
|
| 337 | ||
| 338 | if (!empty($sort)) { |
|
| 339 | foreach ($sort as $column => $order) { |
|
| 340 | $this->data_source->addOrderBy($this->checkAliases($column), $order); |
|
| 341 | } |
|
| 342 | } else { |
|
| 343 | /** |
|
| 344 | * Has the statement already a order by clause? |
|
| 345 | */ |
|
| 346 | if (!$this->data_source->getDQLPart('orderBy')) { |
|
| 347 | $this->data_source->orderBy($this->checkAliases($this->primary_key)); |
|
| 348 | } |
|
| 349 | } |
|
| 350 | ||
| 351 | return $this; |
|
| 352 | } |
|
| 353 | ||
| 354 | ||
| 355 | /** |
|
| @@ 289-319 (lines=31) @@ | ||
| 286 | * @param Sorting $sorting |
|
| 287 | * @return static |
|
| 288 | */ |
|
| 289 | public function sort(Sorting $sorting) |
|
| 290 | { |
|
| 291 | if (is_callable($sorting->getSortCallback())) { |
|
| 292 | call_user_func( |
|
| 293 | $sorting->getSortCallback(), |
|
| 294 | $this->data_source, |
|
| 295 | $sorting->getSort() |
|
| 296 | ); |
|
| 297 | ||
| 298 | return $this; |
|
| 299 | } |
|
| 300 | ||
| 301 | $sort = $sorting->getSort(); |
|
| 302 | ||
| 303 | if (!empty($sort)) { |
|
| 304 | $this->data_source->getSqlBuilder()->setOrder([], []); |
|
| 305 | ||
| 306 | foreach ($sort as $column => $order) { |
|
| 307 | $this->data_source->order("$column $order"); |
|
| 308 | } |
|
| 309 | } else { |
|
| 310 | /** |
|
| 311 | * Has the statement already a order by clause? |
|
| 312 | */ |
|
| 313 | if (!$this->data_source->getSqlBuilder()->getOrder()) { |
|
| 314 | $this->data_source->order($this->primary_key); |
|
| 315 | } |
|
| 316 | } |
|
| 317 | ||
| 318 | return $this; |
|
| 319 | } |
|
| 320 | ||
| 321 | ||
| 322 | /** |
|