-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuickMenuButton.php
130 lines (108 loc) · 3.1 KB
/
QuickMenuButton.php
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
<?php
/**
* Local exception
*/
class QuickMenuException extends CException {}
/**
* Small class for buttons. Basically just an
* array wrapper with some default values.
*
* Implements ArrayAccess so core code can
* use it as an array.
*
* @todo Put this in core?
*/
class QuickMenuButton implements ArrayAccess {
/**
* @var string - href in anchor
*/
public $href;
/**
* @var string - String in tooltip. Empty string means no tooltip
*/
public $tooltip = '';
/**
* @var string - Class with glyphicon
*/
public $iconClass;
/**
* @var string - Button name
*/
public $name;
/**
* @var int - Order sorting
*/
public $order = 0;
/**
* @var bool - Whether or not to open link in new tab
*/
public $openInNewTab = false;
/**
* @var bool - Whether or not to show button only when survey is active
*/
public $showOnlyWhenSurveyIsActivated = false;
/**
* @var bool - Whether or not to show button only when survey is non-active
*/
public $showOnlyWhenSurveyIsDeactivated = false;
/**
* @var array<string> - Tuple with permission category and right, e.g. array("survey", "read")
* Null means available for all.
*/
public $neededPermission = null;
/**
* $options is an array of settings for the button
*
* @param array<string, mixed> $options
* @return QuickMenuButton
*/
public function __construct($options) {
$this->href = $options['href'];
$this->tooltip = $options['tooltip'];
$this->iconClass = $options['iconClass'];
$this->name = $options['name'];
if (isset($options['openInNewTab'])) {
$this->openInNewTab = $options['openInNewTab'];
}
if (isset($options['showOnlyWhenSurveyIsActivated']))
{
$this->showOnlyWhenSurveyIsActivated = $options['showOnlyWhenSurveyIsActivated'];
}
if (isset($options['showOnlyWhenSurveyIsDeactivated']))
{
$this->showOnlyWhenSurveyIsDeactivated = $options['showOnlyWhenSurveyIsDeactivated'];
}
if (isset($options['neededPermission']))
{
if (count($options['neededPermission']) !== 2)
{
throw new InvalidArgumentException("Option neededPermission must have length 2 (permission category and right)");
}
$this->neededPermission = $options['neededPermission'];
}
}
public function setOrder($order)
{
$this->order = $order;
}
public function offsetExists($offset)
{
throw new QuickMenuException("Can't check if offset exists for QuickMenuButton");
}
/**
* @param mixed $offset
* @return mixed
*/
public function offsetGet($offset)
{
return $this->$offset;
}
public function offsetSet($offset, $value)
{
throw new QuickMenuException("Can't set offset for QuickMenuButton");
}
public function offsetUnset($offset)
{
throw new QuickMenuException("Can't unset offset for QuickMenuButton");
}
}