Skip to content

Commit

Permalink
Order comments by timestamp in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviocopes committed Oct 16, 2015
1 parent 9c3d986 commit 7d7dbd1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,22 @@ private function getLastComments($page = 0) {

$files = [];
$files = $this->getFilesOrderedByModifiedDate();

$comments = [];

foreach($files as $file) {
$data = Yaml::parse(file_get_contents($file->filePath));

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);

if ($commentDate < $sevenDaysAgo) {
if ($commentTimestamp < $sevenDaysAgo) {
continue;
}

$data['comments'][$i]['pageTitle'] = $data['title'];
$data['comments'][$i]['filePath'] = $file->filePath;
$data['comments'][$i]['timestamp'] = $commentTimestamp;
}
if (count($data['comments'])) {
$comments = array_merge($comments, $data['comments']);
Expand All @@ -268,7 +269,7 @@ private function getLastComments($page = 0) {

// Order comments by date
usort($comments, function($a, $b) {
return !($a['date'] > $b['date']);
return !($a['timestamp'] > $b['timestamp']);
});

$totalAvailable = count($comments);
Expand Down

0 comments on commit 7d7dbd1

Please sign in to comment.