3 namespace wcf\system\cache\builder
;
5 use wcf\acp\form\OptionForm
;
6 use wcf\data\acp\menu\item\ACPMenuItem
;
7 use wcf\data\acp\menu\item\ACPMenuItemList
;
8 use wcf\data\option\category\OptionCategory
;
9 use wcf\data\option\category\OptionCategoryList
;
10 use wcf\data\option\OptionList
;
13 * Caches the ACP menu items.
15 * @author Matthias Schmidt, Marcel Werk
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\Cache\Builder
20 class ACPMenuCacheBuilder
extends AbstractCacheBuilder
23 * list of option categories which directly contain options
26 protected $categoriesWithOptions = [];
29 * list of option categories grouped by the name of their parent category
30 * @var OptionCategory[]
32 protected $categoryStructure = [];
37 public function rebuild(array $parameters)
41 // get "real" menu items
42 $menuItemList = new ACPMenuItemList();
43 $menuItemList->sqlOrderBy
= "acp_menu_item.showOrder";
44 $menuItemList->readObjects();
45 foreach ($menuItemList as $menuItem) {
46 $data[$menuItem->parentMenuItem
][] = $menuItem;
49 // get menu items for top option categories
50 $data['wcf.acp.menu.link.option.category'] = [];
51 foreach ($this->getTopOptionCategories() as $optionCategory) {
52 $data['wcf.acp.menu.link.option.category'][] = new ACPMenuItem(null, [
53 'menuItem' => 'wcf.acp.option.category.' . $optionCategory->categoryName
,
54 'parentMenuItem' => 'wcf.acp.menu.link.option.category',
55 'menuItemController' => OptionForm
::class,
56 'permissions' => $optionCategory->permissions
,
57 'optionCategoryID' => $optionCategory->categoryID
,
58 'options' => $optionCategory->options
,
66 * Returns the list with top option categories which contain options.
68 * @return OptionCategory[]
70 protected function getTopOptionCategories()
72 $optionCategoryList = new OptionCategoryList();
73 $optionCategoryList->readObjects();
74 $optionCategories = $optionCategoryList->getObjects();
76 // build category structure
77 $this->categoryStructure
= [];
78 foreach ($optionCategories as $optionCategory) {
79 if (!isset($this->categoryStructure
[$optionCategory->parentCategoryName
])) {
80 $this->categoryStructure
[$optionCategory->parentCategoryName
] = [];
83 $this->categoryStructure
[$optionCategory->parentCategoryName
][] = $optionCategory;
86 $optionList = new OptionList();
87 $optionList->readObjects();
89 // collect names of categories which contain options
90 foreach ($optionList as $option) {
91 if (!isset($this->categoriesWithOptions
[$option->categoryName
])) {
92 $this->categoriesWithOptions
[$option->categoryName
] = $option->categoryName
;
96 // collect top categories which contain options
98 foreach ($this->categoryStructure
[""] as $topCategory) {
99 if ($this->containsOptions($topCategory)) {
100 $topCategories[$topCategory->categoryID
] = $topCategory;
104 return $topCategories;
108 * Returns true if the given category or one of its child categories contains
111 * @param OptionCategory $topCategory
114 protected function containsOptions(OptionCategory
$topCategory)
116 // check if category directly contains options
117 if (isset($this->categoriesWithOptions
[$topCategory->categoryName
])) {
121 if (!isset($this->categoryStructure
[$topCategory->categoryName
])) {
122 // if category directly contains no options and has no child
123 // categories, it contains no options at all
127 // check child categories
128 foreach ($this->categoryStructure
[$topCategory->categoryName
] as $category) {
129 if ($this->containsOptions($category)) {