blob: 6bcc1ba35cf30bcff5fc913308a191dced55b74a (
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
|
<?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\Category;
use Piwik\Piwik;
/**
* Base type for category. lets you change the name for a categoryId and specify a different order
* so the category appears eg at a different order in the reporting menu.
*
* This class is for now not exposed as public API until needed. Categories of plugins will be automatically
* displayed in the menu at the very right after all core categories.
*/
class Category
{
/**
* The id of the category as specified eg in {@link Piwik\Widget\WidgetConfig::setCategoryId()`} or
* {@link Piwik\Report\getCategoryId()}. The id is used as the name in the menu and will be visible in the
* URL.
*
* @var string Should be a translation key, eg 'General_Vists'
*/
protected $id = '';
/**
* @var Subcategory[]
*/
protected $subcategories = array();
/**
* The order of the category. The lower the value the further left the category will appear in the menu.
* @var int
*/
protected $order = 99;
/**
* The icon for this category, eg 'icon-user'
* @var int
*/
protected $icon = '';
/**
* @param int $order
* @return static
*/
public function setOrder($order)
{
$this->order = (int) $order;
return $this;
}
public function getOrder()
{
return $this->order;
}
public function setId($id)
{
$this->id = $id;
return $this;
}
public function getId()
{
return $this->id;
}
public function getDisplayName()
{
return Piwik::translate($this->getId());
}
public function addSubcategory(Subcategory $subcategory)
{
$subcategoryId = $subcategory->getId();
if ($this->hasSubcategory($subcategoryId)) {
throw new \Exception(sprintf('Subcategory %s already exists', $subcategoryId));
}
$this->subcategories[$subcategoryId] = $subcategory;
}
public function hasSubcategory($subcategoryId)
{
return isset($this->subcategories[$subcategoryId]);
}
public function getSubcategory($subcategoryId)
{
if ($this->hasSubcategory($subcategoryId)) {
return $this->subcategories[$subcategoryId];
}
}
/**
* @return Subcategory[]
*/
public function getSubcategories()
{
return array_values($this->subcategories);
}
public function hasSubCategories()
{
return !empty($this->subcategories);
}
public function setIcon($icon)
{
$this->icon = $icon;
return $this;
}
public function getIcon()
{
return $this->icon;
}
}
|