Not sure where else to post this, or even if I should at all...yet perhaps it will help someone... it is (obviously) based off of taxonomy_access_node_access_records.

This function accepts a user object and returns an array of taxonomy vocabularies + privileges based on the user's roles.

function taxonomy_access_get_user_vocabulary_privileges($user) {
  if (taxonomy_access_disabling() || !isset($user->uid)) {
    return;
  }

  $grants = array();

  if (is_array($user->roles) AND count($user->roles)) {
    $result = db_query('SELECT tad.vid, 
						BIT_OR(COALESCE( tad.grant_view, tadg.grant_view )) AS grant_view, 
                       BIT_OR(COALESCE( tad.grant_update, tadg.grant_update )) AS grant_update, 
                       BIT_OR(COALESCE( tad.grant_delete, tadg.grant_delete )) AS grant_delete
                       FROM {term_access_defaults} tad
					   INNER JOIN {users_roles} ur ON tad.rid = ur.rid
					   LEFT JOIN {term_access_defaults} tadg ON tadg.vid = 0
					   WHERE ur.uid = %d
                       GROUP BY tad.vid', $user->uid);
  } 
  /*
                       
                      
  */                     
  while($row = db_fetch_array($result)) {
	 error_log ("taxonomy_access_get_user_vocabulary_privileges " . $row['vid']);
    $grants[] = array(
      'realm' => 'vocabulary_access',
       'vid' => $row['vid'],
       'vocabulary' => taxonomy_get_vocabulary($row['vid']),
       'grant_view' => ($row['grant_view'] == 1) ? 1 : 0,
       'grant_update' => ($row['grant_update'] == 1) ? 1 : 0,
       'grant_delete' => ($row['grant_delete'] == 1) ? 1 : 0,
      'priority' => 0,
    );
  }

  return $grants;
}

Comments

xjm’s picture

Status: Active » Closed (fixed)

If you like, you could post the code snippet in the book pages:
http://drupal.org/handbook/customization/php-snippets