You are here

function oa_core_remove_member in Open Atrium Core 7.2

Menu callback to remove user from group

Parameters

$group_type:

$gid:

$uid:

1 string reference to 'oa_core_remove_member'
oa_core_menu in ./oa_core.module
Implements hook_menu().

File

./oa_core.module, line 982

Code

function oa_core_remove_member($group_type, $gid, $from_children, $uid, $type = 'nojs') {
  if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], $group_type . '_' . $gid . '_' . $uid)) {
    return MENU_ACCESS_DENIED;
  }
  $account = user_load($uid);
  $group = entity_load_single($group_type, $gid);
  $label = entity_label($group_type, $group);
  $username = format_username($account);
  og_ungroup('node', $group->nid, 'user', $account);
  if ($from_children == 'all' && module_exists('oa_subspaces') && og_user_access('node', $group->nid, 'administer group') && ($children = og_subgroups_children_load('node', $group->nid)) && ($user_groups = og_get_entity_groups('user', $account))) {
    if ($remove = og_subgroups_intersect_groups($children, $user_groups)) {
      foreach ($remove as $entity_type => $ids) {
        foreach ($ids as $id) {
          $child_group = entity_load_single($entity_type, $id);
          og_ungroup($entity_type, $id, 'user', $account);
          $child_label = entity_label($entity_type, $child_group);
          drupal_set_message(t('%user has been removed from child @type %title.', array(
            '@type' => drupal_strtolower(node_type_get_name($child_group->type)),
            '%user' => $username,
            '%title' => $child_label,
          )));
        }
      }
    }
  }
  drupal_set_message(t('%user has been removed from the @type %title.', array(
    '@type' => drupal_strtolower(node_type_get_name($group->type)),
    '%user' => $username,
    '%title' => $label,
  )));
  if ($type != 'ajax') {
    drupal_goto();
  }
  else {
    $commands = array();
    $commands[] = ajax_command_append('#oa-core-messages', theme('status_messages'));
    $page = array(
      '#type' => 'ajax',
      '#commands' => $commands,
    );
    ajax_deliver($page);
  }
  return NULL;
}