Answers:
直接使用有机群组API:
og_get_group_members_properties($yourGroupNode, array(), 'members', 'node');
为您提供了一组用户ID。
要仅获取活动,待处理或已阻止的用户,可以将“ members__1”,“ members__2”或“ members__3”代替“ members”,例如以下示例:
og_get_group_members_properties($yourGroupNode, array(), 'members__1', 'node');
的,如果您愿意,像这样的一个:
og_get_group_members_properties($yourGroupNode, array(), 'members__' . OG_STATE_ACTIVE, 'node');
返回值的示例:
Array
(
[0] => 48
[1] => 49
[2] => 51
)
或通过DBTNG:
$query = db_select("og_membership", "ogm");
$query->condition("ogm.gid", $yourGroupID, "=");
$query->condition("ogm.group_type", "node", "=");
$query->fields("ogm", array("entity_type", "etid"));
$result = $query->execute();
print_r($result->fetchAll());
...这使您可以联接其他表,而不必像使用一样过滤PHP代码中的结果集EntityFieldQuery
。
$query = new EntityFieldQuery();
$query
->entityCondition("entity_type", "og_membership", "=")
->propertyCondition("gid", $yourGroupID, "=");
$result = $query->execute();
print_r($result["og_membership"]);
(基于http://api.drupal.org/api/drupal/includes--common.inc/function/entity_load/7#comment-14544)
smokris解决方案有效,但我发现了另一种方法EntityFieldQuery
:
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->fieldCondition('og_group_ref', 'target_id', $yourGroupID)
->execute();
返回值的示例:
{"node":
{"22":{"nid":"22","vid":"22","type":"panoramique"},
"32":{"nid":"32","vid":"32","type":"panoramique"},
"35":{"nid":"35","vid":"35","type":"panoramique"},
"36":{"nid":"36","vid":"36","type":"panoramique"}
}
}
扩展@smokris的答案。
成员资格的活动状态为“ 1”(->condition('ogm.state', 1, '=')
)。
function _get_users_in_group($gid) {
$query = db_select('users', 'u');
$query
->condition('u.uid', 0, '<>')
->condition('u.status', 1, '=')
->condition('ogm.state', 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));
return $query->execute();
}