You are here

function _set_default_permissions in Module Grants 6.3

Same name and namespace in other branches
  1. 6.4 module_grants.install \_set_default_permissions()

File

./module_grants.install, line 32
Install and uninstall hooks for Module Grants module

Code

function _set_default_permissions($role_name, $permissions) {
  if (!is_array($permissions)) {
    return;
  }
  $role = db_fetch_object(db_query("SELECT p.rid, perm FROM {permission} p INNER JOIN {role} r ON p.rid=r.rid WHERE r.name='%s'", $role_name));
  if ($role) {
    $added_perms = $role->perm;
    foreach ($permissions as $perm) {
      if (strpos($role->perm, $perm) === FALSE) {
        $added_perms .= ", {$perm}";
      }
    }
    if ($added_perms != $role->perm) {

      // some perms added
      db_query("UPDATE {permission} SET perm='%s' WHERE rid=%d", $added_perms, $role->rid);
    }
  }
}