@@ -93,9 +93,9 @@ public static function getHtmlForUserGroupsTable(ConfigurableMenusFeature $confi
9393 foreach ($ userGroups as $ groupName => $ tabs ) {
9494 $ userGroupVal = [];
9595 $ userGroupVal ['name ' ] = $ groupName ;
96- $ userGroupVal ['serverTab ' ] = self ::getAllowedTabNames ($ tabs , ' server ' );
97- $ userGroupVal ['dbTab ' ] = self ::getAllowedTabNames ($ tabs , ' db ' );
98- $ userGroupVal ['tableTab ' ] = self ::getAllowedTabNames ($ tabs , ' table ' );
96+ $ userGroupVal ['serverTab ' ] = self ::getAllowedTabNames ($ tabs , UserGroupLevel::Server );
97+ $ userGroupVal ['dbTab ' ] = self ::getAllowedTabNames ($ tabs , UserGroupLevel::Database );
98+ $ userGroupVal ['tableTab ' ] = self ::getAllowedTabNames ($ tabs , UserGroupLevel::Table );
9999 $ userGroupVal ['userGroupUrl ' ] = Url::getFromRoute ('/server/user-groups ' );
100100 $ userGroupVal ['viewUsersUrl ' ] = Url::getCommon (
101101 ['viewUsers ' => 1 , 'userGroup ' => $ groupName ],
@@ -132,17 +132,16 @@ public static function getHtmlForUserGroupsTable(ConfigurableMenusFeature $confi
132132 * Returns the list of allowed menu tab names
133133 * based on a data row from usergroup table.
134134 *
135- * @param mixed[] $row row of usergroup table
136- * @param string $level 'server', 'db' or 'table'
135+ * @param mixed[] $row row of usergroup table
137136 *
138137 * @return string comma separated list of allowed menu tab names
139138 */
140- public static function getAllowedTabNames (array $ row , string $ level ): string
139+ public static function getAllowedTabNames (array $ row , UserGroupLevel $ level ): string
141140 {
142141 $ tabNames = [];
143142 $ tabs = Util::getMenuTabList ($ level );
144143 foreach ($ tabs as $ tab => $ tabName ) {
145- if (isset ($ row [$ level . '_ ' . $ tab ]) && $ row [$ level . '_ ' . $ tab ] !== 'Y ' ) {
144+ if (isset ($ row [$ level-> value . '_ ' . $ tab ]) && $ row [$ level-> value . '_ ' . $ tab ] !== 'Y ' ) {
146145 continue ;
147146 }
148147
@@ -227,17 +226,17 @@ public static function getHtmlToEditUserGroup(
227226
228227 $ tabList = self ::getTabList (
229228 __ ('Server-level tabs ' ),
230- ' server ' ,
229+ UserGroupLevel::Server ,
231230 $ allowedTabs ['server ' ],
232231 );
233232 $ tabList .= self ::getTabList (
234233 __ ('Database-level tabs ' ),
235- ' db ' ,
234+ UserGroupLevel::Database ,
236235 $ allowedTabs ['db ' ],
237236 );
238237 $ tabList .= self ::getTabList (
239238 __ ('Table-level tabs ' ),
240- ' table ' ,
239+ UserGroupLevel::Table ,
241240 $ allowedTabs ['table ' ],
242241 );
243242
@@ -257,12 +256,11 @@ public static function getHtmlToEditUserGroup(
257256 * tabs of 'server', 'db' or 'table' levels.
258257 *
259258 * @param string $title title of the checkbox group
260- * @param string $level 'server', 'db' or 'table'
261259 * @param mixed[] $selected array of selected allowed tabs
262260 *
263261 * @return string HTML for checkbox groups
264262 */
265- public static function getTabList (string $ title , string $ level , array $ selected ): string
263+ public static function getTabList (string $ title , UserGroupLevel $ level , array $ selected ): string
266264 {
267265 $ tabs = Util::getMenuTabList ($ level );
268266 $ tabDetails = [];
@@ -278,7 +276,7 @@ public static function getTabList(string $title, string $level, array $selected)
278276
279277 return $ template ->render ('server/user_groups/tab_list ' , [
280278 'title ' => $ title ,
281- 'level ' => $ level ,
279+ 'level ' => $ level-> value ,
282280 'tab_details ' => $ tabDetails ,
283281 ]);
284282 }
@@ -294,7 +292,6 @@ public static function edit(
294292 string $ userGroup ,
295293 bool $ new = false ,
296294 ): void {
297- $ tabs = Util::getMenuTabList ();
298295 $ groupTable = Util::backquote ($ configurableMenusFeature ->database )
299296 . '. ' . Util::backquote ($ configurableMenusFeature ->userGroups );
300297
@@ -309,14 +306,13 @@ public static function edit(
309306 . '(`usergroup`, `tab`, `allowed`) '
310307 . ' VALUES ' ;
311308 $ first = true ;
312- /** @var array<string, string> $tabGroup */
313- foreach ($ tabs as $ tabGroupName => $ tabGroup ) {
314- foreach (array_keys ($ tabGroup ) as $ tab ) {
309+ foreach (UserGroupLevel::cases () as $ tabGroupName ) {
310+ foreach (array_keys (Util::getMenuTabList ($ tabGroupName )) as $ tab ) {
315311 if (! $ first ) {
316312 $ sqlQuery .= ', ' ;
317313 }
318314
319- $ tabName = $ tabGroupName . '_ ' . $ tab ;
315+ $ tabName = $ tabGroupName-> value . '_ ' . $ tab ;
320316 $ allowed = isset ($ _POST [$ tabName ]) && $ _POST [$ tabName ] === 'Y ' ;
321317 $ sqlQuery .= '( ' . $ dbi ->quoteString ($ userGroup , ConnectionType::ControlUser)
322318 . ', ' . $ dbi ->quoteString ($ tabName , ConnectionType::ControlUser) . ", ' "
0 commit comments