perms = $this->getPerms($forumId, $rankId, $userId); } // Get permissions private function getPerms($forumId, $rankId = 0, $userId = 0, $perms = 0) { // Attempt to get the forum's row from the db $forumRows = Database::fetch('forums', true, ['forum_id' => [$forumId, '=']]); // Check if anything was returned, otherwise just stop if (!$forumRows) { return $perms; } // Get the data from the permissions table $forumPerms = Database::fetch('forum_permissions', false, [ 'forum_id' => [$forumId, '='], 'rank_id' => [$rankId, '='], 'user_id' => [$userId, '='], ]); // Perform a bitwise OR if perms is already set to something if ($perms) { $perms = $perms | $forumPerms['forum_perms']; } else { $perms = $forumPerms['forum_perms']; } // Perform this again if this forum has a parent if ($forumRows['forum_category']) { $perms = $this->getPerms($forumId, $rankId, $userId, $perms); } // Return new value return $perms; } // Check permission public function check($perm) { return bindec($this->perms) & $perm === true; } }