blob: f8b94dc97afdaacc6359234b7b7e15f9d804c5fa (
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
|
<?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\SitesManager;
use Piwik\Menu\MenuAdmin;
use Piwik\Piwik;
use Piwik\Measurable\Type\TypeManager;
use Piwik\Plugins\WebsiteMeasurable;
class Menu extends \Piwik\Plugin\Menu
{
private $typeManager;
public function __construct(TypeManager $typeManager)
{
$this->typeManager = $typeManager;
}
public function configureAdminMenu(MenuAdmin $menu)
{
if (Piwik::hasUserSuperUserAccess()) {
$menu->addMeasurableItem('General_Settings', $this->urlForAction('globalSettings'), $order = 11);
}
if (Piwik::isUserHasSomeAdminAccess() && SitesManager::isSitesAdminEnabled()) {
$menu->addMeasurableItem('SitesManager_MenuManage', $this->urlForAction('index'), $order = 10);
$type = $this->getFirstTypeIfOnlyOneIsInUse();
if ($type) {
$menu->rename('CoreAdminHome_MenuMeasurables', $subMenuOriginal = null, $type->getNamePlural(), $subMenuRenamed = null);
}
}
}
private function getFirstTypeIfOnlyOneIsInUse()
{
$types = $this->typeManager->getAllTypes();
if (count($types) === 1) {
// only one type is in use, use this one for the wording
return reset($types);
} else {
// multiple types are activated, check whether only one is actually in use
$model = new Model();
$typeIds = $model->getUsedTypeIds();
if (count($typeIds) === 1) {
$typeManager = new TypeManager();
return $typeManager->getType(reset($typeIds));
}
}
}
}
|