You are here

function taxonomy_access_get_grants in Taxonomy Access Control 6

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

Gets permissions for a given role.

Parameters

$rid: The role id to retrieve the permissions for.

Return value

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

File

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

Code

function taxonomy_access_get_grants($rid) {
  if (!isset($rid)) {
    return FALSE;
  }
  if (isset($rid) && !is_numeric($rid)) {
    $rid = db_result(db_query("SELECT rid FROM {role} WHERE name='%s'", $rid));
  }
  $result = db_query("SELECT * FROM {term_access} WHERE rid=%d", $rid);
  $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;
}