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:
Oliver Davies 2020-03-19 21:42:28 +00:00
parent 87fb45dcbb
commit f9be233bc0

View file

@ -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();
});
}
}