function filedepot_views_pre_execute in filedepot 7
Same name and namespace in other branches
- 6 views/filedepot.views.inc \filedepot_views_pre_execute()
File
- views/
filedepot.views.inc, line 133 - filedepot.views.inc Contains all Views related API calls and default view creation information
Code
function filedepot_views_pre_execute(&$view) {
if ($view->name == 'filedepot') {
$extra_sql = '';
$query = db_select('');
$query = $view->build_info['query'];
$where = array();
// Check if user has entered the argument into the view directly -- ie in the view UI
// If so, we need will use that folder id to remove it and add our own including sub folders.
if (count($view->args) > 0 && $view->args[0] > 0) {
$folder_id = $view->args[0];
/*
//str_replace("WHERE filedepot_categories.cid = '%s'\n", '', $view->build_info['query']);
$wherepos = strpos($view->build_info['query'],"WHERE filedepot_categories.cid = '");
if ($wherepos > 0) {
$wherepos_end = strpos($view->build_info['query'],"'\n",$wherepos);
if ($wherepos_end > $wherepos) {
$view->build_info['query'] = substr($view->build_info['query'],0,$wherepos) . substr($view->build_info['query'],$wherepos_end+3);
}
}*/
}
else {
// Check if a folder id is being passed in to the view from a URL argument
$folder_id = intval(arg(1));
}
$filedepot = filedepot_filedepot();
// if we have a valid folder id determine all viewable subfolders and only generate view for these folders
if ($folder_id > 0 and $filedepot
->checkPermission($folder_id, 'view')) {
module_load_include('php', 'filedepot', 'lib-common');
$array_folders = array();
$array_folders[] = $folder_id;
$filedepot
->getRecursiveCatIDs($array_folders, $folder_id, 'view');
if (!empty($array_folders) and count($array_folders) > 0) {
$folderlist = implode(',', $array_folders);
$where[] = "filedepot_categories.cid in ({$folderlist})";
}
}
else {
if (!empty($filedepot->allowableViewFoldersSql)) {
$where[] = "filedepot_categories.cid in ({$filedepot->allowableViewFoldersSql})";
}
else {
// User does not have any viewable folders
$where[] = "1 = 2";
}
}
if (count($where) > 0) {
$where_str = implode(" AND ", $where);
$view->build_info['query']
->where($where_str);
}
$str = $view->build_info['query']
->__toString();
$s1 = 1;
}
}