2 namespace wcf\data\user\menu\item
;
3 use wcf\data\ProcessibleDatabaseObject
;
4 use wcf\system\menu\user\DefaultUserMenuItemProvider
;
5 use wcf\system\menu\user\IUserMenuItemProvider
;
6 use wcf\system\menu\ITreeMenuItem
;
7 use wcf\system\request\LinkHandler
;
12 * Represents an user menu item.
14 * @author Alexander Ebert
15 * @copyright 2001-2018 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\Data\User\Menu\Item
19 * @property-read integer $menuItemID unique id of the user menu item
20 * @property-read integer $packageID id of the package the which delivers the user menu item
21 * @property-read string $menuItem textual identifier of the user menu item
22 * @property-read string $parentMenuItem textual identifier of the menu item's parent menu item or empty if it has no parent menu item
23 * @property-read string $menuItemController class name of the user menu item's controller used to generate menu item link
24 * @property-read string $menuItemLink additional part of the user menu item link if `$menuItemController` is set or external link
25 * @property-read integer $showOrder position of the user menu item in relation to its siblings
26 * @property-read string $permissions comma separated list of user group permissions of which the active user needs to have at least one to see the user menu item
27 * @property-read string $options comma separated list of options of which at least one needs to be enabled for the user menu item to be shown
28 * @property-read string $className name of the class implementing the user menu item provider interface or empty if there is no specific user menu item provider
29 * @property-read string $iconClassName FontAwesome CSS class name for user menu items on the first level
31 class UserMenuItem
extends ProcessibleDatabaseObject
implements ITreeMenuItem
{
35 protected static $databaseTableIndexName = 'menuItemID';
40 protected static $processorInterface = IUserMenuItemProvider
::class;
43 * application abbreviation
46 protected $application = '';
49 * menu item controller
52 protected $controller = null;
57 public function getProcessor() {
58 if (parent
::getProcessor() === null) {
59 $this->processor
= new DefaultUserMenuItemProvider($this);
62 return $this->processor
;
68 public function getLink() {
70 if (!$this->menuItemController
) {
71 return $this->menuItemLink
;
74 $this->parseController();
75 return LinkHandler
::getInstance()->getLink($this->controller
, ['application' => $this->application
], $this->menuItemLink
);
79 * Returns application abbreviation.
83 public function getApplication() {
84 $this->parseController();
86 return $this->application
;
90 * Returns controller name.
94 public function getController() {
95 $this->parseController();
97 return $this->controller
;
101 * Parses controller name.
103 protected function parseController() {
104 if ($this->controller
=== null) {
105 $this->controller
= '';
107 // resolve application and controller
108 if ($this->menuItemController
) {
109 $parts = explode('\\', $this->menuItemController
);
110 $this->application
= array_shift($parts);
111 $menuItemController = array_pop($parts);
113 // drop controller suffix
114 $this->controller
= Regex
::compile('(Action|Form|Page)$')->replace($menuItemController, '');
120 * Returns the menu item name.
124 public function __toString() {
125 return WCF
::getLanguage()->getDynamicVariable($this->menuItem
);
129 * Returns FontAwesome icon class name.
133 public function getIconClassName() {
134 return ($this->iconClassName ?
: 'fa-bars');