function filedepot_recursiveAccessArray in filedepot 7
Same name and namespace in other branches
- 6 lib-common.php \filedepot_recursiveAccessArray()
Returns a formatted listbox of categories user has access First checks for View access so that delegated admin can be just for sub-categories
Parameters
string|array $perms Single perm 'admin' or array of permissions as required by $filedepot->checkPermission():
int $selected Will make this item the selected item in the listbox:
string $id Parent category to start at and then recursively check:
string $level Used by this function as it calls itself to control the indent formatting:
Return value
string Return an array of folder options
3 calls to filedepot_recursiveAccessArray()
- filedepot_form_alter in ./
filedepot.module - Implementation of hook_form_alter().
- filedepot_newfile_form in ./
filedepot.module - filedepot_newfolder_form in ./
filedepot.module
File
- ./
lib-common.php, line 29 - lib-common.php Common library of functions for the applications
Code
function filedepot_recursiveAccessArray($perms, $id = 0, $level = 1) {
$filedepot = filedepot_filedepot();
$options_tree = array();
if ($filedepot->ogmode_enabled and !empty($filedepot->allowableGroupViewFoldersSql)) {
if ($id == 0) {
$id = $filedepot->ogrootfolder;
}
}
$query = db_query("SELECT cid,pid,name FROM {filedepot_categories} WHERE pid=:pid ORDER BY cid", array(
':pid' => $id,
));
while ($A = $query
->fetchAssoc()) {
list($cid, $pid, $name) = array_values($A);
$indent = ' ';
// Check if user has access to this category
if ($filedepot
->checkPermission($cid, 'view')) {
// Check and see if this category has any sub categories - where a category record has this cid as it's parent
$tempcid = db_query("SELECT cid FROM {filedepot_categories} WHERE pid=:cid", array(
':cid' => $cid,
))
->fetchField();
if ($tempcid > 0) {
if ($level > 1) {
for ($i = 2; $i <= $level; $i++) {
$indent .= "--";
}
$indent .= ' ';
}
if ($filedepot
->checkPermission($cid, $perms)) {
if ($indent != '') {
$name = " {$name}";
}
$options_tree[$cid] = $indent . $name;
$options_tree += filedepot_recursiveAccessArray($perms, $cid, $level + 1);
}
else {
// Need to check for any folders with admin even subfolders of parents that user does not have access
$options_tree += filedepot_recursiveAccessArray($perms, $cid, $level + 1);
}
}
else {
if ($level > 1) {
for ($i = 2; $i <= $level; $i++) {
$indent .= "--";
}
$indent .= ' ';
}
if ($filedepot
->checkPermission($cid, $perms)) {
if ($indent != '') {
$name = " {$name}";
}
$options_tree[$cid] = $indent . $name;
}
}
}
}
return $options_tree;
}