diff options
author | benakamoorthi <benaka.moorthi@gmail.com> | 2012-05-26 23:39:16 +0400 |
---|---|---|
committer | benakamoorthi <benaka.moorthi@gmail.com> | 2012-05-26 23:39:16 +0400 |
commit | 71fc2e87eb99212ccd0da6235a8410f55c39c7b5 (patch) | |
tree | 6c1ca494613399a26eedbbff0247f46a63ecd84e /core/DataTable/Filter/ColumnCallbackAddColumn.php | |
parent | 6add1fa233d9312651d79efb5f76fb5da62b0960 (diff) |
Fixes #3004, redesigned DBStats plugin, added several new reports including database space taken up by tracker tables, database space taken up by archive blob tables, database space taken up by archive metric tables, database space taken up by individual reports & database space taken up by individual metrics.
Notes:
* Added ability to highlight the summary row in ViewDataTable and the ability to always show the summary row regardless of what report page is currently being shown.
* Fixed small issue w/ ViewDataTable::hasReportBeenPurged: default values should be specified in calls to getRequestVar.
* Added Piwik_FetchAssoc function to PluginsFunctions/Sql.php
* Augmented ColumnCallbackAddColumnQuotient filter so the divisor can be obtained from the summary row.
* Modified AddSummaryRow filter so it wouldn't delete rows if desired.
* Added ColumnCallbackAddColumn filer that adds a new column to each row based on the result of a callback.
* Modified ColumnCallbackReplace filter so callback can operate on more than one column value if desired.
* Modified Limit filter so, if desired, the summary row can be exempted from deletion.
* Added GroupBy filter that groups/sums rows by the result of a callback function.
* Fixed GenerateGraphData.php bug where priority filters were not called on view data table.
* Added getPrettyNumber utility function.
git-svn-id: http://dev.piwik.org/svn/trunk@6324 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'core/DataTable/Filter/ColumnCallbackAddColumn.php')
-rwxr-xr-x | core/DataTable/Filter/ColumnCallbackAddColumn.php | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/core/DataTable/Filter/ColumnCallbackAddColumn.php b/core/DataTable/Filter/ColumnCallbackAddColumn.php new file mode 100755 index 0000000000..1216e513d3 --- /dev/null +++ b/core/DataTable/Filter/ColumnCallbackAddColumn.php @@ -0,0 +1,91 @@ +<?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: ColumnCallbackAddColumn.php $ + * + * @category Piwik + * @package Piwik + */ + +/** + * Adds a new column to every row of a DataTable based on the result of callback. + * + * @package Piwik + * @subpackage Piwik_DataTable + */ +class Piwik_DataTable_Filter_ColumnCallbackAddColumn extends Piwik_DataTable_Filter +{ + /** + * The names of the columns to pass to the callback. + */ + private $columns; + + /** + * The name of the column to add. + */ + private $columnToAdd; + + /** + * The callback to apply to each row of the DataTable. The result is added as + * the value of a new column. + */ + private $functionToApply; + + /** + * Extra parameters to pass to the callback. + */ + private $functionParameters; + + /** + * Constructor. + * + * @param Piwik_DataTable $table The DataTable that will be filtered. + * @param array|string $columns The names of the columns to pass to the callback. + * @param string $columnToAdd The name of the column to add. + * @param mixed $functionToApply The callback to apply to each row of a DataTable. + * @param array $functionParameters Extra parameters to pass to $functionToApply. + */ + public function __construct( $table, $columns, $columnToAdd, $functionToApply, $functionParameters = array() ) + { + parent::__construct($table); + + if (!is_array($columns)) + { + $columns = array($columns); + } + + $this->columns = $columns; + $this->columnToAdd = $columnToAdd; + $this->functionToApply = $functionToApply; + $this->functionParameters = $functionParameters; + } + + /** + * Executes a callback on every row of the supplied table and adds the result of + * the callback as a new column to each row. + * + * @param Piwik_DataTable $table The table to filter. + */ + public function filter( $table ) + { + foreach ($table->getRows() as $row) + { + $columnValues = array(); + foreach ($this->columns as $column) + { + $columnValues[] = $row->getColumn($column); + } + + $parameters = array_merge($columnValues, $this->functionParameters); + $value = call_user_func_array($this->functionToApply, $parameters); + + $row->setColumn($this->columnToAdd, $value); + + $this->filterSubTable($row); + } + } +} + |