PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.13.0 5.12.1 5.12.0 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 2 years ago ComputedMetricFactory.php 2 years ago Dimension.php 2 years ago DimensionMetricFactory.php 2 years ago DimensionSegmentFactory.php 2 years ago DimensionsProvider.php 2 years ago Discriminator.php 2 years ago Join.php 2 years ago MetricsList.php 2 years ago Updater.php 2 years ago
DimensionMetricFactory.php
117 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\Columns;
11
12 use Piwik\Piwik;
13 use Piwik\Plugin\ArchivedMetric;
14 use Piwik\Plugin\ComputedMetric;
15 /**
16 * A factory to create metrics from a dimension.
17 *
18 * @api since Piwik 3.2.0
19 */
20 class DimensionMetricFactory
21 {
22 /**
23 * @var Dimension
24 */
25 private $dimension = null;
26 /**
27 * Generates a new dimension metric factory.
28 * @param Dimension $dimension A dimension instance the created metrics should be based on.
29 */
30 public function __construct(\Piwik\Columns\Dimension $dimension)
31 {
32 $this->dimension = $dimension;
33 }
34 /**
35 * @return ArchivedMetric
36 */
37 public function createCustomMetric($metricName, $readableName, $aggregation, $documentation = '', string $semanticType = null)
38 {
39 if (!$this->dimension->getDbTableName() || !$this->dimension->getColumnName()) {
40 throw new \Exception(sprintf('Cannot make metric from dimension %s because DB table or column missing', $this->dimension->getId()));
41 }
42 $metric = new ArchivedMetric($this->dimension, $aggregation);
43 $metric->setType($semanticType ?: $this->dimension->getType());
44 $metric->setName($metricName);
45 $metric->setTranslatedName($readableName);
46 $metric->setDocumentation($documentation);
47 $metric->setCategory($this->dimension->getCategoryId());
48 return $metric;
49 }
50 /**
51 * @return \Piwik\Plugin\ComputedMetric
52 */
53 public function createComputedMetric($metricName1, $metricName2, $aggregation)
54 {
55 // We cannot use reuse ComputedMetricFactory here as it would result in an endless loop since ComputedMetricFactory
56 // requires a MetricsList which is just being built here...
57 $metric = new ComputedMetric($metricName1, $metricName2, $aggregation);
58 $metric->setCategory($this->dimension->getCategoryId());
59 return $metric;
60 }
61 /**
62 * @return ArchivedMetric
63 */
64 public function createMetric($aggregation)
65 {
66 $dimension = $this->dimension;
67 if (!$dimension->getNamePlural()) {
68 throw new \Exception(sprintf('No metric can be created for this dimension %s automatically because no $namePlural is set.', $dimension->getId()));
69 }
70 $prefix = '';
71 $translatedName = $dimension->getNamePlural();
72 $documentation = '';
73 $semanticType = null;
74 // if null, will default to dimension type
75 switch ($aggregation) {
76 case ArchivedMetric::AGGREGATION_COUNT:
77 $prefix = ArchivedMetric::AGGREGATION_COUNT_PREFIX;
78 $translatedName = $dimension->getNamePlural();
79 $documentation = Piwik::translate('General_ComputedMetricCountDocumentation', $dimension->getNamePlural());
80 $semanticType = \Piwik\Columns\Dimension::TYPE_NUMBER;
81 break;
82 case ArchivedMetric::AGGREGATION_SUM:
83 $prefix = ArchivedMetric::AGGREGATION_SUM_PREFIX;
84 $translatedName = Piwik::translate('General_ComputedMetricSum', $dimension->getNamePlural());
85 $documentation = Piwik::translate('General_ComputedMetricSumDocumentation', $dimension->getNamePlural());
86 if ($dimension->getType() == \Piwik\Columns\Dimension::TYPE_BOOL) {
87 $semanticType = \Piwik\Columns\Dimension::TYPE_NUMBER;
88 }
89 break;
90 case ArchivedMetric::AGGREGATION_MAX:
91 $prefix = ArchivedMetric::AGGREGATION_MAX_PREFIX;
92 $translatedName = Piwik::translate('General_ComputedMetricMax', $dimension->getNamePlural());
93 $documentation = Piwik::translate('General_ComputedMetricMaxDocumentation', $dimension->getNamePlural());
94 break;
95 case ArchivedMetric::AGGREGATION_MIN:
96 $prefix = ArchivedMetric::AGGREGATION_MIN_PREFIX;
97 $translatedName = Piwik::translate('General_ComputedMetricMin', $dimension->getNamePlural());
98 $documentation = Piwik::translate('General_ComputedMetricMinDocumentation', $dimension->getNamePlural());
99 break;
100 case ArchivedMetric::AGGREGATION_UNIQUE:
101 $prefix = ArchivedMetric::AGGREGATION_UNIQUE_PREFIX;
102 $translatedName = Piwik::translate('General_ComputedMetricUniqueCount', $dimension->getNamePlural());
103 $documentation = Piwik::translate('General_ComputedMetricUniqueCountDocumentation', $dimension->getNamePlural());
104 $semanticType = \Piwik\Columns\Dimension::TYPE_NUMBER;
105 break;
106 case ArchivedMetric::AGGREGATION_COUNT_WITH_NUMERIC_VALUE:
107 $prefix = ArchivedMetric::AGGREGATION_COUNT_WITH_NUMERIC_VALUE_PREFIX;
108 $translatedName = Piwik::translate('General_ComputedMetricCountWithValue', $dimension->getName());
109 $documentation = Piwik::translate('General_ComputedMetricCountWithValueDocumentation', $dimension->getName());
110 $semanticType = \Piwik\Columns\Dimension::TYPE_NUMBER;
111 break;
112 }
113 $metricId = strtolower($dimension->getMetricId());
114 return $this->createCustomMetric($prefix . $metricId, $translatedName, $aggregation, $documentation, $semanticType);
115 }
116 }
117