diff options
author | benakamoorthi <benaka.moorthi@gmail.com> | 2011-12-26 03:44:45 +0400 |
---|---|---|
committer | benakamoorthi <benaka.moorthi@gmail.com> | 2011-12-26 03:44:45 +0400 |
commit | 6e8ae94fc44bb42b34e5ed9070cbd10dcf01a3d4 (patch) | |
tree | d87850c41d4ea591b2bc299c2cb4a57fdb6bd95d /core/DataTable/Filter/ColumnCallbackAddColumnQuotient.php | |
parent | cea387bf2de590e6d7e4c4a79e01770bd4243e8e (diff) |
Fixes #2810. Refactored MultiSites plugin:
* Created MultiSites API w/ getAll method that gets visit/action/revenue & related evolution data for all sites.
* Modified MultiSites Controller to use aforementioned API.
* Fixed bug I introduced in integration tests, method doTest_TwoVisitors_twoWebsites_differentDays shouldn't allow tests to skip the API.getProcessedReport test.
* Added mergeChildren & related unit test to Piwik_DataTable_Array.
* Added static methods to Piwik_Site to get site data using an ID. Using it avoids having to create a new Piwik_Site instance.
* Modified ColumnCallbackAddColumnQuotient so it can be better extended and so it's possible to avoid processing rows if desired.
git-svn-id: http://dev.piwik.org/svn/trunk@5626 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'core/DataTable/Filter/ColumnCallbackAddColumnQuotient.php')
-rw-r--r-- | core/DataTable/Filter/ColumnCallbackAddColumnQuotient.php | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/core/DataTable/Filter/ColumnCallbackAddColumnQuotient.php b/core/DataTable/Filter/ColumnCallbackAddColumnQuotient.php index 22f157b447..7476111f36 100644 --- a/core/DataTable/Filter/ColumnCallbackAddColumnQuotient.php +++ b/core/DataTable/Filter/ColumnCallbackAddColumnQuotient.php @@ -24,6 +24,7 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient extends Piwik_DataT protected $columnNameUsedAsDivisor; protected $totalValueUsedAsDivisor; protected $quotientPrecision; + protected $shouldSkipRows; /** * @param Piwik_DataTable $table @@ -33,8 +34,9 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient extends Piwik_DataT * if a numeric value is given, we use this value as the divisor to process the percentage. * if a string is given, this string is the column name's value used as the divisor. * @param numeric $quotientPrecision Division precision + * @param numeric $shouldSkipRows Whether rows w/o the column to read should be skipped. */ - public function __construct( $table, $columnNameToAdd, $columnValueToRead, $divisorValueOrDivisorColumnName, $quotientPrecision = 0) + public function __construct( $table, $columnNameToAdd, $columnValueToRead, $divisorValueOrDivisorColumnName, $quotientPrecision = 0, $shouldSkipRows = false) { parent::__construct($table); $this->columnValueToRead = $columnValueToRead; @@ -48,6 +50,7 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient extends Piwik_DataT $this->columnNameUsedAsDivisor = $divisorValueOrDivisorColumnName; } $this->quotientPrecision = $quotientPrecision; + $this->shouldSkipRows = $shouldSkipRows; } public function filter($table) @@ -59,15 +62,15 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient extends Piwik_DataT { continue; } - $value = $row->getColumn($this->columnValueToRead); - if(!is_null($this->totalValueUsedAsDivisor)) - { - $divisor = $this->totalValueUsedAsDivisor; - } - else + + $value = $this->getDividend($row); + if ($value === false && $this->shouldSkipRows) { - $divisor = $row->getColumn($this->columnNameUsedAsDivisor); + continue; } + + $divisor = $this->getDivisor($row); + $formattedValue = $this->formatValue($value, $divisor); $row->addColumn($this->columnNameToAdd, $formattedValue); @@ -84,4 +87,35 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient extends Piwik_DataT } return $quotient; } + + /** + * Returns the dividend to use when calculating the new column value. Can + * be overridden by descendent classes to customize behavior. + * + * @param Piwik_DataTable_Row $row The row being modified. + * @return int|float + */ + protected function getDividend($row) + { + return $row->getColumn($this->columnValueToRead); + } + + /** + * Returns the divisor to use when calculating the new column value. Can + * be overridden by descendent classes to customize behavior. + * + * @param Piwik_DataTable_Row $row The row being modified. + * @return int|float + */ + protected function getDivisor($row) + { + if(!is_null($this->totalValueUsedAsDivisor)) + { + return $this->totalValueUsedAsDivisor; + } + else + { + return $row->getColumn($this->columnNameUsedAsDivisor); + } + } } |