From 452a0a49d0e9bef75667e488b37580dd5688a923 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 2 Feb 2017 16:06:40 +0100 Subject: [statistics_reporting] Move logic js -> php (for export feature) --- .../statistics_reporting/page.inc.php | 111 ++++++++++++++++++--- 1 file changed, 99 insertions(+), 12 deletions(-) (limited to 'modules-available/statistics_reporting/page.inc.php') diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php index 81d44e15..235cebb7 100644 --- a/modules-available/statistics_reporting/page.inc.php +++ b/modules-available/statistics_reporting/page.inc.php @@ -4,7 +4,22 @@ class Page_Statistics_Reporting extends Page { - private $action = false; + private $action; + private $type; + + // "Constants" + private $days; + + /** + * @var array Names of columns that are being used by the various tables + */ + private $COLUMNS = array('col_lastlogout', 'col_laststart', 'col_location', 'col_longsessions', 'col_mediantime', + 'col_sessions', 'col_shortsessions', 'col_timeoffline', 'col_totaltime'); + + /** + * @var array Names of the tables we can display + */ + private $TABLES = array('total', 'location', 'client', 'user', 'vm'); /** * Called before any page rendering happens - early hook to check parameters etc. @@ -19,6 +34,15 @@ class Page_Statistics_Reporting extends Page } $this->action = Request::any('action', 'show', 'string'); + $this->type = Request::get('type', 'total', 'string'); + $this->days = Request::get('cutoff', 7, 'int'); + $this->lower = Request::get('lower', 8, 'int'); + $this->upper = Request::get('upper', 20, 'int'); + + if (!in_array($this->type, $this->TABLES)) { + Message::addError('invalid-table-type', $this->type); + $this->type = 'total'; + } } /** @@ -27,20 +51,67 @@ class Page_Statistics_Reporting extends Page protected function doRender() { if ($this->action === 'show') { + + /* + * Leave these here for the translate module + * Dictionary::translate('col_lastlogout'); + * Dictionary::translate('col_laststart'); + * Dictionary::translate('col_location'); + * Dictionary::translate('col_longsessions'); + * Dictionary::translate('col_mediantime'); + * Dictionary::translate('col_sessions'); + * Dictionary::translate('col_shortsessions'); + * Dictionary::translate('col_timeoffline'); + * Dictionary::translate('col_totaltime'); + * Dictionary::translate('table_total'); + * Dictionary::translate('table_location'); + * Dictionary::translate('table_client'); + * Dictionary::translate('table_user'); + * Dictionary::translate('table_vm'); + */ + + $data = array( + 'columns' => array(), + 'tables' => array(), + 'days' => array() + ); + + foreach ($this->COLUMNS as $column) { + $data['columns'][] = array( + 'id' => $column, + 'name' => Dictionary::translate($column, true), + 'checked' => Request::get($column, 'on', 'string') === 'on' ? 'checked' : '', + ); + } + + foreach ($this->TABLES as $table) { + $data['tables'][] = array( + 'name' => Dictionary::translate('table_' . $table, true), + 'value' => $table, + 'selected' => ($this->type === $table) ? 'selected' : '', + ); + } + + foreach (array(1,2,5,7,14,30,90) as $day) { + $data['days'][] = array( + 'days' => $day, + 'selected' => ($day === $this->days) ? 'selected' : '', + ); + } + + $data['lower'] = $this->lower; + $data['upper'] = $this->upper; + + Render::addTemplate('columnChooser', $data); + // timespan you want to see. default = last 7 days - GetData::$from = strtotime("- " . (Request::get('cutoff', 7, 'int') - 1) . " days 00:00:00"); + GetData::$from = strtotime("- " . ($this->days - 1) . " days 00:00:00"); GetData::$to = time(); - GetData::$lowerTimeBound = Request::get('lower', 0, 'int'); - GetData::$upperTimeBound = Request::get('upper', 24, 'int'); - - $data = GetData::total(GETDATA_PRINTABLE); - $data['perLocation'] = GetData::perLocation(GETDATA_PRINTABLE); - $data['perClient'] = GetData::perClient(GETDATA_PRINTABLE); - $data['perUser'] = GetData::perUser(GETDATA_PRINTABLE); - $data['perVM'] = GetData::perVM(GETDATA_PRINTABLE); + GetData::$lowerTimeBound = $this->lower; + GetData::$upperTimeBound = $this->upper; - Render::addTemplate('columnChooser'); - Render::addTemplate('_page', $data); + $data['data'] = $this->fetchData(GETDATA_PRINTABLE); + Render::addTemplate('table-' . $this->type, $data); } } @@ -63,4 +134,20 @@ class Page_Statistics_Reporting extends Page } } + private function fetchData($flags) + { + switch ($this->type) { + case 'total': + return GetData::total($flags); + case 'location': + return GetData::perLocation($flags); + case 'client': + return GetData::perClient($flags); + case 'user': + return GetData::perUser($flags); + case 'vm': + return GetData::perVM($flags); + } + } + } -- cgit v1.2.3-55-g7522