You are here

function taxonomy_access_get_default_grants in Taxonomy Access Control 6

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

Gets default 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[vid][grant] where vid is the vocab id and grant is the permission (i.e. 'view','delete',ect.) this entry in the hash is true if permission is granted, false otherwise

File

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

Code

function taxonomy_access_get_default_grants($rid) {
  if (!is_numeric($rid)) {
    return FALSE;
  }
  $result = db_query("SELECT * FROM {term_access_defaults} WHERE rid=%d", $rid);
  $grants = array();
  while ($grant = db_fetch_array($result)) {
    $vid = $grant['vid'];
    foreach ($grant as $key => $grant_val) {
      if (strpos($key, 'grant_') !== FALSE) {
        $grant_name = '';
        $grant_name = str_replace('grant_', '', $key);
        if (!isset($grants[$vid][$grant_name]) || !$grants[$vid][$grant_name]) {

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