You are here

function og_ui_user_admin_account in Organic groups 7

Form builder; OG user administration page.

See also

og_ui_user_admin_account_validate().

og_ui_user_admin_account_submit().

1 string reference to 'og_ui_user_admin_account'
og_ui_menu in og_ui/og_ui.module
Implements hook_menu().

File

og_ui/og_ui.admin.inc, line 179
Admin settings for Organic groups module.

Code

function og_ui_user_admin_account($form, $form_state, $entity_type, $etid) {
  og_set_breadcrumb($entity_type, $etid, array(
    l(t('Group'), "{$entity_type}/{$etid}/group"),
  ));
  $group = og_get_group($entity_type, $etid);

  // Get the group real entity, so we can check the user ID of the entity.
  $entity = $group
    ->getEntity();
  $form['group'] = array(
    '#type' => 'value',
    '#value' => $group,
  );
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update options'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );
  $options = array();
  foreach (module_implements('og_user_operations') as $module) {
    $result = call_user_func($module . '_og_user_operations', array(), array(
      'group' => $group,
    ));
    foreach ($result as $operation => $array) {
      $options[$operation] = $array['label'];
    }
  }
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => 'unblock',
  );
  $options = array();
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );
  $states = og_group_content_states();
  $roles = og_roles($group->gid);
  $header = array(
    'username' => array(
      'data' => t('Username'),
      'field' => 'u.name',
    ),
    'state' => array(
      'data' => t('State'),
      'field' => 'ogm.state',
    ),
    'roles' => array(
      'data' => t('Roles'),
    ),
    'member_for' => array(
      'data' => t('Member for'),
      'field' => 'ogm.created',
      'sort' => 'desc',
    ),
  );
  $query = db_select('users', 'u');
  $query
    ->innerJoin('og_membership', 'ogm', 'u.uid = ogm.etid');
  $query
    ->condition('ogm.gid', $group->gid, '=')
    ->condition('ogm.entity_type', 'user', '=');
  $count_query = clone $query;
  $count_query
    ->addExpression('COUNT(u.uid)');
  $query = $query
    ->extend('PagerDefault')
    ->extend('TableSort');
  $query
    ->fields('u', array(
    'uid',
    'name',
  ))
    ->fields('ogm', array(
    'state',
    'created',
  ))
    ->limit(25)
    ->orderByHeader($header)
    ->setCountQuery($count_query);
  $result = $query
    ->execute();
  foreach ($result as $row) {

    // Note that we allow editing of the group manager, but will make sure on
    // submit that they can not be removed from group.
    $users_roles = array();
    foreach (og_get_user_roles($group->gid, $row->uid) as $rid) {
      if (!in_array($roles[$rid], array(
        OG_ANONYMOUS_ROLE,
        OG_AUTHENTICATED_ROLE,
      ))) {

        // Show the user's roles, except of the authenticated role, that all
        // group members have, or anonymous that blocked members have.
        $users_roles[] = $roles[$rid];
      }
    }
    asort($users_roles);
    $account = user_load($row->uid);
    $options[$account->uid] = array(
      'username' => theme('username', array(
        'account' => $account,
      )),
      'state' => $states[$row->state],
      'roles' => theme('item_list', array(
        'items' => $users_roles,
      )),
      'member_for' => format_interval(REQUEST_TIME - $row->created),
    );
  }

  // Add group manager details.
  $form['group_manager'] = array(
    '#type' => 'item',
    '#title' => t('Group manager'),
    '#markup' => theme('username', array(
      'account' => $entity,
    )),
  );
  $form['accounts'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => !empty($entity->uid) ? t('No people available apart of the group manager.') : t('No people available.'),
  );
  $form['pager'] = array(
    '#markup' => theme('pager', array(
      'tags' => NULL,
    )),
  );
  return $form;
}