You are here

function og_rules_get_members in Organic groups 7.2

Same name and namespace in other branches
  1. 7 og.rules.inc \og_rules_get_members()

Action: Get group members from a group content.

1 string reference to 'og_rules_get_members'
og_rules_action_info in ./og.rules.inc
Implements hook_rules_action_info().

File

./og.rules.inc, line 282
Rules integration for the Organic groups module.

Code

function og_rules_get_members($group_content) {
  if (!isset($group_content->og_membership)) {

    // Not a group content.
    return;
  }
  $members = array();
  foreach ($group_content->og_membership
    ->value() as $og_membership) {

    // Get the group members the group content belongs to.
    $current_members = db_select('og_membership', 'om')
      ->fields('om', array(
      'etid',
    ))
      ->condition('om.gid', $og_membership->gid)
      ->condition('om.group_type', $og_membership->group_type)
      ->condition('om.entity_type', 'user')
      ->execute()
      ->fetchCol();
    $members = array_merge($members, $current_members);
  }

  // Remove duplicate items.
  $members = array_keys(array_flip($members));
  return array(
    'group_members' => $members,
  );
}