Skip to content

Instantly share code, notes, and snippets.

@acao
Last active August 29, 2015 14:04
Show Gist options
  • Save acao/8102b7eb2fc43164c528 to your computer and use it in GitHub Desktop.
Save acao/8102b7eb2fc43164c528 to your computer and use it in GitHub Desktop.
/**
* Implements hook_node_accces().
*/
function example_schedules_node_access($node, $op, $account) {
if ($op !== 'view' && $node->type == 'class') {
if($profile = example_account_profile($account->uid)){
if ($profile->type == 'teacher') {
if ($op == 'create'){
return NODE_ACCESS_ALLOW;
}
$teacher = isset($node->field_teacher[LANGUAGE_NONE][0]['target_id']) ? $node->field_teacher[LANGUAGE_NONE][0]['target_id'] : 0;
if ($teacher == $profile->nid) {
return NODE_ACCESS_ALLOW;
}
}
else {
$venue = isset($node->field_venue[LANGUAGE_NONE][0]['target_id']) ? $node->field_venue[LANGUAGE_NONE][0]['target_id'] : 0;
if ($venue == $profile->nid) {
return NODE_ACCESS_ALLOW;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment