function term_permissions_allowed in Taxonomy Term Permissions 6
Same name and namespace in other branches
- 7 term_permissions.module \term_permissions_allowed()
Given a term ID, determine if a user has access to that term. UID 1 is always allowed access. If no permissions are set on the term, allow access by default.
Parameters
$tid: The term ID to look up.
$user: The user to determine if it has access to the term ID.
Return value
bool TRUE if the user has access to the term, otherwise FALSE.
1 call to term_permissions_allowed()
- term_permissions_form_alter in ./term_permissions.module 
- Implementation of hook_form_alter()
File
- ./term_permissions.module, line 205 
- Allows access to terms in a vocabulary to be limited by user or role.
Code
function term_permissions_allowed($tid, $user) {
  if ($user->uid == 1) {
    return TRUE;
  }
  // Are permissions enabled on this term?
  if (!(db_result(db_query("SELECT COUNT(1) FROM {term_permissions_user} WHERE tid = %d", $tid)) || db_result(db_query("SELECT COUNT(1) FROM {term_permissions_role} WHERE tid = %d", $tid)))) {
    return TRUE;
  }
  // Permissions are enabled, check to see if this user or one of their roles
  // is allowed.
  if (db_result(db_query("SELECT uid FROM {term_permissions_user} WHERE tid = %d AND uid = %d", $tid, $user->uid)) || db_result(db_query("SELECT rid FROM {term_permissions_role} WHERE tid = %d AND rid IN (" . implode(', ', array_keys($user->roles)) . ")", $tid))) {
    return TRUE;
  }
  return FALSE;
}