Permalink
Browse files

MDL-36872 reports: Fixing incorrect sorting of recent activites by ti…

…mestamp
  • Loading branch information...
1 parent 1bfc006 commit 77df5b724d0fca245a281d25c98b3bab606d41e2 @ankitagarwal ankitagarwal committed Mar 12, 2013
Showing with 21 additions and 5 deletions.
  1. +21 −5 course/recent.php
View
26 course/recent.php
@@ -280,21 +280,37 @@
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 ((!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)
+ 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;
}

0 comments on commit 77df5b7

Please sign in to comment.