From bed55c909dc48f489ed45f2a1fe7ab2ac40ee6d2 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Thu, 12 Sep 2024 12:28:02 +0300 Subject: [PATCH] User 1 is always superuser, User 2 is always demo --- app/classes/user.php | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/app/classes/user.php b/app/classes/user.php index 648f340..9f8f32e 100644 --- a/app/classes/user.php +++ b/app/classes/user.php @@ -112,7 +112,6 @@ class User { public function getUserRights($user_id) { $sql = 'SELECT u.id AS user_id, - u.username, r.id AS right_id, r.name AS right_name FROM @@ -129,7 +128,39 @@ class User { ':user_id' => $user_id, ]); - return $query->fetchAll(PDO::FETCH_ASSOC); + $result = $query->fetchAll(PDO::FETCH_ASSOC); + + // ensure specific entries are included in the result + $specialEntries = []; + + // user 1 is always superuser + if ($user_id == 1) { + $specialEntries = [ + [ + 'user_id' => 1, + 'right_id' => 1, + 'right_name' => 'superuser' + ] + ]; + + // user 2 is always demo + } elseif ($user_id == 2) { + $specialEntries = [ + [ + 'user_id' => 2, + 'right_id' => 100, + 'right_name' => 'demo user' + ] + ]; + } + + // merge the special entries with the existing results + $result = array_merge($specialEntries, $result); + // remove duplicates if necessary + $result = array_unique($result, SORT_REGULAR); + + // return the modified result + return $result; }