Skip to content

Instantly share code, notes, and snippets.

@danpoltawski
Created August 1, 2012 03:26
Show Gist options
  • Select an option

  • Save danpoltawski/3223376 to your computer and use it in GitHub Desktop.

Select an option

Save danpoltawski/3223376 to your computer and use it in GitHub Desktop.
enrol all users to a course
<?php
define('CLI_SCRIPT', true);
require_once('config.php');
require_once($CFG->dirroot.'/user/lib.php');
define('COURSEID', 2);
define('STUDENTROLEID', 5);
$enrol = enrol_get_plugin('manual');
$enrolinstances = enrol_get_instances(COURSEID, true);
$rs = $DB->get_recordset_sql('SELECT id FROM {user} WHERE id > 2');
foreach ($rs as $r) {
$enrol->enrol_user($enrolinstances[1], $r->id, STUDENTROLEID);
}
$rs->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment