Skip to content

Commit 7d7dbd1

Browse files
committed
Order comments by timestamp in admin
1 parent 9c3d986 commit 7d7dbd1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

comments.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,22 @@ private function getLastComments($page = 0) {
245245

246246
$files = [];
247247
$files = $this->getFilesOrderedByModifiedDate();
248-
249248
$comments = [];
250249

251250
foreach($files as $file) {
252251
$data = Yaml::parse(file_get_contents($file->filePath));
252+
253253
for ($i = 0; $i < count($data['comments']); $i++) {
254-
$commentDate = \DateTime::createFromFormat('D, d M Y H:i:s', $data['comments'][$i]['date'])->getTimestamp();
254+
$commentTimestamp = \DateTime::createFromFormat('D, d M Y H:i:s', $data['comments'][$i]['date'])->getTimestamp();
255255
$sevenDaysAgo = time() - (7 * 24 * 60 * 60);
256256

257-
if ($commentDate < $sevenDaysAgo) {
257+
if ($commentTimestamp < $sevenDaysAgo) {
258258
continue;
259259
}
260260

261261
$data['comments'][$i]['pageTitle'] = $data['title'];
262262
$data['comments'][$i]['filePath'] = $file->filePath;
263+
$data['comments'][$i]['timestamp'] = $commentTimestamp;
263264
}
264265
if (count($data['comments'])) {
265266
$comments = array_merge($comments, $data['comments']);
@@ -268,7 +269,7 @@ private function getLastComments($page = 0) {
268269

269270
// Order comments by date
270271
usort($comments, function($a, $b) {
271-
return !($a['date'] > $b['date']);
272+
return !($a['timestamp'] > $b['timestamp']);
272273
});
273274

274275
$totalAvailable = count($comments);

0 commit comments

Comments
 (0)