-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenuItem.php
94 lines (90 loc) · 2.1 KB
/
menuItem.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
<?php
/**
* Menu item (entry) for the module.
*
* Allows incjectiong either a single menu item or an item with submenu (sub-entries).
* So this is basically li or li > ul.
*
* @author Maciej Nux Jaros
*/
class MenuItem
{
/**
* Module name as set by __construct().
* @readonly
* @var string
*/
public $moduleName;
/**
* Title of the module shown to the user in menu.
* @var string
*/
public $title;
/**
* [optional] A number used to order main menu items (if not given then sorting by module name).
* @var int|null
*/
public $order = null;
/**
* [optional] Custom URL (i.e. not linking to a module).
* @var string|null
*/
public $url = null;
/**
* [optional] Users allowed to use this module/action
*
* Use 'anon' or keep `null` to allow anonymous access.
* To be more exact `null` means any authorized user OR anon can access module.
* Setting to 'anon' would mean only anonymous access is allowed.
*
* @var string
*/
public $users = null;
/**
* Submenu items.
* @readonly Use addSubItem instead.
* @var array
*/
public $submenu = array();
/**
* @param type $moduleName Keep it set autmatically as a dirname of the module; unless you have a realy good reason not too ;-)
*/
public function __construct($moduleName)
{
$this->moduleName = $moduleName;
}
/**
* Add (append) submenu item.
* @param type $action Action name.
* @param type $title Title (if empty then the same as action).
*/
public function addSubItem($action, $title='')
{
if (empty($title))
{
$title = $action;
}
$this->submenu[] = array (
'action' => $action,
'title' => $title,
);
}
/**
* Check if given user name is authorized to view the menu/module.
*
* @note This does NOT check if user is logged in or anything like that. This just checks settings.
*/
public function authCheck($userName)
{
if (is_null($this->users))
{
return true;
}
$users = explode(',', $this->users);
if (in_array($userName, $users))
{
return true;
}
return false;
}
}