function cm_update_class_grades() { global $CFG, $CURMAN; $classid = 0; /// 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. /// Get all classes with unlocked enrolments. $select = 'SELECT cce.classid as classid, COUNT(cce.userid) as numusers '; $from = 'FROM ' . $CFG->prefix . 'crlm_class_enrolment cce '; $where = 'WHERE cce.locked = 0 '; $group = 'GROUP BY classid '; $order = 'ORDER BY classid ASC '; $sql = $select . $from . $where . $group . $order; $rs = get_recordset_sql($sql); if ($rs) { while ($rec = rs_fetch_next_record($rs)) { $cmclass = new cmclass($rec->classid); $cmclass->update_all_class_grades(); } set_time_limit(600); } }