Skip to content

Commit 85348f2

Browse files
committed
Sort log entries on the frontend.
1 parent 983cf7d commit 85348f2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/view_logs.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
$logs = array();
99
}
1010

11+
// We don't care about hashes on the frontend, and this lets us sort.
12+
$logs->incidence = get_object_vars($logs->incidence);
13+
1114
function format_log($log) {
1215
$log->decoded_message = $log->message;
1316
if ( $log->format == 'json' ) {
@@ -23,6 +26,21 @@ function format_log($log) {
2326
$log = format_log($log);
2427
}
2528

29+
// Show log entries in reverse chronological order.
30+
$logs->log = array_reverse($logs->log);
31+
32+
// Sort incidence entries by count.
33+
usort(
34+
$logs->incidence,
35+
function($a, $b) {
36+
if ( $a->count == $b->count ) {
37+
return 0;
38+
}
39+
// We're sorting descending.
40+
return ( $a->count < $b->count ) ? 1 : -1;
41+
}
42+
);
43+
2644
?>
2745
<!doctype html>
2846
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->

0 commit comments

Comments
 (0)