diff options
Diffstat (limited to 'core')
-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); } } |