fetchAllPermissions (function)

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

Purpose

Grabs all permission levels

Location

users/helpers/permissions.php

Parameters

This function does not take any arguments

Returns

Data Type Description of Returned Data
array It simply retrieves all the permissions from the permissions table in the database and returns them as an array of objects, where each object represents a permission in the table.

Example

fetchAllPermissions()

Further Documentation:

The fetchAllPermissions() function is a custom function in the UserSpice PHP application that retrieves all the permissions from the permissions table in the database. Here's how the function works:

$db = DB::getInstance(); - This line gets a singleton instance of the DB class, which is responsible for connecting to the database and executing queries.

$query = $db->query('SELECT id, name FROM permissions'); - This line creates a new query object using the query() method of the DB instance. The query selects the id and name columns from the permissions table in the database.

$results = $query->results(); - This line executes the query and retrieves the results as an array of objects.

return $results; - This line returns the results of the query as an array of objects, where each object represents a permission in the permissions table. Each object has the properties id and name, which correspond to the id and name columns in the table.

Here's an example of how you might use this function in a PHP script:


// Get all permissions from the database
$permissions = fetchAllPermissions();

// Print out the permissions
foreach ($permissions as $permission) {
echo "{$permission->id}: {$permission->name}\n";
}

Assuming that the fetchAllPermissions() function is defined in a file that has been included in the script, this code retrieves all the permissions from the permissions table in the database and prints out their IDs and names. The resulting output would be a list of all the permissions in the permissions table.