Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <benaka@piwik.pro>2014-11-24 13:20:25 +0300
committerdiosmosis <benaka@piwik.pro>2014-11-24 13:20:25 +0300
commit551413f3d3694830aa0822f7f28e6a33372eff67 (patch)
treebb4a9cebfcd03ee22fdbd4f95d1f55a6ff9b5dc0 /core/Plugin/Report.php
parentc8daaabc8b1dcee3c2db01665ef98dd1883cbf7c (diff)
Move MetricsFormatter::getMetricsToFormat logic to Report class.
Diffstat (limited to 'core/Plugin/Report.php')
-rw-r--r--core/Plugin/Report.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/core/Plugin/Report.php b/core/Plugin/Report.php
index 265ce37bb1..41f3cfcf56 100644
--- a/core/Plugin/Report.php
+++ b/core/Plugin/Report.php
@@ -843,4 +843,52 @@ class Report
}
return $result;
}
+
+ /**
+ * Returns the Metrics that are displayed by a DataTable of a certain Report type.
+ *
+ * Includes ProcessedMetrics and Metrics.
+ *
+ * @param DataTable $dataTable
+ * @param Report|null $report
+ * @param string $baseType The base type each metric class needs to be of.
+ * @return Metric[]
+ * @api
+ */
+ public static function getMetricsForTable(DataTable $dataTable, Report $report = null, $baseType = 'Piwik\\Plugin\\Metric')
+ {
+ $metrics = $dataTable->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME) ?: array();
+
+ if (!empty($report)) {
+ $metrics = array_merge($metrics, $report->getProcessedMetricsById());
+ }
+
+ $result = array();
+
+ /** @var Metric $metric */
+ foreach ($metrics as $metric) {
+ if (!($metric instanceof $baseType)) {
+ continue;
+ }
+
+ $result[$metric->getName()] = $metric;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Returns the ProcessedMetrics that should be computed and formatted for a DataTable of a
+ * certain report. The ProcessedMetrics returned are those specified by the Report metadata
+ * as well as the DataTable metadata.
+ *
+ * @param DataTable $dataTable
+ * @param Report|null $report
+ * @return ProcessedMetric[]
+ * @api
+ */
+ public static function getProcessedMetricsForTable(DataTable $dataTable, Report $report = null)
+ {
+ return self::getMetricsForTable($dataTable, $report, 'Piwik\\Plugin\\ProcessedMetric');
+ }
} \ No newline at end of file