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

Tour.php « Tour « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bda6e4144560304ae54477aceec00da7b0b5331a (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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
 * Matomo - 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\Tour;

use Piwik\Common;
use Piwik\Container\StaticContainer;
use Piwik\Piwik;
use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution;
use Piwik\Plugins\CoreVisualizations\Visualizations\Sparkline;
use Piwik\Plugins\Tour\Engagement\Challenge;
use Piwik\Plugins\Tour\Engagement\ChallengeAddedAnnotation;
use Piwik\Plugins\Tour\Engagement\ChallengeAddedUser;
use Piwik\Plugins\Tour\Engagement\ChallengeBrowseMarketplace;
use Piwik\Plugins\Tour\Engagement\ChallengeChangeVisualisation;
use Piwik\Plugins\Tour\Engagement\ChallengeCreatedGoal;
use Piwik\Plugins\Tour\Engagement\ChallengeFlattenActions;
use Piwik\Plugins\Tour\Engagement\ChallengeSelectDateRange;
use Piwik\Plugins\Tour\Engagement\ChallengeViewRowEvolution;
use Piwik\Plugins\Tour\Engagement\ChallengeViewVisitorProfile;
use Piwik\Plugins\Tour\Engagement\ChallengeViewVisitsLog;

class Tour extends \Piwik\Plugin
{

    public function registerEvents()
    {
        return array(
            'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
            'AssetManager.getJavaScriptFiles' => 'getJsFiles',
            'Dashboard.changeDefaultDashboardLayout' => 'changeDefaultDashboardLayout',
            'API.Annotations.add.end' => 'onAnnotationAdded',
            'API.Goals.addGoal.end' => 'onGoalAdded',
            'API.UsersManager.addUser' => 'onUserAdded',
            'Controller.CoreHome.getRowEvolutionPopover' => 'onViewRowEvolution',
            'Controller.Live.getLastVisitsDetails' => 'onViewVisitorLog',
            'Controller.Live.getVisitorProfilePopup' => 'onViewVisitorProfile',
            'Controller.Marketplace.overview' => 'onBrowseMarketplace',
            'ViewDataTable.configure' => array('function' => 'onConfigureView', 'after' => true),
        );
    }

    public function onBrowseMarketplace()
    {
        $this->setSimpleChallengeCompleted(ChallengeBrowseMarketplace::class);
    }

    public function onConfigureView()
    {
        if (Common::getRequestVar('period', '', 'string') === 'range') {
            $this->setSimpleChallengeCompleted(ChallengeSelectDateRange::class);
        }

        if (Common::getRequestVar('flat', '0', 'string') === '1') {
            $module = Piwik::getModule();
            if ($module === 'Actions' || $module === 'Contents' || $module === 'UsersFlow') {
                $this->setSimpleChallengeCompleted(ChallengeFlattenActions::class);
            }
        }

        $viewDataTable = Common::getRequestVar('viewDataTable', '', 'string');
        if ($viewDataTable && !Common::getRequestVar('forceView', '', 'string')) {
            if ($viewDataTable !== Sparkline::ID && $viewDataTable !== Evolution::ID) {
                // sparkline and graphEvolution may be used without forceView
                $this->setSimpleChallengeCompleted(ChallengeChangeVisualisation::class);
            }
        }
    }

    private function setSimpleChallengeCompleted($className)
    {
        if (Piwik::hasUserSuperUserAccess()) {
            /** @var Challenge $challenge */
            $challenge = StaticContainer::get($className);
            $challenge->setCompleted();
        }
    }

    public function onViewRowEvolution()
    {
        $this->setSimpleChallengeCompleted(ChallengeViewRowEvolution::class);
    }

    public function onViewVisitorLog()
    {
        $this->setSimpleChallengeCompleted(ChallengeViewVisitsLog::class);
    }

    public function onViewVisitorProfile()
    {
        $this->setSimpleChallengeCompleted(ChallengeViewVisitorProfile::class);
    }

    public function onAnnotationAdded($response)
    {
        if (Piwik::hasUserSuperUserAccess() && !empty($response)) {
            $annotation = new ChallengeAddedAnnotation();
            $annotation->setCompleted();
        }
    }

    public function onGoalAdded($response)
    {
        if (Piwik::hasUserSuperUserAccess() && !empty($response)) {
            $annotation = new ChallengeCreatedGoal();
            $annotation->setCompleted();
        }
    }

    public function onUserAdded($response)
    {
        if (Piwik::hasUserSuperUserAccess()) {
            $annotation = new ChallengeAddedUser();
            $annotation->setCompleted();
        }
    }

    public function changeDefaultDashboardLayout(&$defaultLayout)
    {
        if (Piwik::hasUserSuperUserAccess()) {
            $defaultLayout = json_decode($defaultLayout, true);
            $engagementWidget = array('uniqueId' => 'widgetTourgetEngagement', 'parameters' => array('module' => 'Tour', 'action' => 'getEngagement'));
            if (is_array($defaultLayout) && isset($defaultLayout[2]) && is_array($defaultLayout[2])) {
                array_unshift($defaultLayout[2], $engagementWidget);
            }
            $defaultLayout = json_encode($defaultLayout);
        }
    }

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

    public function getJsFiles(&$jsFiles)
    {
        $jsFiles[] = "plugins/Tour/javascripts/engagement.js";
    }
}