public function GroupType::getRoles in Group 7
Retrieve all possible roles for a group type.
Parameters
bool $special: Include special roles 'anonymous', 'outsider' and 'member'.
bool $reset: Whether to reset the internal cache.
Return value
array A list of GroupRole entities.
See also
1 call to GroupType::getRoles()
- GroupType::removeRoles in classes/
group_type.inc - Delete all possible roles for a group type.
File
- classes/
group_type.inc, line 50 - Defines the Entity API class for group types.
Class
- GroupType
- Main class for group type entities.
Code
public function getRoles($special = TRUE, $reset = FALSE) {
if (empty($this->entityCache) || $reset) {
// We're about to fake two type specific roles: outsider and member.
$values = array(
'type' => $this->name,
'global' => 0,
);
// Fake the anonymous role.
$values['name'] = 'anonymous';
$values['label'] = t('Anonymous');
$values['permissions'] = $this->anonymous_permissions;
$group_roles['anonymous'] = entity_create('group_role', $values);
// Fake the outsider role.
$values['name'] = 'outsider';
$values['label'] = t('Outsider');
$values['permissions'] = $this->outsider_permissions;
$group_roles['outsider'] = entity_create('group_role', $values);
// Fake the member role.
$values['name'] = 'member';
$values['label'] = t('Member');
$values['permissions'] = $this->member_permissions;
$group_roles['member'] = entity_create('group_role', $values);
// Unset the is_new flags to avoid confusion.
unset($group_roles['anonymous']->is_new, $group_roles['outsider']->is_new, $group_roles['member']->is_new);
// Add the local roles for this group type.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'group_role');
$query
->propertyCondition('type', $this->name);
$query
->propertyOrderBy('weight');
$result = $query
->execute();
if (isset($result['group_role'])) {
$group_roles += group_roles(array_keys($result['group_role']));
}
// Add global roles.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'group_role');
$query
->propertyCondition('global', 1);
$query
->propertyOrderBy('weight');
$result = $query
->execute();
if (isset($result['group_role'])) {
$group_roles += group_roles(array_keys($result['group_role']));
}
$this->entityCache = $group_roles;
}
$group_roles = $this->entityCache;
if (!$special) {
unset($group_roles['anonymous'], $group_roles['outsider'], $group_roles['member']);
}
return $group_roles;
}