forked from matomo-org/matomo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
diosmosis
committed
Nov 27, 2014
1 parent
36c7c60
commit a58c81e
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
plugins/MultiSites/Columns/Metrics/EcommerceOnlyEvolutionMetric.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Piwik - free/libre analytics platform | ||
* | ||
* @link http://piwik.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
namespace Piwik\Plugins\MultiSites\Columns\Metrics; | ||
|
||
use Piwik\DataTable; | ||
use Piwik\DataTable\Row; | ||
use Piwik\Plugins\CoreHome\Columns\Metrics\EvolutionMetric; | ||
use Piwik\Site; | ||
|
||
/** | ||
* Ecommerce evolution metric adapter. This is a special processed metric for MultiSites API methods. It will | ||
* only be calculated for sites that have ecommerce enabled. The site is determined by the label | ||
* of each row. | ||
*/ | ||
class EcommerceOnlyEvolutionMetric extends EvolutionMetric | ||
{ | ||
private $isRevenueEvolution; | ||
|
||
public function __construct($wrapped, DataTable $pastData, $evolutionMetricName = false, $quotientPrecision = 0) | ||
{ | ||
parent::__construct($wrapped, $pastData, $evolutionMetricName, $quotientPrecision); | ||
|
||
$this->isRevenueEvolution = $this->getName() == 'revenue_evolution'; | ||
} | ||
|
||
public function compute(Row $row) | ||
{ | ||
$columnName = $this->getWrappedName(); | ||
$currentValue = $this->getMetric($row, $columnName); | ||
|
||
// if the site this is for doesn't support ecommerce & this is for the revenue_evolution column, | ||
// we don't add the new column | ||
if (($currentValue === false | ||
|| !$this->isRevenueEvolution) | ||
&& !Site::isEcommerceEnabledFor($row->getColumn('label')) | ||
) { | ||
$row->deleteColumn($columnName); | ||
|
||
return false; | ||
} | ||
|
||
return parent::compute($row); | ||
} | ||
} |