public function filedepot::updatePerms in filedepot 7
Same name and namespace in other branches
- 6 filedepot.class.php \filedepot::updatePerms()
1 call to filedepot::updatePerms()
- filedepot::createFolder in ./
filedepot.class.php - Call createFolderNode to create the folder which will trigger this method through filedepot_insert @global type $user
File
- ./
filedepot.class.php, line 530 - filedepot.class.php Main class for the Filedepot module
Class
- filedepot
- @file filedepot.class.php Main class for the Filedepot module
Code
public function updatePerms($id, $accessrights, $users = '', $groups = '', $roles = '') {
if ($users != '' and !is_array($users)) {
$users = array(
$users,
);
}
if ($groups != '' and !is_array($groups)) {
$groups = array(
$groups,
);
}
if ($roles != '' and !is_array($roles)) {
$roles = array(
$roles,
);
}
if (!empty($accessrights)) {
if (in_array('view', $accessrights)) {
$view = 1;
}
else {
$view = 0;
}
if (in_array('upload', $accessrights)) {
$upload = 1;
}
else {
$upload = 0;
}
if (in_array('approval', $accessrights)) {
$approval = 1;
}
else {
$approval = 0;
}
if (in_array('upload_dir', $accessrights)) {
$direct = 1;
}
else {
$direct = 0;
}
if (in_array('admin', $accessrights)) {
$admin = 1;
}
else {
$admin = 0;
}
if (in_array('upload_ver', $accessrights)) {
$versions = 1;
}
else {
$versions = 0;
}
if (!empty($users)) {
foreach ($users as $uid) {
$uid = intval($uid);
$query = db_query("SELECT accid FROM {filedepot_access} WHERE catid=:cid AND permtype='user' AND permid=:uid", array(
':cid' => $id,
':uid' => $uid,
));
if ($query
->fetchField() === FALSE) {
$query = db_insert('filedepot_access');
$query
->fields(array(
'catid',
'permid',
'permtype',
'view',
'upload',
'upload_direct',
'upload_ver',
'approval',
'admin',
));
$query
->values(array(
'catid' => $id,
'permid' => $uid,
'permtype' => 'user',
'view' => $view,
'upload' => $upload,
'upload_direct' => $direct,
'upload_ver' => $versions,
'approval' => $approval,
'admin' => $admin,
));
$query
->execute();
}
else {
db_update('filedepot_access')
->fields(array(
'view' => $view,
'upload' => $upload,
'upload_direct' => $direct,
'upload_ver' => $versions,
'approval' => $approval,
'admin' => $admin,
))
->condition('catid', $id)
->condition('permtype', 'user')
->condition('permid', $uid)
->execute();
}
}
}
if (!empty($groups)) {
foreach ($groups as $gid) {
$gid = intval($gid);
$query = db_query("SELECT accid FROM {filedepot_access} WHERE catid=:cid AND permtype='group' AND permid=:gid", array(
':cid' => $id,
':gid' => $gid,
));
if ($query
->fetchField() === FALSE) {
$query = db_insert('filedepot_access');
$query
->fields(array(
'catid',
'permid',
'permtype',
'view',
'upload',
'upload_direct',
'upload_ver',
'approval',
'admin',
));
$query
->values(array(
'catid' => $id,
'permid' => $gid,
'permtype' => 'group',
'view' => $view,
'upload' => $upload,
'upload_direct' => $direct,
'upload_ver' => $versions,
'approval' => $approval,
'admin' => $admin,
));
$query
->execute();
}
else {
db_update('filedepot_access')
->fields(array(
'view' => $view,
'upload' => $upload,
'upload_direct' => $direct,
'upload_ver' => $versions,
'approval' => $approval,
'admin' => $admin,
))
->condition('catid', $id)
->condition('permtype', 'group')
->condition('permid', $gid)
->execute();
}
}
}
if (!empty($roles)) {
foreach ($roles as $rid) {
$rid = intval($rid);
$query = db_query("SELECT accid FROM {filedepot_access} WHERE catid=:cid AND permtype='role' AND permid=:uid", array(
'cid' => $id,
'uid' => $rid,
));
if ($query
->fetchField() === FALSE) {
$query = db_insert('filedepot_access');
$query
->fields(array(
'catid',
'permid',
'permtype',
'view',
'upload',
'upload_direct',
'upload_ver',
'approval',
'admin',
));
$query
->values(array(
'catid' => $id,
'permid' => $rid,
'permtype' => 'role',
'view' => $view,
'upload' => $upload,
'upload_direct' => $direct,
'upload_ver' => $versions,
'approval' => $approval,
'admin' => $admin,
));
$query
->execute();
}
else {
db_update('filedepot_access')
->fields(array(
'view' => $view,
'upload' => $upload,
'upload_direct' => $direct,
'upload_ver' => $versions,
'approval' => $approval,
'admin' => $admin,
))
->condition('catid', $id)
->condition('permtype', 'role')
->condition('permid', $rid)
->execute();
}
}
}
/* May need to review this - and clear only those users that have been updated later.
But determining the users in updated groups and sorting out duplicates from the individual user perms
and only updating them may take more processing then simply clearing all.
The users setting will be updated the next time they use the application - public/filedepot/library.php
Distributing the load to update the cached setting.
This cached setting will really only benefit when there are many thousand access records like portal23
*/
db_update('filedepot_usersettings')
->fields(array(
'allowable_view_folders' => '',
))
->execute();
return TRUE;
}
else {
return FALSE;
}
}