fetchPermissionUsers (function)

Last updated: Mon, Apr 17, 2023 9:35 am
Return to Knowledgebase

Purpose

Retrieves a list of users who have a permission level.

Location

users/helpers/permissions.php

Parameters

# Parameter Data Type Required Description
1 $permission_id integer Yes the ID of the permission for which users need to be fetched

Returns

Data Type Description of Returned Data
array Returns an array of user information that includes the user ID and the ID of the permission they are associated with.

Example

fetchPermissionUsers(2)

Further Documentation:

The fetchPermissionUsers() function is a part of the UserSpice PHP framework, and it is used to retrieve the users associated with a particular permission ID. The function takes a single parameter, which is the ID of the permission for which users need to be fetched. It returns an array of user information that includes the user ID and the ID of the permission they are associated with.

Here is an example usage of the fetchPermissionUsers() function:
// Assume the permission ID is 5
$permission_id = 5;

// Call the function to fetch the users associated with the permission ID
$users = fetchPermissionUsers($permission_id);

// Loop through the returned array of users and display their information
foreach ($users as $user) {
echo "User ID: " . $user['user_id'] . "
";
echo "Permission ID: " . $user['id'] . "
";
}

This code will fetch all the users associated with the permission ID 5 and display their information. Note that the code block starting from $row[$user] and ending with return $row; is not functional and does not affect the result of the function. It can be safely removed.

Also note that to use this function, you need to have the UserSpice framework installed and set up properly, and the DB class and query() method referenced in the function should be defined elsewhere in your code.