Order comments by timestamp in admin

This commit is contained in:
Flavio Copes 2015-10-16 14:59:22 +02:00
parent 9c3d9860b9
commit 7d7dbd1644
1 changed files with 5 additions and 4 deletions

View File

@ -245,21 +245,22 @@ class CommentsPlugin extends Plugin
$files = []; $files = [];
$files = $this->getFilesOrderedByModifiedDate(); $files = $this->getFilesOrderedByModifiedDate();
$comments = []; $comments = [];
foreach($files as $file) { foreach($files as $file) {
$data = Yaml::parse(file_get_contents($file->filePath)); $data = Yaml::parse(file_get_contents($file->filePath));
for ($i = 0; $i < count($data['comments']); $i++) { for ($i = 0; $i < count($data['comments']); $i++) {
$commentDate = \DateTime::createFromFormat('D, d M Y H:i:s', $data['comments'][$i]['date'])->getTimestamp(); $commentTimestamp = \DateTime::createFromFormat('D, d M Y H:i:s', $data['comments'][$i]['date'])->getTimestamp();
$sevenDaysAgo = time() - (7 * 24 * 60 * 60); $sevenDaysAgo = time() - (7 * 24 * 60 * 60);
if ($commentDate < $sevenDaysAgo) { if ($commentTimestamp < $sevenDaysAgo) {
continue; continue;
} }
$data['comments'][$i]['pageTitle'] = $data['title']; $data['comments'][$i]['pageTitle'] = $data['title'];
$data['comments'][$i]['filePath'] = $file->filePath; $data['comments'][$i]['filePath'] = $file->filePath;
$data['comments'][$i]['timestamp'] = $commentTimestamp;
} }
if (count($data['comments'])) { if (count($data['comments'])) {
$comments = array_merge($comments, $data['comments']); $comments = array_merge($comments, $data['comments']);
@ -268,7 +269,7 @@ class CommentsPlugin extends Plugin
// Order comments by date // Order comments by date
usort($comments, function($a, $b) { usort($comments, function($a, $b) {
return !($a['date'] > $b['date']); return !($a['timestamp'] > $b['timestamp']);
}); });
$totalAvailable = count($comments); $totalAvailable = count($comments);