diff options
author | mattpiwik <matthieu.aubry@gmail.com> | 2008-08-04 04:11:03 +0400 |
---|---|---|
committer | mattpiwik <matthieu.aubry@gmail.com> | 2008-08-04 04:11:03 +0400 |
commit | 2854426e8609e0f9e3ceac2e27327532bf00a408 (patch) | |
tree | 5214705435461179efecb331075a9830a21a5594 /core/DataTable/Filter/AddSummaryRow.php | |
parent | 42b52b6d8a88b3fa4c4f3978c4e7bf00b1eac778 (diff) |
oops i totally screwed up my last commit, deleting /modules instead of renaming it...
git-svn-id: http://dev.piwik.org/svn/trunk@587 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'core/DataTable/Filter/AddSummaryRow.php')
-rw-r--r-- | core/DataTable/Filter/AddSummaryRow.php | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/core/DataTable/Filter/AddSummaryRow.php b/core/DataTable/Filter/AddSummaryRow.php new file mode 100644 index 0000000000..b8d956dd43 --- /dev/null +++ b/core/DataTable/Filter/AddSummaryRow.php @@ -0,0 +1,67 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later + * @version $Id: Limit.php 168 2008-01-14 05:26:43Z matt $ + * + * @package Piwik_DataTable + */ + +/** + * Add a new row to the table containing a summary + * of the rows from StartRowToSummarize to EndRowToSummarize. + * It then deletes the rows from StartRowToSummarize to EndRowToSummarize. + * The new row created has a label = 'other' + * + * This filter is useful to build a more compact view of a table, + * keeping the first records unchanged. + * + * For example we use this for the pie chart, to build the last pie part + * which is the sum of all the remaining data after the top 5 data. + * This row is assigned a label of 'Others'. + * + * @package Piwik_DataTable + * @subpackage Piwik_DataTable_Filter + */ +class Piwik_DataTable_Filter_AddSummaryRow extends Piwik_DataTable_Filter +{ + public function __construct( $table, $startRowToSummarize, $labelSummaryRow = Piwik_DataTable::LABEL_SUMMARY_ROW, $columnToSortByBeforeTruncating = Piwik_Archive::INDEX_NB_VISITS ) + { + parent::__construct($table); + $this->startRowToSummarize = $startRowToSummarize; + $this->labelSummaryRow = $labelSummaryRow; + $this->columnToSortByBeforeTruncating = $columnToSortByBeforeTruncating; + + if($table->getRowsCount() > $startRowToSummarize + 1) + { + $this->filter(); + } + } + + protected function filter() + { + $filter = new Piwik_DataTable_Filter_Sort($this->table, $this->columnToSortByBeforeTruncating, 'desc'); + + $rows = $this->table->getRows(); + $count = $this->table->getRowsCount(); + $newRow = new Piwik_DataTable_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 Piwik_DataTable::ID_SUMMARY_ROW + $summaryRow = $this->table->getRowFromId(Piwik_DataTable::ID_SUMMARY_ROW); + $newRow->sumRow($summaryRow); + } + else + { + $newRow->sumRow($rows[$i]); + } + } + $newRow->addColumn('label', $this->labelSummaryRow); + $filter = new Piwik_DataTable_Filter_Limit($this->table, 0, $this->startRowToSummarize); + $this->table->addSummaryRow($newRow); + } +} |