You are here

function privatemsg_user_role_permissions in Privatemsg 6.2

Helper function; Check if a role has a permission.

Code adapted from user_access().

1 call to privatemsg_user_role_permissions()
privatemsg_devel_generate_form in ./privatemsg.devel_generate.inc
Form Builder; Integrates with Devel Generate.

File

./privatemsg.devel_generate.inc, line 282

Code

function privatemsg_user_role_permissions($perm, $roles, $reset = FALSE) {
  if ($cache = cache_get('privatemsg_user_role_permissions') && $reset == FALSE) {
    return $cache->data;
  }
  else {
    $result = db_query("SELECT p.perm FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.rid IN (" . db_placeholders($roles) . ")", array_keys($roles));
    $perms = array();
    while ($row = db_fetch_object($result)) {
      $perms += array_flip(explode(', ', $row->perm));
    }
    $set = isset($perms[$perm]);
    cache_set('privatemsg_user_role_permissions', $set, 'cache');
    return $set;
  }
}