You are here

function taxonomy_access_get_grants in Taxonomy Access Control 5

Same name and namespace in other branches
  1. 5.2 taxonomy_access.module \taxonomy_access_get_grants()
  2. 6 taxonomy_access.module \taxonomy_access_get_grants()

Gets permissions for a given role

Parameters

$role: The role to retrieve the permissions for. Can be the name or the role id or blank for all term permissions.

Return value

A two dimensional hash of the form $grants[tid][grant] where tid is the term id and grant is the permission (i.e. 'view','delete',ect.) this entry in the hash is true if permission is granted, false otherwise

1 call to taxonomy_access_get_grants()
_taxonomy_access_permissions_form in ./taxonomy_access_admin.inc
Generating the category permissions form for choosen user role.

File

./taxonomy_access.module, line 335
Allows administrators to specify how each category (in the taxonomy) can be used by various roles.

Code

function taxonomy_access_get_grants($role) {
  if (!isset($role)) {
    return false;
  }
  if (isset($role) && !is_numeric($role)) {
    $role = db_result(db_query("SELECT rid FROM {role} WHERE name='{$role}'"));
  }
  $result = db_query("SELECT * FROM {term_access} WHERE rid='{$role}'");
  $grants = array();
  while ($grant = db_fetch_array($result)) {
    $tid = $grant['tid'];
    foreach ($grant as $key => $grant_val) {
      if (strpos($key, 'grant_') !== FALSE) {
        $grant_name = '';
        $grant_name = str_replace('grant_', '', $key);
        if (!isset($grants[$tid][$grant_name]) || !$grants[$tid][$grant_name]) {

          // If there's conflicting DB rules, take the most lenient
          $grants[$tid][$grant_name] = $grant_val;
        }
      }
    }
  }
  return $grants;
}