4j: Update the sort order
Before returning the articles from the `getAll()` method, sort them based on their created date.
This commit is contained in:
parent
87fb45dcbb
commit
f9be233bc0
1 changed files with 11 additions and 1 deletions
|
@ -17,10 +17,20 @@ class ArticleRepository {
|
|||
}
|
||||
|
||||
public function getAll(): array {
|
||||
return $this->nodeStorage->loadByProperties([
|
||||
$articles = $this->nodeStorage->loadByProperties([
|
||||
'status' => NodeInterface::PUBLISHED,
|
||||
'type' => 'article',
|
||||
]);
|
||||
|
||||
$this->sortByCreatedDate($articles);
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
private function sortByCreatedDate(array &$articles): void {
|
||||
uasort($articles, function (NodeInterface $a, NodeInterface $b): bool {
|
||||
return $a->getCreatedTime() < $b->getCreatedTime();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue