From 5773706aa201b003ad10790de4d67b2709e802fa Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Wed, 8 Jan 2014 00:41:57 +0000 Subject: [PATCH 1/2] refs #1486 added some methods needed in CustomAlerts plugin to validate report and metric is still valid --- plugins/API/ProcessedReport.php | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php index 910623a8589..51af2ecddd4 100644 --- a/plugins/API/ProcessedReport.php +++ b/plugins/API/ProcessedReport.php @@ -64,6 +64,77 @@ public function getMetadata($idSite, $apiModule, $apiAction, $apiParameters = ar return false; } + /** + * Verfies whether the given report exists for the given site. + * + * @param int $idSite + * @param string $apiModule For example 'MultiSites' + * @param string $apiAction For example 'getAll' + * + * @return bool + */ + public function isValidReportForSite($idSite, $apiModule, $apiAction) + { + $report = $this->getSingleReportMetadata($idSite, $apiModule, $apiAction); + + return !empty($report); + } + + /** + * Verfies whether the given metric belongs to the given report. + * + * @param int $idSite + * @param string $metric For example 'nb_visits' + * @param string $apiModule For example 'MultiSites' + * @param string $apiAction For example 'getAll' + * + * @return bool + */ + public function isValidMetricForReport($metric, $idSite, $apiModule, $apiAction) + { + $translation = $this->translateMetric($metric, $idSite, $apiModule, $apiAction); + + return !empty($translation); + } + + private function getSingleReportMetadata($idSite, $apiModule, $apiAction) + { + $metadata = $this->getMetadata($idSite, $apiModule, $apiAction); + + if (empty($metadata)) { + return false; + } + + return array_shift($metadata); + } + + /** + * Translates the given metric in case the report exists and in case the metric acutally belongs to the report. + * + * @param string $metric For example 'nb_visits' + * @param int $idSite + * @param string $apiModule For example 'MultiSites' + * @param string $apiAction For example 'getAll' + * + * @return null|string + */ + public function translateMetric($metric, $idSite, $apiModule, $apiAction) + { + $report = $this->getSingleReportMetadata($idSite, $apiModule, $apiAction); + + if (empty($report)) { + return; + } + + $properties = array('metrics', 'processedMetrics', 'processedMetricsGoal'); + + foreach ($properties as $prop) { + if (!empty($report[$prop]) && is_array($report[$prop]) && array_key_exists($metric, $report[$prop])) { + return $report[$prop][$metric]; + } + } + } + /** * Triggers a hook to ask plugins for available Reports. * Returns metadata information about each report (category, name, dimension, metrics, etc.) From b0b5ccc2e0525d909fde627d813097bd7a3f61d7 Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Wed, 8 Jan 2014 00:44:23 +0000 Subject: [PATCH 2/2] updated submodule --- plugins/CustomAlerts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/CustomAlerts b/plugins/CustomAlerts index bbb1d175971..71facccd325 160000 --- a/plugins/CustomAlerts +++ b/plugins/CustomAlerts @@ -1 +1 @@ -Subproject commit bbb1d1759717d51c9b4de4a4a96e98170c0bb3f0 +Subproject commit 71facccd325cd8603a132b6358e7eee8abef8f04