Apply PSR-12 code style (#3886)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / menu / user / UserMenu.class.php
1 <?php
2
3 namespace wcf\system\menu\user;
4
5 use wcf\data\user\menu\item\UserMenuItem;
6 use wcf\system\cache\builder\UserMenuCacheBuilder;
7 use wcf\system\menu\ITreeMenuItem;
8 use wcf\system\menu\TreeMenu;
9 use wcf\system\option\user\UserOptionHandler;
10 use wcf\system\WCF;
11
12 /**
13 * Builds the user menu.
14 *
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\System\Menu\User
19 */
20 class UserMenu extends TreeMenu
21 {
22 /**
23 * user option handler for the `settings` category
24 * @var UserOptionHandler
25 */
26 protected $optionHandler;
27
28 /**
29 * @inheritDoc
30 */
31 protected function loadCache()
32 {
33 parent::loadCache();
34
35 $this->menuItems = UserMenuCacheBuilder::getInstance()->getData();
36 $this->optionHandler = new UserOptionHandler(false, '', 'settings');
37 $this->optionHandler->setUser(WCF::getUser());
38 }
39
40 /**
41 * @inheritDoc
42 */
43 protected function checkMenuItem(ITreeMenuItem $item)
44 {
45 /** @var UserMenuItem $item */
46
47 if (!parent::checkMenuItem($item)) {
48 return false;
49 }
50
51 // Hide links to user option categories without accessible options.
52 if (\strpos($item->menuItem, 'wcf.user.option.category.') === 0) {
53 $categoryName = \str_replace('wcf.user.option.category.', '', $item->menuItem);
54 if (!$this->optionHandler->countCategoryOptions($categoryName)) {
55 return false;
56 }
57 }
58
59 return $item->getProcessor()->isVisible();
60 }
61 }