diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-02-26 05:23:28 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2015-03-05 05:31:18 +0300 |
commit | 287aad82841f0f0e85406192b2f1f865bc0be67d (patch) | |
tree | d9c035a484c3f2727d7fa1cdf14ccd213c308508 /core/DataTable.php | |
parent | a1cb3695319b321f92bb0a4fd31892a9bc1bdf38 (diff) |
Faster flattening for many reports
Diffstat (limited to 'core/DataTable.php')
-rw-r--r-- | core/DataTable.php | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/core/DataTable.php b/core/DataTable.php index b060a87245..0b0d9845f0 100644 --- a/core/DataTable.php +++ b/core/DataTable.php @@ -342,6 +342,17 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess } /** + * @ignore + * does not update the summary row! + */ + public function setRows($rows) + { + unset($this->rows); + $this->rows = $rows; + $this->indexNotUpToDate = true; + } + + /** * Sorts the DataTable rows using the supplied callback function. * * @param string $functionCallback A comparison callback compatible with {@link usort}. @@ -350,11 +361,11 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess */ public function sort($functionCallback, $columnSortedBy) { - $this->indexNotUpToDate = true; - $this->tableSortedBy = $columnSortedBy; + $this->setTableSortedBy($columnSortedBy); + usort($this->rows, $functionCallback); - if ($this->enableRecursiveSort === true) { + if ($this->isSortRecursiveEnabled()) { foreach ($this->getRows() as $row) { $subTable = $row->getSubtable(); @@ -388,6 +399,23 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess } /** + * @ignore + */ + public function isSortRecursiveEnabled() + { + return $this->enableRecursiveSort === true; + } + + /** + * @ignore + */ + public function setTableSortedBy($column) + { + $this->indexNotUpToDate = true; + $this->tableSortedBy = $column; + } + + /** * Enables recursive filtering. If this method is called then the {@link filter()} method * will apply filters to every subtable in addition to this instance. */ @@ -397,6 +425,14 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess } /** + * @ignore + */ + public function disableRecursiveFilters() + { + $this->enableRecursiveFilters = false; + } + + /** * Applies a filter to this datatable. * * If {@link enableRecursiveFilters()} was called, the filter will be applied @@ -434,6 +470,25 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess } /** + * Applies a filter to all subtables but not to this datatable. + * + * @param string|Closure $className Class name, eg. `"Sort"` or "Piwik\DataTable\Filters\Sort"`. If no + * namespace is supplied, `Piwik\DataTable\BaseFilter` is assumed. This parameter + * can also be a closure that takes a DataTable as its first parameter. + * @param array $parameters Array of extra parameters to pass to the filter. + */ + public function filterSubtables($className, $parameters = array()) + { + foreach ($this->getRows() as $row) { + $subtable = $row->getSubtable(); + if ($subtable) { + $subtable->filter($className, $parameters); + $subtable->filterSubtables($className, $parameters); + } + } + } + + /** * Adds a filter and a list of parameters to the list of queued filters. These filters will be * executed when {@link applyQueuedFilters()} is called. * @@ -730,6 +785,14 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess } /** + * @ignore + */ + public function getRowsWithoutSummaryRow() + { + return $this->rows; + } + + /** * Returns an array containing all column values for the requested column. * * @param string $name The column name. |