function permissions_by_term_allowed in Permissions by Term 7
Implements permissions_by_term_allowed().
5 calls to permissions_by_term_allowed()
- permissions_by_term_form_alter in ./
permissions_by_term.module - Implements hook_form_alter().
- permissions_by_term_node_access in ./
permissions_by_term.module - Implements hook_node_access().
- permissions_by_term_views_post_execute in ./
permissions_by_term.module - Implements hook_views_post_execute().
- _permissions_by_term_remove_disallowed_term_matches in ./
permissions_by_term.module - Removes disallowed term matches by reference.
- _permissions_by_term_remove_restricted_items_in_select_field in ./
permissions_by_term.module - Removes restricted items in select field.
File
- ./
permissions_by_term.module, line 358 - Allows access to terms in a vocabulary to be limited by user or role.
Code
function permissions_by_term_allowed($tid, $user) {
if ($user->uid == 1) {
return TRUE;
}
// Are permissions enabled on this term?
if (!(db_query("SELECT COUNT(1) FROM {permissions_by_term_user} WHERE tid = :tid", array(
':tid' => $tid,
))
->fetchField() || db_query("SELECT COUNT(1) FROM {permissions_by_term_role} WHERE tid = :tid", array(
':tid' => $tid,
))
->fetchField())) {
return TRUE;
}
/* Permissions are enabled, check to see if this user or one of their roles
is allowed.
*/
$user_roles = array_keys($user->roles);
$i = 0;
while (isset($user_roles[$i])) {
if (db_query("SELECT uid FROM {permissions_by_term_user} WHERE tid = :tid AND uid = :uid", array(
':tid' => $tid,
':uid' => $user->uid,
))
->fetchField() || db_query("SELECT rid FROM {permissions_by_term_role} WHERE tid = :tid AND rid IN (:user_roles)", array(
':tid' => $tid,
':user_roles' => $user_roles[$i],
))
->fetchField()) {
return TRUE;
}
$i++;
}
return FALSE;
}