findAll(); } catch (\Exception $e) { // Log the error message if the query fails log_message('error', 'Error fetching permissions: ' . $e->getMessage()); // Rethrow the exception to be handled by the caller throw $e; } } /** * Fetch permissions assigned to a specific role * * @param int $role_id The ID of the role * @return array List of permissions associated with the role * @throws \Exception If there is an error during the fetch */ public function getRolePermissions($role_id) { try { // Query to get role permissions along with default permissions $rolePermissions = $this->db->table('role_permissions') ->select('role_permissions.*, permissions.name') // Join with 'permissions' table to get permission details ->join('permissions', 'role_permissions.permission_id = permissions.id', 'left') // Filter by the specified role ID ->where('role_permissions.role_id', $role_id) ->get() // Get the result as an array ->getResultArray(); // Log the fetched role permissions for debugging log_message('info', 'Role permissions fetched: ' . print_r($rolePermissions, true)); return $rolePermissions; } catch (\Exception $e) { // Log the error message if the query fails log_message('error', 'Error fetching role permissions for role ID: ' . $role_id . ': ' . $e->getMessage()); // Rethrow the exception to be handled by the caller throw $e; } } }