function cf_convert_from_crud in Common Functionality 7
Same name and namespace in other branches
- 7.2 cf.module \cf_convert_from_crud()
Converts the passed argument into an array of multiple booleans.
An array of booleans is returned whose keys are: create, read, update, and delete
Crud works in the same way that the linux filesystem permissions tend to be:
- create = 1
- read = 2
- update = 4
- delete = 8
Why: For efficiency reasons it may make more sense to store these boolean values into a single database column similar to how the unix permission umask works.
Parameters
int $crud: An integer representing the crud that is to be converted into an array of booleans.
array $function_history: (optional) An array of function names, ie: array('0' => 'my_function_name').
Return value
array An array containing the following keys:
- create: A boolean representing create permissions.
- read: A boolean representing read permissions.
- update: A boolean representing update permissions.
- delete: A boolean representing delete permissions.
File
- ./
cf.module, line 258
Code
function cf_convert_from_crud($crud, array $function_history = array()) {
cf_error_append_history($function_history, __FUNCTION__);
$uncrud = array();
$uncrud['create'] = FALSE;
$uncrud['read'] = FALSE;
$uncrud['update'] = FALSE;
$uncrud['delete'] = FALSE;
if (!isset($crud)) {
cf_error_invalid_variable($function_history, 'crud', 'Not defined', array());
return $uncrud;
}
if (!is_numeric($crud)) {
cf_error_not_numeric($function_history, 'crud');
return $uncrud;
}
if ($crud - 8 >= 0) {
$uncrud['delete'] = TRUE;
$crud -= 8;
}
if ($crud - 4 >= 0) {
$uncrud['update'] = TRUE;
$crud -= 4;
}
if ($crud - 2 >= 0) {
$uncrud['read'] = TRUE;
$crud -= 2;
}
if ($crud - 1 >= 0) {
$uncrud['create'] = TRUE;
}
return $uncrud;
}