function cf_convert_from_crud in Common Functionality 7.2
Same name and namespace in other branches
- 7 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
Justification: 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.
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.
Related topics
File
- ./
cf.module, line 184 - Common Functionality module.
Code
function cf_convert_from_crud($crud) {
$uncrud = array();
$uncrud['create'] = FALSE;
$uncrud['read'] = FALSE;
$uncrud['update'] = FALSE;
$uncrud['delete'] = FALSE;
if (!isset($crud)) {
if (class_exists('cf_error')) {
cf_error::invalid_variable('crud', 'Not defined');
}
return $uncrud;
}
if (!is_numeric($crud)) {
if (class_exists('cf_error')) {
cf_error::invalid_numeric('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;
}