4k: Sort articles before returning
This commit is contained in:
parent
91f7d094e7
commit
290c8fbcba
1 changed files with 11 additions and 1 deletions
|
@ -14,10 +14,20 @@ class ArticleRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAll(): array {
|
public function getAll(): array {
|
||||||
return $this->nodeStorage->loadByProperties([
|
$articles = $this->nodeStorage->loadByProperties([
|
||||||
'status' => NodeInterface::PUBLISHED,
|
'status' => NodeInterface::PUBLISHED,
|
||||||
'type' => 'article',
|
'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