This repository was archived by the owner on Oct 31, 2018. It is now read-only.
forked from matomo-org/plugin-CustomDimensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.php
More file actions
106 lines (88 loc) · 3.5 KB
/
Menu.php
File metadata and controls
106 lines (88 loc) · 3.5 KB
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
<?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\CustomDimensions;
use Piwik\Common;
use Piwik\Menu\Group;
use Piwik\Menu\MenuReporting;
use Piwik\Menu\MenuUser;
use Piwik\Piwik;
use Piwik\Plugins\CustomDimensions\Dao\Configuration;
use Piwik\Plugins\UsersManager\UserPreferences;
/**
* This class allows you to add, remove or rename menu items.
* To configure a menu (such as Admin Menu, Reporting Menu, User Menu...) simply call the corresponding methods as
* described in the API-Reference http://developer.piwik.org/api-reference/Piwik/Menu/MenuAbstract
*/
class Menu extends \Piwik\Plugin\Menu
{
public function configureUserMenu(MenuUser $menu)
{
$userPreferences = new UserPreferences();
$default = $userPreferences->getDefaultWebsiteId();
$idSite = Common::getRequestVar('idSite', $default, 'int');
if (Piwik::isUserHasAdminAccess($idSite)) {
$menu->addManageItem('CustomDimensions_CustomDimensions', $this->urlForAction('manage'), $orderId = 16);
}
}
public function configureReportingMenu(MenuReporting $menu)
{
$idSite = Common::getRequestVar('idSite', null, 'int');
$config = new Configuration();
$dimensions = $config->getCustomDimensionsForSite($idSite);
foreach ($dimensions as $index => $dimension) {
if (!$dimension['active']) {
unset($dimensions[$index]);
}
}
$this->addMenuItemsForCustomDimensions($menu, $dimensions, CustomDimensions::SCOPE_VISIT);
$this->addMenuItemsForCustomDimensions($menu, $dimensions, CustomDimensions::SCOPE_ACTION);
}
private function addMenuItemsForCustomDimensions(MenuReporting $menu, $dimensions, $scope)
{
$numItems = 0;
foreach ($dimensions as $dimension) {
if ($scope === $dimension['scope']) {
$numItems++;
}
}
$group = new Group();
$mainMenuName = '';
if ($scope === CustomDimensions::SCOPE_VISIT) {
$mainMenuName = 'General_Visitors';
} elseif ($scope === CustomDimensions::SCOPE_ACTION) {
$mainMenuName = 'General_Actions';
}
foreach ($dimensions as $dimension) {
if ($dimension['scope'] !== $scope) {
continue;
}
$name = $dimension['name'];
$id = $dimension['idcustomdimension'];
$url = $this->urlForAction('menuGetCustomDimension', array('idDimension' => $id));
$order = 100 + $id;
$tooltip = Piwik::translate('CustomDimensions_CustomDimensionId', $id);
if ($scope === CustomDimensions::SCOPE_VISIT) {
if ($numItems > 3) {
$group->add($name, $url, $tooltip);
} else {
$menu->addVisitorsItem($name, $url, $order, $tooltip);
}
} elseif ($scope === CustomDimensions::SCOPE_ACTION) {
if ($numItems > 3) {
$group->add($name, $url, $tooltip);
} else {
$menu->addActionsItem($name, $url, $order, $tooltip);
}
}
if ($numItems > 3) {
$title = Piwik::translate('CustomDimensions_CustomDimensions');
$menu->addGroup($mainMenuName, $title, $group, ++$order, $tooltip = false);
}
}
}
}