1919
2020namespace phpMyFAQ \Administration ;
2121
22+ use phpMyFAQ \Category \Permission \CategoryPermissionService ;
2223use phpMyFAQ \Configuration ;
2324use phpMyFAQ \Database ;
2425
2526/**
2627 * Class Category
2728 *
28- * All methods in this class only needed for admin category management.
29+ * All methods in this class are only needed for admin category management.
2930 */
3031class Category
3132{
@@ -72,9 +73,13 @@ public function loadCategories(): array
7273 );
7374 }
7475
75- $ query = sprintf (
76- '
77- SELECT
76+ // Centralize permission WHERE clause
77+ $ perm = new CategoryPermissionService ();
78+ // In admin, include inactive categories (no active filter)
79+ $ where = $ perm ->buildWhereClause ($ this ->groups , $ this ->user , true ) . ' ' . $ languageCheck ;
80+
81+ $ prefix = Database::getTablePrefix ();
82+ $ query = "SELECT
7883 fc.id AS id,
7984 fc.lang AS lang,
8085 fc.parent_id AS parent_id,
@@ -86,38 +91,19 @@ public function loadCategories(): array
8691 fc.image AS image,
8792 fc.show_home AS show_home
8893 FROM
89- %sfaqcategories fc
90- LEFT JOIN
91- %sfaqcategory_group fg
92- ON
93- fc.id = fg.category_id
94- LEFT JOIN
95- %sfaqcategory_order fco
96- ON
97- fc.id = fco.category_id
98- LEFT JOIN
99- %sfaqcategory_user fu
100- ON
101- fc.id = fu.category_id
102- WHERE
103- ( fg.group_id IN (%s)
104- OR
105- (fu.user_id = %d AND fg.group_id IN (%s)))
106- %s
94+ {$ prefix }faqcategories fc
95+ LEFT JOIN {$ prefix }faqcategory_group fg
96+ ON fc.id = fg.category_id
97+ LEFT JOIN {$ prefix }faqcategory_order fco
98+ ON fc.id = fco.category_id
99+ LEFT JOIN {$ prefix }faqcategory_user fu
100+ ON fc.id = fu.category_id
101+ {$ where }
107102 GROUP BY
108- fc.id, fc.lang, fc.parent_id, fc.name, fc.description, fc.user_id, fc.group_id, fc.active, fc.image,
103+ fc.id, fc.lang, fc.parent_id, fc.name, fc.description, fc.user_id, fc.group_id, fc.active, fc.image,
109104 fc.show_home, fco.position
110105 ORDER BY
111- fco.position, fc.id ASC ' ,
112- Database::getTablePrefix (),
113- Database::getTablePrefix (),
114- Database::getTablePrefix (),
115- Database::getTablePrefix (),
116- implode (', ' , $ this ->groups ),
117- $ this ->user ,
118- implode (', ' , $ this ->groups ),
119- $ languageCheck ,
120- );
106+ fco.position, fc.id ASC " ;
121107
122108 $ result = $ this ->configuration ->getDb ()->query ($ query );
123109
@@ -144,8 +130,11 @@ public function loadCategories(): array
144130 ];
145131 }
146132
147- foreach ($ this ->categoryName as $ id ) {
148- $ this ->categoryName [$ id ['id ' ]]['level ' ] = $ this ->getLevelOf ($ this ->categoryName [$ id ['id ' ]]['id ' ]);
133+ // Ensure level is set for each entry in categoryName
134+ foreach ($ this ->categoryName as $ cid => $ row ) {
135+ if (is_array ($ row ) && isset ($ row ['id ' ])) {
136+ $ this ->categoryName [$ cid ]['level ' ] = $ this ->getLevelOf ((int ) $ row ['id ' ]);
137+ }
149138 }
150139 }
151140
0 commit comments