diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-03-05 04:19:11 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2015-03-05 05:31:19 +0300 |
commit | d30c78b8f46946e6f071b0547c638601bc78c7ab (patch) | |
tree | 6360689af81034355aaf5881d039e230b23b4230 /core/DataTable/Filter/ColumnCallbackAddColumn.php | |
parent | 287aad82841f0f0e85406192b2f1f865bc0be67d (diff) |
this should fix a bug with dbstats since we removed callable columns
Diffstat (limited to 'core/DataTable/Filter/ColumnCallbackAddColumn.php')
-rwxr-xr-x | core/DataTable/Filter/ColumnCallbackAddColumn.php | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/core/DataTable/Filter/ColumnCallbackAddColumn.php b/core/DataTable/Filter/ColumnCallbackAddColumn.php index 27746c4f28..1d81f189be 100755 --- a/core/DataTable/Filter/ColumnCallbackAddColumn.php +++ b/core/DataTable/Filter/ColumnCallbackAddColumn.php @@ -10,6 +10,7 @@ namespace Piwik\DataTable\Filter; use Piwik\DataTable; use Piwik\DataTable\BaseFilter; +use Piwik\Plugins\CoreHome\Columns\Metrics\CallableProcessedMetric; /** * Adds a new column to every row of a {@link DataTable} based on the result of callback. @@ -83,20 +84,29 @@ class ColumnCallbackAddColumn extends BaseFilter $functionParams = $this->functionParameters; $functionToApply = $this->functionToApply; - foreach ($table->getRows() as $row) { + $extraProcessedMetrics = $table->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME); + + if (empty($extraProcessedMetrics)) { + $extraProcessedMetrics = array(); + } - $row->setColumn($this->columnToAdd, function (DataTable\Row $row) use ($columns, $functionParams, $functionToApply) { + $metric = new CallableProcessedMetric($this->columnToAdd, function (DataTable\Row $row) use ($columns, $functionParams, $functionToApply) { - $columnValues = array(); - foreach ($columns as $column) { - $columnValues[] = $row->getColumn($column); - } + $columnValues = array(); + foreach ($columns as $column) { + $columnValues[] = $row->getColumn($column); + } - $parameters = array_merge($columnValues, $functionParams); + $parameters = array_merge($columnValues, $functionParams); - return call_user_func_array($functionToApply, $parameters); - }); + return call_user_func_array($functionToApply, $parameters); + }, $columns); + $extraProcessedMetrics[] = $metric; + $table->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics); + + foreach ($table->getRows() as $row) { + $row->setColumn($this->columnToAdd, $metric->compute($row)); $this->filterSubTable($row); } } |