From 24908c0871f8ea12b2f158a08499cf1e14dfa7de Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 8 Feb 2017 15:18:06 +0100 Subject: [statistics_reporting] Implement column filtering for export --- .../statistics_reporting/page.inc.php | 30 ++++++++++++++++++++-- .../templates/columnChooser.html | 7 +++-- 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'modules-available/statistics_reporting') diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php index f0614d35..51c137f6 100644 --- a/modules-available/statistics_reporting/page.inc.php +++ b/modules-available/statistics_reporting/page.inc.php @@ -87,11 +87,12 @@ class Page_Statistics_Reporting extends Page 'days' => array() ); + $forceOn = (Request::get('type') === false); foreach ($this->COLUMNS as $column) { $data['columns'][] = array( 'id' => 'col_' . $column, 'name' => Dictionary::translateFile('template-tags', 'lang_' . $column, true), - 'checked' => Request::get($column, 'on', 'string') === 'on' ? 'checked' : '', + 'checked' => ($forceOn || Request::get('col_' . $column, 'off', 'string') !== 'off') ? 'checked' : '', ); } @@ -162,7 +163,32 @@ class Page_Statistics_Reporting extends Page $flags |= GETDATA_PRINTABLE; } $res = $this->fetchData($flags); - // TODO: Filter unwanted columns + // Filter unwanted columns + if (isset($res[0])) { + foreach ($this->COLUMNS as $column) { + if (Request::get('col_' . $column, 'delete', 'string') === 'delete') { + foreach ($res as &$row) { + unset($row[$column], $row[$column . '_s']); + if ($column === 'location') { + unset($row['locationId']); + } + } + } elseif ($printable && isset($row[0][$column . '_s'])) { + foreach ($res as &$row) { + unset($row[$column]); + } + } elseif ($column === 'location' && (isset($res[0]['location']) || isset($res[0]['locationId']))) { + foreach ($res as &$row) { + if ($printable) { + unset($row['locationId']); + } else { + unset($row['location']); + } + } + } + } + unset($row); + } Header('Content-Disposition: attachment; filename=' . 'statistics-' . date('Y.m.d-H.i.s') . '.' . $format); switch ($format) { case 'json': diff --git a/modules-available/statistics_reporting/templates/columnChooser.html b/modules-available/statistics_reporting/templates/columnChooser.html index 75dfb34f..f08daf1c 100644 --- a/modules-available/statistics_reporting/templates/columnChooser.html +++ b/modules-available/statistics_reporting/templates/columnChooser.html @@ -34,9 +34,8 @@
{{lang_displayColumns}}
{{#columns}} -
- +
{{/columns}} @@ -142,6 +141,10 @@ $('.column-toggle').each(function () { var box = $(this); if ($('.' + box.attr('name')).length === 0) { + if (!box.is(':checked')) { + box.attr('value', 'off'); + box.prop('checked', true); + } box.parent().hide(); } else { updateColumn(box); -- cgit v1.2.3-55-g7522