Skip to content
Browse files

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

…mestamp
  • Loading branch information...
1 parent 8673a98 commit 50c02a3556298234241a6e048b4f5ff6b6a1ef87 @ankitagarwal ankitagarwal committed
Showing with 21 additions and 5 deletions.
  1. +21 −5 course/recent.php
View
26 course/recent.php
@@ -274,21 +274,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 50c02a3

Please sign in to comment.
Something went wrong with that request. Please try again.