File: Get.php

package info (click to toggle)
matomo 5.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 95,068 kB
  • sloc: php: 289,425; xml: 127,249; javascript: 112,130; python: 202; sh: 178; makefile: 20; sql: 10
file content (110 lines) | stat: -rw-r--r-- 4,095 bytes parent folder | download | duplicates (2)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php

/**
 * Matomo - free/libre analytics platform
 *
 * @link    https://matomo.org
 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Plugins\PagePerformance\Reports;

use Piwik\EventDispatcher;
use Piwik\Piwik;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\CoreVisualizations\Visualizations\Sparklines;
use Piwik\Plugins\PagePerformance\Metrics;
use Piwik\Plugins\PagePerformance\Visualizations\JqplotGraph\StackedBarEvolution;
use Piwik\Plugins\PagePerformance\Visualizations\PerformanceColumns;
use Piwik\Report\ReportWidgetFactory;
use Piwik\Url;
use Piwik\Widget\WidgetsList;

class Get extends \Piwik\Plugin\Report
{
    protected function init()
    {
        parent::init();

        $this->dimension = null;
        $this->categoryId = 'General_Actions';
        $this->subcategoryId = 'PagePerformance_Performance';
        $this->order = 5;

        $this->name = Piwik::translate('PagePerformance_Overview');
        $this->documentation = Piwik::translate('PagePerformance_OverviewDocumentation');
        $this->onlineGuideUrl = Url::addCampaignParametersToMatomoLink('https://matomo.org/faq/how-to/how-do-i-see-page-performance-reports/');
        $this->processedMetrics = Metrics::getAllPagePerformanceMetrics();
        $this->metrics = Metrics::getAllPagePerformanceMetrics();
    }

    public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $factory)
    {
        $config = $factory->createWidget();
        $config->forceViewDataTable(StackedBarEvolution::ID);
        $config->setAction('getEvolutionGraph');
        $config->setOrder(1);
        $config->setName('PagePerformance_EvolutionOverPeriod');
        $widgetsList->addWidgetConfig($config);

        $config = $factory->createWidget();
        $config->forceViewDataTable(Sparklines::ID);
        $config->setName('');
        $config->setIsNotWidgetizable();
        $config->setOrder(2);
        $widgetsList->addWidgetConfig($config);

        $config = $factory->createWidget();
        $config->forceViewDataTable(PerformanceColumns::ID);
        $config->setModule('Actions');
        $config->setAction('getPageUrls');
        $config->setName('Actions_PageUrls');
        $config->setOrder(3);
        // set an additional parameter so we can use that in the report to check if we are in a report on the performance page
        $config->addParameters(['performance' => 1]);
        $config->setIsNotWidgetizable();
        $config->setIsWide();
        $widgetsList->addWidgetConfig($config);

        $config = $factory->createWidget();
        $config->forceViewDataTable(PerformanceColumns::ID);
        $config->setModule('Actions');
        $config->setAction('getPageTitles');
        $config->setName('Actions_SubmenuPageTitles');
        $config->setOrder(4);
        // set an additional parameter so we can use that in the report to check if we are in a report on the performance page
        $config->addParameters(['performance' => 1]);
        $config->setIsWide();
        $config->setIsNotWidgetizable();
        $widgetsList->addWidgetConfig($config);
    }

    public function configureView(ViewDataTable $view)
    {
        if (
            $view->isViewDataTableId(Sparklines::ID)
            && $view instanceof Sparklines
        ) {
            $this->addSparklineColumns($view);

            $view->config->columns_to_display = array_keys(Metrics::getAllPagePerformanceMetrics());
            $view->config->setNotLinkableWithAnyEvolutionGraph();
            $this->configureFooterMessage($view);
        }
    }

    private function addSparklineColumns(Sparklines $view)
    {
        $count = 0;
        foreach ($this->getMetrics() as $metric => $translation) {
            $view->config->addSparklineMetric([$metric], $count++);
        }
    }

    private function configureFooterMessage(ViewDataTable $view)
    {
        $out = '';
        EventDispatcher::getInstance()->postEvent('Template.afterPagePerformanceReport', array(&$out));
        $view->config->show_footer_message = $out;
    }
}