1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\CoreVisualizations\Widgets;
use Piwik\API\Request;
use Piwik\Common;
use Piwik\View;
use Piwik\Widget\WidgetConfig;
use Piwik\Plugin\Manager as PluginManager;
use Piwik\Plugins\Goals\API as GoalsAPI;
class SingleMetricView extends \Piwik\Widget\Widget
{
public static function configure(WidgetConfig $config)
{
parent::configure($config);
$column = Common::getRequestVar('column', '', 'string');
$config->addParameters(['column' => $column]);
$config->setCategoryId('General_Generic');
$config->setName('General_Metric');
$config->setIsWidgetizable();
}
public function render()
{
$column = Common::getRequestVar('column', 'nb_visits', 'string');
$goalMetrics = [];
$goals = [];
$idSite = Common::getRequestVar('idSite');
$idGoal = Common::getRequestVar('idGoal', false);
$reportMetadata = Request::processRequest('API.getMetadata', [
'idSites' => $idSite,
'apiModule' => 'API',
'apiAction' => 'get',
]);
$reportMetadata = reset($reportMetadata);
$metricTranslations = array_merge($reportMetadata['metrics'], $reportMetadata['processedMetrics']);
$metricDocumentations = $reportMetadata['metricsDocumentation'];
if (PluginManager::getInstance()->isPluginActivated('Goals')) {
$reportMetadata = Request::processRequest('API.getMetadata', [
'idSites' => $idSite,
'apiModule' => 'Goals',
'apiAction' => 'get',
]);
$reportMetadata = reset($reportMetadata);
$goalMetrics = array_merge(
array_keys($reportMetadata['metrics']),
array_keys($reportMetadata['processedMetrics'])
);
$metricDocumentations = array_merge($metricDocumentations, $reportMetadata['metricsDocumentation']);
$goals = GoalsAPI::getInstance()->getGoals($idSite);
}
$view = new View("@CoreHome/_angularComponent.twig");
$view->componentName = 'piwik-single-metric-view';
$view->componentParameters = [
'metric' => json_encode($column),
'id-goal' => $idGoal === false ? 'undefined' : $idGoal,
'goal-metrics' => json_encode($goalMetrics),
'goals' => json_encode($goals),
'metric-translations' => json_encode($metricTranslations),
'metric-documentations' => json_encode($metricDocumentations),
];
return $view->render();
}
}
|