diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-03-16 06:12:02 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2015-03-16 06:12:02 +0300 |
commit | 54ac2bf9d949d45eb756768003a0d4e0008e0a61 (patch) | |
tree | 2842cc3cd4911dd5b473eb20302f97ecaa8f09b4 /core | |
parent | fe85ab09c24dc41a69bb08e39ac5ea41c43a4f66 (diff) |
possibility to define a default sort order in a report class
Diffstat (limited to 'core')
-rw-r--r-- | core/API/DataTableGenericFilter.php | 31 | ||||
-rw-r--r-- | core/API/DataTablePostProcessor.php | 2 | ||||
-rw-r--r-- | core/Plugin/Report.php | 15 |
3 files changed, 44 insertions, 4 deletions
diff --git a/core/API/DataTableGenericFilter.php b/core/API/DataTableGenericFilter.php index 46274b0c31..ff49491642 100644 --- a/core/API/DataTableGenericFilter.php +++ b/core/API/DataTableGenericFilter.php @@ -10,7 +10,6 @@ namespace Piwik\API; use Exception; use Piwik\Common; -use Piwik\DataTable\Filter\AddColumnsProcessedMetricsGoal; use Piwik\DataTable; use Piwik\Plugin\ProcessedMetric; use Piwik\Plugin\Report; @@ -25,13 +24,24 @@ class DataTableGenericFilter private $disabledFilters = array(); /** + * @var Report + */ + private $report; + + /** + * @var array + */ + private $request; + + /** * Constructor * * @param $request */ - function __construct($request) + function __construct($request, $report) { $this->request = $request; + $this->report = $report; } /** @@ -102,6 +112,21 @@ class DataTableGenericFilter ); } + private function getGenericFiltersHavingDefaultValues() + { + $filters = self::getGenericFiltersInformation(); + + if ($this->report && $this->report->getDefaultSortColumn()) { + foreach ($filters as $index => $filter) { + if ($filter[0] === 'Sort') { + $filters[$index][1]['filter_sort_column'] = array('string', $this->report->getDefaultSortColumn()); + } + } + } + + return $filters; + } + /** * Apply generic filters to the DataTable object resulting from the API Call. * Disable this feature by setting the parameter disable_generic_filters to 1 in the API call request. @@ -119,7 +144,7 @@ class DataTableGenericFilter return; } - $genericFilters = self::getGenericFiltersInformation(); + $genericFilters = $this->getGenericFiltersHavingDefaultValues(); $filterApplied = false; foreach ($genericFilters as $filterMeta) { diff --git a/core/API/DataTablePostProcessor.php b/core/API/DataTablePostProcessor.php index dfa0434da6..8d936e6779 100644 --- a/core/API/DataTablePostProcessor.php +++ b/core/API/DataTablePostProcessor.php @@ -207,7 +207,7 @@ class DataTablePostProcessor if (0 == Common::getRequestVar('disable_generic_filters', '0', 'string', $this->request)) { $this->applyProcessedMetricsGenericFilters($dataTable); - $genericFilter = new DataTableGenericFilter($this->request); + $genericFilter = new DataTableGenericFilter($this->request, $this->report); $self = $this; $report = $this->report; diff --git a/core/Plugin/Report.php b/core/Plugin/Report.php index b9c407e10e..dfbe6e50cf 100644 --- a/core/Plugin/Report.php +++ b/core/Plugin/Report.php @@ -189,6 +189,13 @@ class Report protected $recursiveLabelSeparator = ' - '; /** + * Default sort column. Either a column name or a column id. + * + * @var string|int + */ + protected $defaultSortColumn = ''; + + /** * @var array * @ignore */ @@ -579,6 +586,14 @@ class Report } /** + * @ignore + */ + public function getDefaultSortColumn() + { + return $this->defaultSortColumn; + } + + /** * Get the list of related reports if there are any. They will be displayed for instance below a report as a * recommended related report. * |