diff options
-rw-r--r-- | core/DataTable.php | 6 | ||||
-rw-r--r-- | core/DataTable/Filter/AddSummaryRow.php | 44 | ||||
-rw-r--r-- | core/DataTable/Filter/Truncate.php | 61 | ||||
-rw-r--r-- | plugins/CoreVisualizations/JqplotDataGenerator.php | 2 | ||||
-rw-r--r-- | plugins/DBStats/DBStats.php | 4 |
5 files changed, 65 insertions, 52 deletions
diff --git a/core/DataTable.php b/core/DataTable.php index cc367d98cd..193ad4d04e 100644 --- a/core/DataTable.php +++ b/core/DataTable.php @@ -1099,10 +1099,12 @@ class DataTable implements DataTableInterface throw new Exception("Maximum recursion level of " . self::$maximumDepthLevelAllowed . " reached. Maybe you have set a DataTable\Row with an associated DataTable belonging already to one of its parent tables?"); } if (!is_null($maximumRowsInDataTable)) { - $this->filter('AddSummaryRow', + $this->filter('Truncate', array($maximumRowsInDataTable - 1, DataTable::LABEL_SUMMARY_ROW, - $columnToSortByBeforeTruncation) + $columnToSortByBeforeTruncation, + $deleteRows = true, + $filterRecursive = false) ); } diff --git a/core/DataTable/Filter/AddSummaryRow.php b/core/DataTable/Filter/AddSummaryRow.php index 371b6df1fe..a050e31e1a 100644 --- a/core/DataTable/Filter/AddSummaryRow.php +++ b/core/DataTable/Filter/AddSummaryRow.php @@ -41,17 +41,10 @@ class AddSummaryRow extends Filter * @param null $columnToSortByBeforeTruncating * @param bool $deleteRows */ - public function __construct($table, - $startRowToSummarize, - $labelSummaryRow = DataTable::LABEL_SUMMARY_ROW, - $columnToSortByBeforeTruncating = null, - $deleteRows = true) + public function __construct($table, $labelSummaryRow = DataTable::LABEL_SUMMARY_ROW) { parent::__construct($table); - $this->startRowToSummarize = $startRowToSummarize; $this->labelSummaryRow = $labelSummaryRow; - $this->columnToSortByBeforeTruncating = $columnToSortByBeforeTruncating; - $this->deleteRows = $deleteRows; } /** @@ -61,35 +54,8 @@ class AddSummaryRow extends Filter */ public function filter($table) { - $table->filter('Sort', - array($this->columnToSortByBeforeTruncating, 'desc')); - - if ($table->getRowsCount() <= $this->startRowToSummarize + 1) { - return; - } - - $rows = $table->getRows(); - $count = $table->getRowsCount(); - $newRow = new Row(); - for ($i = $this->startRowToSummarize; $i < $count; $i++) { - if (!isset($rows[$i])) { - // case when the last row is a summary row, it is not indexed by $cout but by DataTable::ID_SUMMARY_ROW - $summaryRow = $table->getRowFromId(DataTable::ID_SUMMARY_ROW); - - //FIXME: I'm not sure why it could return false, but it was reported in: http://forum.piwik.org/read.php?2,89324,page=1#msg-89442 - if ($summaryRow) { - $newRow->sumRow($summaryRow, $enableCopyMetadata = false, $table->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME)); - } - } else { - $newRow->sumRow($rows[$i], $enableCopyMetadata = false, $table->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME)); - } - } - - $newRow->setColumns(array('label' => $this->labelSummaryRow) + $newRow->getColumns()); - if ($this->deleteRows) { - $table->filter('Limit', array(0, $this->startRowToSummarize)); - } - $table->addSummaryRow($newRow); - unset($rows); + $row = new DataTableSummaryRow($table); + $row->setColumn('label', $this->labelSummaryRow); + $table->addSummaryRow($row); } -} +}
\ No newline at end of file diff --git a/core/DataTable/Filter/Truncate.php b/core/DataTable/Filter/Truncate.php index bea38ad178..56aa4ea5b2 100644 --- a/core/DataTable/Filter/Truncate.php +++ b/core/DataTable/Filter/Truncate.php @@ -24,10 +24,19 @@ class Truncate extends Filter * @param DataTable $table * @param int $truncateAfter */ - public function __construct($table, $truncateAfter) + public function __construct($table, + $truncateAfter, + $labelSummaryRow = DataTable::LABEL_SUMMARY_ROW, + $columnToSortByBeforeTruncating = null, + $deleteRows = true, + $filterRecursive = true) { parent::__construct($table); $this->truncateAfter = $truncateAfter; + $this->labelSummaryRow = $labelSummaryRow; + $this->columnToSortByBeforeTruncating = $columnToSortByBeforeTruncating; + $this->deleteRows = $deleteRows; + $this->filterRecursive = $filterRecursive; } /** @@ -37,15 +46,51 @@ class Truncate extends Filter */ public function filter($table) { - $table->filter('AddSummaryRow', array($this->truncateAfter)); + $this->addSummaryRow($table); $table->filter('ReplaceSummaryRowLabel'); - foreach ($table->getRows() as $row) { - if ($row->isSubtableLoaded()) { - $idSubTable = $row->getIdSubDataTable(); - $subTable = Manager::getInstance()->getTable($idSubTable); - $subTable->filter('Truncate', array($this->truncateAfter)); + if ($this->filterRecursive) { + foreach ($table->getRows() as $row) { + if ($row->isSubtableLoaded()) { + $idSubTable = $row->getIdSubDataTable(); + $subTable = Manager::getInstance()->getTable($idSubTable); + $subTable->filter('Truncate', array($this->truncateAfter)); + } } } } -} + + public function addSummaryRow($table) + { + $table->filter('Sort', + array($this->columnToSortByBeforeTruncating, 'desc')); + + if ($table->getRowsCount() <= $this->startRowToSummarize + 1) { + return; + } + + $rows = $table->getRows(); + $count = $table->getRowsCount(); + $newRow = new Row(); + for ($i = $this->startRowToSummarize; $i < $count; $i++) { + if (!isset($rows[$i])) { + // case when the last row is a summary row, it is not indexed by $cout but by DataTable::ID_SUMMARY_ROW + $summaryRow = $table->getRowFromId(DataTable::ID_SUMMARY_ROW); + + //FIXME: I'm not sure why it could return false, but it was reported in: http://forum.piwik.org/read.php?2,89324,page=1#msg-89442 + if ($summaryRow) { + $newRow->sumRow($summaryRow, $enableCopyMetadata = false, $table->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME)); + } + } else { + $newRow->sumRow($rows[$i], $enableCopyMetadata = false, $table->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME)); + } + } + + $newRow->setColumns(array('label' => $this->labelSummaryRow) + $newRow->getColumns()); + if ($this->deleteRows) { + $table->filter('Limit', array(0, $this->startRowToSummarize)); + } + $table->addSummaryRow($newRow); + unset($rows); + } +}
\ No newline at end of file diff --git a/plugins/CoreVisualizations/JqplotDataGenerator.php b/plugins/CoreVisualizations/JqplotDataGenerator.php index f13a6cf3cc..00e4330bd3 100644 --- a/plugins/CoreVisualizations/JqplotDataGenerator.php +++ b/plugins/CoreVisualizations/JqplotDataGenerator.php @@ -87,7 +87,7 @@ class JqplotDataGenerator // if addTotalRow was called in GenerateGraphHTML, add a row containing totals of // different metrics if ($this->properties['add_total_row']) { - $dataTable->queueFilter('AddSummaryRow', array(0, Piwik::translate('General_Total'), null, false)); + $dataTable->queueFilter('AddSummaryRow', Piwik::translate('General_Total')); } $dataTable->applyQueuedFilters(); diff --git a/plugins/DBStats/DBStats.php b/plugins/DBStats/DBStats.php index 63f9f439f5..9b9eac305c 100644 --- a/plugins/DBStats/DBStats.php +++ b/plugins/DBStats/DBStats.php @@ -16,6 +16,7 @@ use Piwik\Date; use Piwik\Menu\MenuAdmin; use Piwik\Option; use Piwik\Piwik; +use Piwik\DataTable\Row\DataTableSummaryRow; use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie; @@ -312,8 +313,7 @@ class DBStats extends \Piwik\Plugin if ($view->isViewDataTableId(HtmlTable::ID)) { // add summary row only if displaying a table - $view->config->filters[] = array( - 'AddSummaryRow', array(0, Piwik::translate('General_Total'), 'label', false), $isPriority = true); + $dataTable->queueFilter('AddSummaryRow', Piwik::translate('General_Total')); // add percentage column if desired if ($addPercentColumn |