From 46f0636f2fc796b9010c16d22ddb351a7f4582d5 Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Sat, 18 Jul 2015 21:27:30 +0200 Subject: arrival statistics --- includes/pages/admin_arrive.php | 68 +++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 12 deletions(-) (limited to 'includes/pages') diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index 399cb335..60e1fe2c 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -31,6 +31,7 @@ function admin_arrive() { } $users = sql_select("SELECT * FROM `User` ORDER BY `Nick`"); + $arrival_count_at_day = array(); $table = ""; $users_matched = array(); if ($search == "") @@ -49,20 +50,36 @@ function admin_arrive() { if (! $match) continue; } - $table .= ''; - $table .= '' . User_Nick_render($usr) . ''; + $usr['nick'] = User_Nick_render($usr); - $usr['planned_arrival_date'] = date('Y-m-d', $usr['planned_arrival_date']); - $usr['arrival_date'] = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : "-"; + $usr['rendered_planned_arrival_date'] = date('Y-m-d', $usr['planned_arrival_date']); + $usr['rendered_arrival_date'] = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : "-"; $usr['arrived'] = $usr['Gekommen'] == 1 ? _("yes") : ""; $usr['actions'] = $usr['Gekommen'] == 1 ? '' . _("reset") . '' : '' . _("arrived") . ''; - if ($usr['Gekommen'] == 1) - $table .= 'yesreset'; - else - $table .= 'arrived'; - $table .= ''; + + $day = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : date('Y-m-d', $usr['planned_arrival_date']); + if (! isset($arrival_count_at_day[$day])) + $arrival_count_at_day[$day] = 0; + $arrival_count_at_day[$day] ++; + $users_matched[] = $usr; } + + ksort($arrival_count_at_day); + + $arrival_count = array(); + $arrival_sums = array(); + $arrival_sum = 0; + foreach ($arrival_count_at_day as $day => $count) { + $arrival_sum += $count; + $arrival_sums[$day] = $arrival_sum; + $arrival_count[] = array( + 'day' => $day, + 'count' => $count, + 'sum' => $arrival_sum + ); + } + return page_with_title(admin_arrive_title(), array( msg(), form(array( @@ -71,11 +88,38 @@ function admin_arrive() { )), table(array( 'nick' => _("Nickname"), - 'planned_arrival_date' => _("Planned date"), + 'rendered_planned_arrival_date' => _("Planned date"), 'arrived' => _("Arrived?"), - 'arrival_date' => _("Arrival date"), + 'rendered_arrival_date' => _("Arrival date"), 'actions' => "" - ), $users_matched) + ), $users_matched), + heading(_("Arrival statistics"), 2), + table(array( + 'day' => _("Date"), + 'count' => _("arrived"), + 'sum' => _("arrived sum") + ), $arrival_count), + ' + ' )); } ?> -- cgit v1.2.3-70-g09d2