2 namespace wcf\data\user\menu\item
;
3 use wcf\data\ITitledObject
;
4 use wcf\data\ProcessibleDatabaseObject
;
5 use wcf\system\menu\user\DefaultUserMenuItemProvider
;
6 use wcf\system\menu\user\IUserMenuItemProvider
;
7 use wcf\system\menu\ITreeMenuItem
;
8 use wcf\system\request\LinkHandler
;
13 * Represents an user menu item.
15 * @author Alexander Ebert
16 * @copyright 2001-2019 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package WoltLabSuite\Core\Data\User\Menu\Item
20 * @property-read integer $menuItemID unique id of the user menu item
21 * @property-read integer $packageID id of the package the which delivers the user menu item
22 * @property-read string $menuItem textual identifier of the user menu item
23 * @property-read string $parentMenuItem textual identifier of the menu item's parent menu item or empty if it has no parent menu item
24 * @property-read string $menuItemController class name of the user menu item's controller used to generate menu item link
25 * @property-read string $menuItemLink additional part of the user menu item link if `$menuItemController` is set or external link
26 * @property-read integer $showOrder position of the user menu item in relation to its siblings
27 * @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
28 * @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
29 * @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
30 * @property-read string $iconClassName FontAwesome CSS class name for user menu items on the first level
32 class UserMenuItem
extends ProcessibleDatabaseObject
implements ITitledObject
, ITreeMenuItem
{
36 protected static $databaseTableIndexName = 'menuItemID';
41 protected static $processorInterface = IUserMenuItemProvider
::class;
44 * application abbreviation
47 protected $application = '';
50 * menu item controller
53 protected $controller = null;
58 public function getProcessor() {
59 if (parent
::getProcessor() === null) {
60 $this->processor
= new DefaultUserMenuItemProvider($this);
63 return $this->processor
;
69 public function getLink() {
71 if (!$this->menuItemController
) {
72 return $this->menuItemLink
;
75 $this->parseController();
76 return LinkHandler
::getInstance()->getLink($this->controller
, ['application' => $this->application
], $this->menuItemLink
);
83 public function getTitle() {
84 return WCF
::getLanguage()->get($this->menuItem
);
88 * Returns application abbreviation.
92 public function getApplication() {
93 $this->parseController();
95 return $this->application
;
99 * Returns controller name.
103 public function getController() {
104 $this->parseController();
106 return $this->controller
;
110 * Parses controller name.
112 protected function parseController() {
113 if ($this->controller
=== null) {
114 $this->controller
= '';
116 // resolve application and controller
117 if ($this->menuItemController
) {
118 $parts = explode('\\', $this->menuItemController
);
119 $this->application
= array_shift($parts);
120 $menuItemController = array_pop($parts);
122 // drop controller suffix
123 $this->controller
= Regex
::compile('(Action|Form|Page)$')->replace($menuItemController, '');
129 * Returns the menu item name.
133 public function __toString() {
134 return WCF
::getLanguage()->getDynamicVariable($this->menuItem
);
138 * Returns FontAwesome icon class name.
142 public function getIconClassName() {
143 return ($this->iconClassName ?
: 'fa-bars');