|
2 | 2 |
|
3 | 3 | namespace wcf\system\cache\builder; |
4 | 4 |
|
5 | | -use wcf\acp\form\OptionForm; |
6 | | -use wcf\data\acp\menu\item\ACPMenuItem; |
7 | 5 | 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; |
11 | 6 |
|
12 | 7 | /** |
13 | 8 | * Caches the ACP menu items. |
|
18 | 13 | */ |
19 | 14 | class ACPMenuCacheBuilder extends AbstractCacheBuilder |
20 | 15 | { |
21 | | - /** |
22 | | - * list of option categories which directly contain options |
23 | | - * @var string[] |
24 | | - */ |
25 | | - protected $categoriesWithOptions = []; |
26 | | - |
27 | | - /** |
28 | | - * list of option categories grouped by the name of their parent category |
29 | | - * @var array<string, OptionCategory[]> |
30 | | - */ |
31 | | - protected $categoryStructure = []; |
32 | | - |
33 | 16 | /** |
34 | 17 | * @inheritDoc |
35 | 18 | */ |
36 | 19 | public function rebuild(array $parameters) |
37 | 20 | { |
38 | 21 | $data = []; |
39 | 22 |
|
40 | | - // get "real" menu items |
41 | 23 | $menuItemList = new ACPMenuItemList(); |
42 | 24 | $menuItemList->sqlOrderBy = "acp_menu_item.showOrder"; |
43 | 25 | $menuItemList->readObjects(); |
44 | 26 | foreach ($menuItemList as $menuItem) { |
45 | 27 | $data[$menuItem->parentMenuItem][] = $menuItem; |
46 | 28 | } |
47 | 29 |
|
48 | | - // get menu items for top option categories |
49 | | - /*$data['wcf.acp.menu.link.option.category'] = []; |
50 | | - foreach ($this->getTopOptionCategories() as $optionCategory) { |
51 | | - $data['wcf.acp.menu.link.option.category'][] = new ACPMenuItem(null, [ |
52 | | - 'menuItem' => 'wcf.acp.option.category.' . $optionCategory->categoryName, |
53 | | - 'parentMenuItem' => 'wcf.acp.menu.link.option.category', |
54 | | - 'menuItemController' => OptionForm::class, |
55 | | - 'permissions' => $optionCategory->permissions, |
56 | | - 'optionCategoryID' => $optionCategory->categoryID, |
57 | | - 'options' => $optionCategory->options, |
58 | | - ]); |
59 | | - }*/ |
60 | | - |
61 | 30 | return $data; |
62 | 31 | } |
63 | | - |
64 | | - /** |
65 | | - * Returns the list with top option categories which contain options. |
66 | | - * |
67 | | - * @return OptionCategory[] |
68 | | - */ |
69 | | - protected function getTopOptionCategories() |
70 | | - { |
71 | | - $optionCategoryList = new OptionCategoryList(); |
72 | | - $optionCategoryList->readObjects(); |
73 | | - $optionCategories = $optionCategoryList->getObjects(); |
74 | | - |
75 | | - // build category structure |
76 | | - $this->categoryStructure = []; |
77 | | - foreach ($optionCategories as $optionCategory) { |
78 | | - if (!isset($this->categoryStructure[$optionCategory->parentCategoryName])) { |
79 | | - $this->categoryStructure[$optionCategory->parentCategoryName] = []; |
80 | | - } |
81 | | - |
82 | | - $this->categoryStructure[$optionCategory->parentCategoryName][] = $optionCategory; |
83 | | - } |
84 | | - |
85 | | - $optionList = new OptionList(); |
86 | | - $optionList->readObjects(); |
87 | | - |
88 | | - // collect names of categories which contain options |
89 | | - foreach ($optionList as $option) { |
90 | | - if (!isset($this->categoriesWithOptions[$option->categoryName])) { |
91 | | - $this->categoriesWithOptions[$option->categoryName] = $option->categoryName; |
92 | | - } |
93 | | - } |
94 | | - |
95 | | - // collect top categories which contain options |
96 | | - $topCategories = []; |
97 | | - foreach ($this->categoryStructure[""] as $topCategory) { |
98 | | - if ($this->containsOptions($topCategory)) { |
99 | | - $topCategories[$topCategory->categoryID] = $topCategory; |
100 | | - } |
101 | | - } |
102 | | - |
103 | | - return $topCategories; |
104 | | - } |
105 | | - |
106 | | - /** |
107 | | - * Returns true if the given category or one of its child categories contains |
108 | | - * options. |
109 | | - * |
110 | | - * @param OptionCategory $topCategory |
111 | | - * @return bool |
112 | | - */ |
113 | | - protected function containsOptions(OptionCategory $topCategory) |
114 | | - { |
115 | | - // check if category directly contains options |
116 | | - if (isset($this->categoriesWithOptions[$topCategory->categoryName])) { |
117 | | - return true; |
118 | | - } |
119 | | - |
120 | | - if (!isset($this->categoryStructure[$topCategory->categoryName])) { |
121 | | - // if category directly contains no options and has no child |
122 | | - // categories, it contains no options at all |
123 | | - return false; |
124 | | - } |
125 | | - |
126 | | - // check child categories |
127 | | - foreach ($this->categoryStructure[$topCategory->categoryName] as $category) { |
128 | | - if ($this->containsOptions($category)) { |
129 | | - return true; |
130 | | - } |
131 | | - } |
132 | | - |
133 | | - return false; |
134 | | - } |
135 | 32 | } |
0 commit comments