function og_vocab_get_accessible_vocabs in OG Vocabulary 7
Same name and namespace in other branches
- 6 og_vocab.module \og_vocab_get_accessible_vocabs()
API function; Get all the vocabs a user may access.
This will include the global vocabualries (i.e. ones that aren't associated with a group), and the ones that are associated with a group the user is a member.
@todo: Take care of administrators, we need to show ALL widgets?
Parameters
$entity_type: The entity type.
$bundle: The entity bundle.
$field_name: The field name that is associated with the OG-vocab.
$account: User object. Defaults to current user.
Return value
An array with the vocabulary IDs or an empty array if no vocabulary was found.
1 call to og_vocab_get_accessible_vocabs()
- og_vocab_field_widget_form in ./
og_vocab.module - Implements hook_field_widget_form().
File
- ./
og_vocab.module, line 1363 - Give each group its own system controlled vocabularies.
Code
function og_vocab_get_accessible_vocabs($entity_type, $bundle, $field_name, $account = NULL) {
if (empty($account)) {
global $user;
$account = clone $user;
}
$field = field_info_field($field_name);
$use_context = !empty($field['settings']['handler_settings']['behaviors']['og_vocab']['use_context']) ? $field['settings']['handler_settings']['behaviors']['og_vocab']['use_context'] : 'yes';
$context = FALSE;
$gids = array();
if (in_array($use_context, array(
'force',
'yes',
)) && module_exists('og_context') && ($context = og_context())) {
$gids[$context['group_type']][$context['gid']] = array(
$context['gid'],
);
}
elseif (in_array($use_context, array(
'yes',
'no',
)) && !$gids) {
$gids = og_get_entity_groups('user', $account);
}
if (!$gids) {
return;
}
$query = db_select('og_vocab_relation', 'ogr');
$query
->fields('ogr', array(
'vid',
));
// Prepare a query according to the group types. In the common case that
// the user has only a single group type (e.g. node) we can make a simpler
// query.
if (count($gids) == 1) {
$group_type = key($gids);
$query
->condition('group_type', $group_type)
->condition('gid', $gids[$group_type], 'IN');
}
else {
// TODO
}
// Join with the OG-vocab.
$query
->innerJoin('og_vocab', 'ogv', 'ogr.vid = ogv.vid');
$query
->condition('ogv.entity_type', $entity_type)
->condition('ogv.bundle', $bundle)
->condition('ogv.field_name', $field_name);
$result = $query
->execute()
->fetchAllAssoc('vid');
return !empty($result) ? array_keys($result) : FALSE;
}