Move selectedPermissionsArray to helper, since it can be used by users as well

This commit is contained in:
snipe 2016-04-28 20:56:47 -07:00
parent 8dc0dc0a07
commit 7783471cc3

View file

@ -278,4 +278,54 @@ class Helper
return false; return false;
} }
/**
* Walks through the permissions in the permissions config file and determines if
* permissions are granted based on a $selected_arr array.
*
* The $permissions array is a multidimensional array broke down by section.
* (Licenses, Assets, etc)
*
* The $selected_arr should be a flattened array that contains just the
* corresponding permission name and a true or false boolean to determine
* if that group/user has been granted that permission.
*
* @author [A. Gianotto] [<snipe@snipe.net]
* @param array $permissions
* @param array $selected_arr
* @since [v1.0]
* @return Array
*/
public static function selectedPermissionsArray($permissions, $selected_arr = array())
{
$permissions_arr = array();
foreach ($permissions as $permission) {
for ($x = 0; $x < count($permission); $x++) {
$permission_name = $permission[$x]['permission'];
if ($permission[$x]['display'] === true) {
if ($selected_arr) {
if (array_key_exists($permission_name,$selected_arr)) {
$permissions_arr[$permission_name] = ($selected_arr[$permission_name] === 1) ? '1': '0';
} else {
$permissions_arr[$permission_name] = 'bum';
}
} else {
$permissions_arr[$permission_name] = 'hodor';
}
}
}
}
return $permissions_arr;
}
} }