function opigno_access_tools in Opigno 7
Custom access callback for the tools tab on course nodes, or the rendered opigno_tools field.
Parameters
stdClass $node:
Return value
bool
1 call to opigno_access_tools()
- opigno_block_view in ./
opigno.module - Implements hook_block_view().
1 string reference to 'opigno_access_tools'
- opigno_menu in ./
opigno.module - Implements hook_menu().
File
- ./
opigno.module, line 500 - Contains all hook_implementations and module specific API.
Code
function opigno_access_tools($node) {
global $user;
if ($node->type === OPIGNO_COURSE_BUNDLE) {
if ($user->uid === '1') {
return TRUE;
}
$tools = opigno_get_tools($node);
// If there are some tools, we must do some more checking.
if (!empty($tools)) {
// Only allow tool access when the membership is in a certain state.
$allowed_states = variable_get('opigno_access_tools_only_when_state', array(
OG_STATE_ACTIVE,
));
// @todo this is hardcoded for now
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'og_membership', '=')
->propertyCondition('gid', $node->nid, '=')
->propertyCondition('entity_type', 'user', '=')
->propertyCondition('etid', $user->uid, '=');
$result = $query
->execute();
if (!empty($result['og_membership'])) {
$info = current($result['og_membership']);
// There's only one membership.
$og_membership = og_membership_load($info->id);
return in_array((int) $og_membership->state, $allowed_states, TRUE);
}
}
}
return FALSE;
}