Revert "MDL-34332 completion: timeenrolled not always set correctly"

This reverts commit 154a72b002.
This commit is contained in:
Dan Poltawski
2012-11-01 12:02:49 +08:00
parent 92c99211af
commit 926f51436b
6 changed files with 101 additions and 503 deletions
-60
View File
@@ -566,64 +566,4 @@ EOD;
return $DB->get_record('scale', array('id'=>$id), '*', MUST_EXIST);
}
/**
* Create a test enrolment
* @param array|stdClass $record
* @return boolean
*/
function create_enrolment($record = null) {
global $DB, $CFG;
require_once("{$CFG->libdir}/enrollib.php");
$record = (array)$record;
if (empty($record['courseid'])) {
throw new coding_exception('courseid must be present in phpunit_util::create_enrolment() $record');
}
if (empty($record['userid'])) {
throw new coding_exception('userid must be present in phpunit_util::create_enrolment() $record');
}
if (empty($record['roleid'])) {
$record['roleid'] = null;
}
if (empty($record['timestart'])) {
$record['timestart'] = 0;
}
if (empty($record['timeend'])) {
$record['timeend'] = 0;
}
if (empty($record['plugin'])) {
$record['plugin'] = 'manual';
}
if (!enrol_is_enabled($record['plugin'])) {
return false;
}
if (!$enrol = enrol_get_plugin($record['plugin'])) {
return false;
}
$params = array(
'enrol' => $record['plugin'],
'courseid' => $record['courseid'],
'status' => ENROL_INSTANCE_ENABLED
);
if (!$instances = $DB->get_records('enrol', $params, 'sortorder,id ASC')) {
return false;
}
$instance = reset($instances);
$enrol->enrol_user($instance, $record['userid'], $record['roleid'], $record['timestart'], $record['timeend']);
return true;
}
}