Skip to content

Commit

Permalink
Forgot to add refactored file.
Browse files Browse the repository at this point in the history
  • Loading branch information
diosmosis committed Nov 27, 2014
1 parent 36c7c60 commit a58c81e
Showing 1 changed file with 50 additions and 0 deletions.
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);
}
}

0 comments on commit a58c81e

Please sign in to comment.