PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Columns / DimensionMetricFactory.php
matomo / app / core / Columns Last commit date
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
DimensionMetricFactory.php
122 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 /**
18 * A factory to create metrics from a dimension.
19 *
20 * @api since Piwik 3.2.0
21 */
22 class DimensionMetricFactory
23 {
24 /**
25 * @var Dimension
26 */
27 private $dimension = null;
28
29 /**
30 * Generates a new dimension metric factory.
31 * @param Dimension $dimension A dimension instance the created metrics should be based on.
32 */
33 public function __construct(Dimension $dimension)
34 {
35 $this->dimension = $dimension;
36 }
37
38 /**
39 * @return ArchivedMetric
40 */
41 public function createCustomMetric($metricName, $readableName, $aggregation, $documentation = '')
42 {
43 if (!$this->dimension->getDbTableName() || !$this->dimension->getColumnName()) {
44 throw new \Exception(sprintf('Cannot make metric from dimension %s because DB table or column missing', $this->dimension->getId()));
45 }
46
47 $metric = new ArchivedMetric($this->dimension, $aggregation);
48 $metric->setType($this->dimension->getType());
49 $metric->setName($metricName);
50 $metric->setTranslatedName($readableName);
51 $metric->setDocumentation($documentation);
52 $metric->setCategory($this->dimension->getCategoryId());
53
54 return $metric;
55 }
56
57 /**
58 * @return \Piwik\Plugin\ComputedMetric
59 */
60 public function createComputedMetric($metricName1, $metricName2, $aggregation)
61 {
62 // We cannot use reuse ComputedMetricFactory here as it would result in an endless loop since ComputedMetricFactory
63 // requires a MetricsList which is just being built here...
64 $metric = new ComputedMetric($metricName1, $metricName2, $aggregation);
65 $metric->setCategory($this->dimension->getCategoryId());
66 return $metric;
67 }
68
69 /**
70 * @return ArchivedMetric
71 */
72 public function createMetric($aggregation)
73 {
74 $dimension = $this->dimension;
75
76 if (!$dimension->getNamePlural()) {
77 throw new \Exception(sprintf('No metric can be created for this dimension %s automatically because no $namePlural is set.', $dimension->getId()));
78 }
79
80 $prefix = '';
81 $translatedName = $dimension->getNamePlural();
82
83 $documentation = '';
84
85 switch ($aggregation) {
86 case ArchivedMetric::AGGREGATION_COUNT;
87 $prefix = ArchivedMetric::AGGREGATION_COUNT_PREFIX;
88 $translatedName = $dimension->getNamePlural();
89 $documentation = Piwik::translate('General_ComputedMetricCountDocumentation', $dimension->getNamePlural());
90 break;
91 case ArchivedMetric::AGGREGATION_SUM;
92 $prefix = ArchivedMetric::AGGREGATION_SUM_PREFIX;
93 $translatedName = Piwik::translate('General_ComputedMetricSum', $dimension->getNamePlural());
94 $documentation = Piwik::translate('General_ComputedMetricSumDocumentation', $dimension->getNamePlural());
95 break;
96 case ArchivedMetric::AGGREGATION_MAX;
97 $prefix = ArchivedMetric::AGGREGATION_MAX_PREFIX;
98 $translatedName = Piwik::translate('General_ComputedMetricMax', $dimension->getNamePlural());
99 $documentation = Piwik::translate('General_ComputedMetricMaxDocumentation', $dimension->getNamePlural());
100 break;
101 case ArchivedMetric::AGGREGATION_MIN;
102 $prefix = ArchivedMetric::AGGREGATION_MIN_PREFIX;
103 $translatedName = Piwik::translate('General_ComputedMetricMin', $dimension->getNamePlural());
104 $documentation = Piwik::translate('General_ComputedMetricMinDocumentation', $dimension->getNamePlural());
105 break;
106 case ArchivedMetric::AGGREGATION_UNIQUE;
107 $prefix = ArchivedMetric::AGGREGATION_UNIQUE_PREFIX;
108 $translatedName = Piwik::translate('General_ComputedMetricUniqueCount', $dimension->getNamePlural());
109 $documentation = Piwik::translate('General_ComputedMetricUniqueCountDocumentation', $dimension->getNamePlural());
110 break;
111 case ArchivedMetric::AGGREGATION_COUNT_WITH_NUMERIC_VALUE;
112 $prefix = ArchivedMetric::AGGREGATION_COUNT_WITH_NUMERIC_VALUE_PREFIX;
113 $translatedName = Piwik::translate('General_ComputedMetricCountWithValue', $dimension->getName());
114 $documentation = Piwik::translate('General_ComputedMetricCountWithValueDocumentation', $dimension->getName());
115 break;
116 }
117
118 $metricId = strtolower($dimension->getMetricId());
119
120 return $this->createCustomMetric($prefix . $metricId, $translatedName, $aggregation, $documentation);
121 }
122 }