function _og_massadd_fromstring in Organic Groups Mass Add 6
Same name and namespace in other branches
- 7 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 152 - The og_massadd module file
Code
function _og_massadd_fromstring($input, $groups) {
// 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, $groups);
if ($address === FALSE) {
$status['failed'][] = implode(",", $line);
}
else {
if ($address == 0) {
$status['existing'][] = implode(",", $line);
}
else {
if ($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');
}
}