/** * Update enrolment status of users enroled in all classes, completing and locking * records where applicable based on class grade and required completion elements * * @param int $pmuserid optional userid to update, default(0) updates all users */ function pm_update_enrolment_status($pmuserid = 0) { global $DB; require_once elispm::lib('data/pmclass.class.php'); require_once elispm::lib('data/student.class.php'); /// Need to separate this out so that the enrolments by class are checked for completion. /// ... for each class and then for each enrolment... /// Goal is to minimize database reads, so we can't just instantiate a student object, as /// each one will go and get the same things for one class. So, we probably need a class-level /// function that then manages the student objects. Once this is in place, add completion notice /// to the code. // Note: As of Moodle 2.5, cannot set time limit to non-zero set_time_limit(0); /// Get all classes with unlocked enrolments. $sql = 'SELECT cce.classid as classid, COUNT(cce.userid) as numusers FROM {' . student::TABLE . '} cce INNER JOIN {' . pmclass::TABLE . '} cls ON cls.id = cce.classid WHERE cce.locked = 0'; $params = array(); if ($pmuserid) { $sql .= ' AND cce.userid = ?'; $params = array($pmuserid); } $sql .= ' GROUP BY cce.classid ORDER BY cce.classid ASC'; $rs = $DB->get_recordset_sql($sql, $params); foreach ($rs as $rec) { $pmclass = new pmclass($rec->classid); $pmclass->update_enrolment_status($pmuserid); } }
/** * Validate that credits are correctly transferred from course to enrolment * for a specific user * * @param array $enrolments Enrolment records to create * @param array $expectedenrolments Records to validate * @param array $classids The ids of the classes we should run the method for * @dataProvider dataprovider_credits */ public function test_enrolmentupdatesetscreditsforspecificuserid($enrolments, $expectedenrolments, $classids) { global $DB; $this->load_csv_data(true); // Set up a second course and class. $course = new course(array('name' => 'secondcourse', 'idnumber' => 'secondcourse', 'syllabus' => '', 'credits' => 1)); $course->save(); $pmclass = new pmclass(array('courseid' => $course->id, 'idnumber' => 'secondclass')); $pmclass->save(); $this->save_enrolments($enrolments); $pmuserid = 103; foreach ($classids as $classid) { $pmclass = new pmclass($classid); $sink = $this->redirectMessages(); $pmclass->update_enrolment_status($pmuserid); } $expectedenrolments = $this->filter_by_userid($expectedenrolments, $pmuserid); $this->validate_expected_enrolments($expectedenrolments, $pmuserid); }