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

VisitsSummary.php « VisitsSummary « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 466808c17355083c840f081bb18ea688c5c3b8dc (plain)
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
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */
namespace Piwik\Plugins\VisitsSummary;
use Piwik\DataTable;
use Piwik\Plugins\CoreHome\Columns\UserId;
use Piwik\Plugins\VisitsSummary\Reports\Get;

/**
 * Note: This plugin does not hook on Daily and Period Archiving like other Plugins because it reports the
 * very core metrics (visits, actions, visit duration, etc.) which are processed in the Core
 * Day class directly.
 * These metrics can be used by other Plugins so they need to be processed up front.
 *
 */
class VisitsSummary extends \Piwik\Plugin
{
    /**
     * @see Piwik\Plugin::registerEvents
     */
    public function registerEvents()
    {
        return array(
            'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
            'API.API.getProcessedReport.end' => 'enrichProcessedReportIfVisitsSummaryGet',
        );
    }

    private function isRequestingVisitsSummaryGet($module, $method)
    {
        return ($module === 'VisitsSummary' && $method === 'get');
    }

    public function enrichProcessedReportIfVisitsSummaryGet(&$response, $infos)
    {
        if (empty($infos['parameters']['apiAction']) || empty($response['reportData'])) {
            return;
        }

        $params  = $infos['parameters'];
        $idSites = array($params['idSite']);
        $period  = $params['period'];
        $date    = $params['date'];
        $module  = $params['apiModule'];
        $method  = $params['apiAction'];

        if (!$this->isRequestingVisitsSummaryGet($module, $method)) {
            return;
        }

        $userId = new UserId();

        /** @var DataTable|DataTable\Map $dataTable */
        $dataTable = $response['reportData'];

        if (!$userId->hasDataTableUsers($dataTable) &&
            !$userId->isUsedInAtLeastOneSite($idSites, $period, $date)) {
            $report = new Get();
            $report->removeUsersFromProcessedReport($response);
        }
    }

    public function getStylesheetFiles(&$stylesheets)
    {
        $stylesheets[] = "plugins/VisitsSummary/stylesheets/datatable.less";
    }

}