You are here

function _og_massadd_fromstring in Organic Groups Mass Add 7

Same name and namespace in other branches
  1. 6 og_massadd.module \_og_massadd_fromstring()

Mass adding users from string input

1 call to _og_massadd_fromstring()
og_massadd_massadd_form_submit in ./og_massadd.module
Mass adding users submit function

File

./og_massadd.module, line 208
The og_massadd module file

Code

function _og_massadd_fromstring($input, $group_type, $group_ids) {

  // Fill our data array
  $data = explode("\n", $input);
  foreach ($data as $i => $line) {
    if (trim($line)) {
      $data[$i] = array_map("trim", explode(",", $line));
    }
    else {
      unset($data[$i]);
    }
  }
  $status = array(
    "new" => array(),
    "failed" => array(),
    "existing" => array(),
  );
  foreach ($data as $line) {
    $address = _og_massadd_adduser($line, $group_type, $group_ids);
    if ($address === FALSE) {
      $status['failed'][] = implode(",", $line);
    }
    elseif ($address == 0) {
      $status['existing'][] = implode(",", $line);
    }
    elseif ($address == 1) {
      $status['new'][] = implode(",", $line);
    }
  }
  if (count($status['new'])) {
    drupal_set_message(t("The following users were created and added to the group(s):") . "<br />" . implode("<br />", $status['new']));
  }
  if (count($status['existing'])) {
    drupal_set_message(t("The following users already had an account and were added to the group(s):") . "<br />" . implode("<br />", $status['existing']));
  }
  if (count($status['failed'])) {
    drupal_set_message(t("The following users could not be added:") . "<br />" . implode("<br />", $status['failed']), 'error');
  }
}