/** * Removes all grades from gradebook * @param int $courseid * @param string optional type */ function data_reset_gradebook($courseid, $type = '') { global $CFG; $sql = "SELECT d.*, cm.idnumber as cmidnumber, d.course as courseid\n FROM {$CFG->prefix}data d, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id AND d.course={$courseid}"; if ($datas = get_records_sql($sql)) { foreach ($datas as $data) { data_grade_item_update($data, 'reset'); } } }
/** * Removes all grades from gradebook * * @global object * @global object * @param int $courseid * @param string $type optional type */ function data_reset_gradebook($courseid, $type='') { global $CFG, $DB; $sql = "SELECT d.*, cm.idnumber as cmidnumber, d.course as courseid FROM {data} d, {course_modules} cm, {modules} m WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id AND d.course=?"; if ($datas = $DB->get_records_sql($sql, array($courseid))) { foreach ($datas as $data) { data_grade_item_update($data, 'reset'); } } }
/** * Update grades by firing grade_updated event * * @param object $data null means all databases * @param int $userid specific user only, 0 mean all */ function data_update_grades($data = null, $userid = 0, $nullifnone = true) { global $CFG; if (!function_exists('grade_update')) { //workaround for buggy PHP versions require_once $CFG->libdir . '/gradelib.php'; } if ($data != null) { if ($grades = data_get_user_grades($data, $userid)) { grade_update('mod/data', $data->course, 'mod', 'data', $data->id, 0, $grades); } else { if ($userid and $nullifnone) { $grade = new object(); $grade->userid = $userid; $grade->rawgrade = NULL; grade_update('mod/data', $data->course, 'mod', 'data', $data->id, 0, $grade); } } } else { $sql = "SELECT d.*, cm.idnumber as cmidnumber\n FROM {$CFG->prefix}data d, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id"; if ($rs = get_recordset_sql($sql)) { if ($rs->RecordCount() > 0) { while ($data = rs_fetch_next_record($rs)) { data_grade_item_update($data); if ($data->assessed) { data_update_grades($data, 0, false); } } } rs_close($rs); } } }