= 1"); $groups = array(); while ($group = db_fetch_array($result)) { $groups[$group['nid']][] = $group['uid']; } return $groups; } function gou_count_users() { return db_result(db_query('SELECT COUNT(*) FROM {users} WHERE uid > 0')); } function gou_assign_users($nid, $admins, $limit = NULL) { $sql = 'INSERT INTO og_uid (nid, uid, is_active, mail_type) SELECT %d, uid, 1, 1 FROM users u WHERE u.uid NOT IN ('. str_pad('', count($admins) * 3 - 1, '%d,') .') ORDER BY RAND()'; if ($limit) { $sql .= " LIMIT $limit"; } db_query($sql, $nid, implode(',', $admins)); } $users = gou_count_users(); $groups = gou_get_groups(); foreach ($groups as $nid => $group) { $node = node_load($nid); drupal_set_message(t('Assigned %n users to group %t.', array('%n' => $users, '%t' => theme('placeholder', $node->title)))); gou_assign_users($nid, $group, $users); $users = floor($users / 2 + count($group)); }