| @@ 16-39 (lines=24) @@ | ||
| 13 | /** |
|
| 14 | * Class Collection. |
|
| 15 | */ |
|
| 16 | class Collection extends CecilCollection |
|
| 17 | { |
|
| 18 | /** |
|
| 19 | * Sort items by date. |
|
| 20 | * |
|
| 21 | * @return self |
|
| 22 | */ |
|
| 23 | public function sortByDate(): self |
|
| 24 | { |
|
| 25 | return $this->usort(function ($a, $b) { |
|
| 26 | if (!isset($a['date'])) { |
|
| 27 | return -1; |
|
| 28 | } |
|
| 29 | if (!isset($b['date'])) { |
|
| 30 | return 1; |
|
| 31 | } |
|
| 32 | if ($a['date'] == $b['date']) { |
|
| 33 | return 0; |
|
| 34 | } |
|
| 35 | ||
| 36 | return ($a['date'] > $b['date']) ? -1 : 1; |
|
| 37 | }); |
|
| 38 | } |
|
| 39 | } |
|
| 40 | ||
| @@ 17-40 (lines=24) @@ | ||
| 14 | /** |
|
| 15 | * Class Term. |
|
| 16 | */ |
|
| 17 | class Term extends CecilCollection implements ItemInterface |
|
| 18 | { |
|
| 19 | /** |
|
| 20 | * Sort items by date. |
|
| 21 | * |
|
| 22 | * @return self |
|
| 23 | */ |
|
| 24 | public function sortByDate(): self |
|
| 25 | { |
|
| 26 | return $this->usort(function ($a, $b) { |
|
| 27 | if (!isset($a['date'])) { |
|
| 28 | return -1; |
|
| 29 | } |
|
| 30 | if (!isset($b['date'])) { |
|
| 31 | return 1; |
|
| 32 | } |
|
| 33 | if ($a['date'] == $b['date']) { |
|
| 34 | return 0; |
|
| 35 | } |
|
| 36 | ||
| 37 | return ($a['date'] > $b['date']) ? -1 : 1; |
|
| 38 | }); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||