Join
6 years ago
ComputedMetricFactory.php
6 years ago
Dimension.php
6 years ago
DimensionMetricFactory.php
6 years ago
DimensionsProvider.php
6 years ago
Discriminator.php
6 years ago
Join.php
6 years ago
MetricsList.php
6 years ago
Updater.php
6 years ago
ComputedMetricFactory.php
57 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Piwik - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * |
| 8 | */ |
| 9 | namespace Piwik\Columns; |
| 10 | |
| 11 | use Piwik\Piwik; |
| 12 | use Piwik\Plugin\ArchivedMetric; |
| 13 | use Piwik\Plugin\ComputedMetric; |
| 14 | use Piwik\Plugin\Report; |
| 15 | |
| 16 | /** |
| 17 | * A factory to create computed metrics. |
| 18 | * |
| 19 | * @api since Piwik 3.2.0 |
| 20 | */ |
| 21 | class ComputedMetricFactory |
| 22 | { |
| 23 | /** |
| 24 | * @var MetricsList |
| 25 | */ |
| 26 | private $metricsList = null; |
| 27 | |
| 28 | /** |
| 29 | * Generates a new report metric factory. |
| 30 | * @param MetricsList $list A report list instance |
| 31 | * @ignore |
| 32 | */ |
| 33 | public function __construct(MetricsList $list) |
| 34 | { |
| 35 | $this->metricsList = $list; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @return \Piwik\Plugin\ComputedMetric |
| 40 | */ |
| 41 | public function createComputedMetric($metricName1, $metricName2, $aggregation) |
| 42 | { |
| 43 | $metric1 = $this->metricsList->getMetric($metricName1); |
| 44 | |
| 45 | if (!$metric1 instanceof ArchivedMetric || !$metric1->getDimension()) { |
| 46 | throw new \Exception('Only possible to create computed metric for an archived metric with a dimension'); |
| 47 | } |
| 48 | |
| 49 | $dimension1 = $metric1->getDimension(); |
| 50 | |
| 51 | $metric = new ComputedMetric($metricName1, $metricName2, $aggregation); |
| 52 | $metric->setCategory($dimension1->getCategoryId()); |
| 53 | |
| 54 | return $metric; |
| 55 | } |
| 56 | |
| 57 | } |