Use a method for sorting articles

Fixes #13
This commit is contained in:
Oliver Davies 2020-03-19 23:23:41 +00:00
parent a1529f22d7
commit a13636a2f2

View file

@ -904,12 +904,15 @@ To order the articles by their created date, we can update the `getAll()` method
'type' => 'article', 'type' => 'article',
]); ]);
+ +
+ // Sort the articles by their created date. + $this->sortByCreatedDate($articles);
+
+ return $articles;
+ }
+
+ private function sortByCreatedDate(array &$articles): void {
+ uasort($articles, function (NodeInterface $a, NodeInterface $b): bool { + uasort($articles, function (NodeInterface $a, NodeInterface $b): bool {
+ return $a->getCreatedTime() < $b->getCreatedTime(); + return $a->getCreatedTime() < $b->getCreatedTime();
+ }); + });
+
+ return $articles;
} }
``` ```