/** * Removes all grades from gradebook * * @global stdClass * @global object * @param int $courseid * @param string optional type */ function lesson_reset_gradebook($courseid, $type = '') { global $CFG, $DB; $sql = "SELECT l.*, cm.idnumber as cmidnumber, l.course as courseid\n FROM {lesson} l, {course_modules} cm, {modules} m\n WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id AND l.course=:course"; $params = array("course" => $courseid); if ($lessons = $DB->get_records_sql($sql, $params)) { foreach ($lessons as $lesson) { lesson_grade_item_update($lesson, 'reset'); } } }
/** * Removes all grades from gradebook * @param int $courseid * @param string optional type */ function lesson_reset_gradebook($courseid, $type = '') { global $CFG; $sql = "SELECT l.*, cm.idnumber as cmidnumber, l.course as courseid\n FROM {$CFG->prefix}lesson l, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id AND l.course={$courseid}"; if ($lessons = get_records_sql($sql)) { foreach ($lessons as $lesson) { lesson_grade_item_update($lesson, 'reset'); } } }
/** * Update grades in central gradebook * * @param object $lesson null means all lessons * @param int $userid specific user only, 0 mean all */ function lesson_update_grades($lesson = null, $userid = 0, $nullifnone = true) { global $CFG; if (!function_exists('grade_update')) { //workaround for buggy PHP versions require_once $CFG->libdir . '/gradelib.php'; } if ($lesson != null) { if ($grades = lesson_get_user_grades($lesson, $userid)) { grade_update('mod/lesson', $lesson->course, 'mod', 'lesson', $lesson->id, 0, $grades); } else { if ($userid and $nullifnone) { $grade = new object(); $grade->userid = $userid; $grade->rawgrade = NULL; grade_update('mod/lesson', $lesson->course, 'mod', 'lesson', $lesson->id, 0, $grade); } } } else { $sql = "SELECT l.*, cm.idnumber as cmidnumber, l.course as courseid\n FROM {$CFG->prefix}lesson l, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id"; if ($rs = get_recordset_sql($sql)) { if ($rs->RecordCount() > 0) { while ($lesson = rs_fetch_next_record($rs)) { lesson_grade_item_update($lesson); if ($lesson->grade != 0) { lesson_update_grades($lesson, 0, false); } } } rs_close($rs); } } }