Last active
December 19, 2015 00:09
-
-
Save steffenr/5866644 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Helper function to retrieve all members of an organic group. | |
*/ | |
function _get_users_in_group($gid) { | |
$group_members = array(); | |
if (!empty($gid)) { | |
$query = db_select('users', 'u'); | |
$query | |
->condition('u.uid', 0, '<>') | |
->condition('u.status', 1, '=') | |
->fields('u', array('uid', 'name')) | |
->join('og_membership', 'ogm', "ogm.gid = :gid AND u.uid = ogm.etid AND ogm.entity_type = 'user'", array(':gid' => $gid)); | |
$result = $query->execute(); | |
$group_members = $result->fetchAll(); | |
} | |
return $group_members; | |
} | |
// Usage of function in a form element. | |
$group_members = _get_users_in_group(YOUR_GROUP_ID); | |
// Build array used in select field | |
$options = array(); | |
foreach ($group_members as $member) { | |
$options[$member->uid] = $member->name; | |
} | |
$form['members_of_group'] = array( | |
'#type' => 'select', | |
'#title' => t('All Members'), | |
'#default_value' => variable_get('members_of_group', array()), | |
'#description' => t('irgendwas'), | |
'#options' => $options, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment