From 77df5b724d0fca245a281d25c98b3bab606d41e2 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Tue, 12 Mar 2013 17:04:53 +0800 Subject: [PATCH] MDL-36872 reports: Fixing incorrect sorting of recent activites by timestamp --- course/recent.php | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/course/recent.php b/course/recent.php index 8b31e29835f..3783d31756b 100644 --- a/course/recent.php +++ b/course/recent.php @@ -280,21 +280,37 @@ echo $OUTPUT->footer(); function compare_activities_by_time_desc($a, $b) { // make sure the activities actually have a timestamp property - if ((!array_key_exists('timestamp', $a)) or (!array_key_exists('timestamp', $b))) { - return 0; - } - if ($a->timestamp == $b->timestamp) + if ((!array_key_exists('timestamp', $a)) && (!array_key_exists('timestamp', $b))) { return 0; + } + // We treat instances without timestamp as if they have a timestamp of 0. + if ((!array_key_exists('timestamp', $a)) && (array_key_exists('timestamp', $b))) { + return 1; + } + if ((array_key_exists('timestamp', $a)) && (!array_key_exists('timestamp', $b))) { + return -1; + } + if ($a->timestamp == $b->timestamp) { + return 0; + } return ($a->timestamp > $b->timestamp) ? -1 : 1; } function compare_activities_by_time_asc($a, $b) { // make sure the activities actually have a timestamp property - if ((!array_key_exists('timestamp', $a)) or (!array_key_exists('timestamp', $b))) { + if ((!array_key_exists('timestamp', $a)) && (!array_key_exists('timestamp', $b))) { return 0; } - if ($a->timestamp == $b->timestamp) + // We treat instances without timestamp as if they have a timestamp of 0. + if ((!array_key_exists('timestamp', $a)) && (array_key_exists('timestamp', $b))) { + return -1; + } + if ((array_key_exists('timestamp', $a)) && (!array_key_exists('timestamp', $b))) { + return 1; + } + if ($a->timestamp == $b->timestamp) { return 0; + } return ($a->timestamp < $b->timestamp) ? -1 : 1; }