I worked this out this afternoon. With the following code modifications you can automatically register users to cohorts.
Edit admin/uploaduserlib.php at line 200:
} else if (preg_match('/^(course|group|type|role|enrolperiod)\d+$/', $lcfield)) {
to
} else if (preg_match('/^(course|group|type|role|enrolperiod|cohort)\d+$/', $lcfield)) {
Edit admin/uploaduser.php
After line 32 add:
require_once($CFG->dirroot.'/cohort/lib.php');
Edit admin/uploaduser.php at approximately line 700 add code below
// find cohort enrolments
foreach ($filecolumns as $column) {
if(!preg_match('/^cohort\d+$/', $column)) {
continue;
}
$i = substr($column, 6);
if(empty($user->{'cohort'.$i})) {
continue;
}
if (!empty($user->{'cohort'.$i})) {
$cShortname = $user->{'cohort'.$i};
// check if assigned to a cohort
if($DB->record_exists('cohort', array('idnumber'=>$cShortname))) {
// Get cohertId
$cohortData = $DB->get_record('cohort',array('idnumber'=>$cShortname));
cohort_add_member($cohortData->id, $user->id);
}
}
}
A sample CSV file would be:
firstname, lastname, username, cohort1, cohort2, cohort3
Joe, Bloggs, jbloggs, x, y, z
cohort1 etc must be the cohort id