You are here

function opigno_get_users_in_group in Opigno 7

Helper function to get all users from a course.

Parameters

int $gid:

int $state = OG_STATE_ACTIVE:

Return value

array

2 calls to opigno_get_users_in_group()
opigno_get_course_teachers in ./opigno.module
_opigno_course_students_info in ./opigno.module

File

./opigno.module, line 648
Contains all hook_implementations and module specific API.

Code

function opigno_get_users_in_group($gid, $state = OG_STATE_ACTIVE) {
  $users = array();
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'og_membership')
    ->propertyCondition('group_type', 'node', '=')
    ->propertyCondition('gid', $gid, '=')
    ->propertyCondition('entity_type', 'user', '=')
    ->propertyCondition('state', $state, '=');
  $result = $query
    ->execute();
  if (!empty($result['og_membership'])) {

    // Use a temporary array for sorting.
    $temp = array();
    foreach ($result['og_membership'] as $membership_info) {
      $og_membership = og_membership_load($membership_info->id);
      $account = user_load($og_membership->etid);
      $temp[$account->name] = $account;
    }

    // Sort by name.
    ksort($temp);
    foreach ($temp as $account) {
      $users[$account->uid] = $account;
    }
  }
  return $users;
}