/** * Update grades in central gradebook * * @param object $hotpot null means all hotpots * @param int $userid specific user only, 0 mean all */ function hotpot_update_grades($hotpot = null, $userid = 0, $nullifnone = true) { global $CFG; if (!function_exists('grade_update')) { //workaround for buggy PHP versions require_once $CFG->libdir . '/gradelib.php'; } if ($hotpot) { if ($grades = hotpot_get_user_grades($hotpot, $userid)) { hotpot_grade_item_update($hotpot, $grades); } else { if ($userid && $nullifnone) { $grade = new object(); $grade->userid = $userid; $grade->rawgrade = null; hotpot_grade_item_update($hotpot, $grade); } else { hotpot_grade_item_update($hotpot); } } } else { $sql = "SELECT h.*, cm.idnumber as cmidnumber\n FROM {$CFG->prefix}hotpot h, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=s.id"; if ($rs = get_recordset_sql($sql)) { while ($hotpot = rs_fetch_next_record($rs)) { hotpot_update_grades($hotpot, 0, false); } rs_close($rs); } } }
/** * Update grades in central gradebook * this function is called from db/upgrade.php * it is initially called with no arguments, which forces it to get a list of all hotpots * it then iterates through the hotpots, calling itself to create a grade record for each hotpot * * @param object $hotpot null means all hotpots * @param int $userid specific user only, 0 means all users */ function hotpot_update_grades($hotpot = null, $userid = 0, $nullifnone = true) { global $CFG; if (!function_exists('grade_update')) { require_once $CFG->libdir . '/gradelib.php'; } if (is_null($hotpot)) { // update (=create) grades for all hotpots $sql = "\n SELECT h.*, cm.idnumber as cmidnumber\n FROM {$CFG->prefix}hotpot h, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=h.id"; if ($rs = get_recordset_sql($sql)) { while ($hotpot = rs_fetch_next_record($rs)) { hotpot_update_grades($hotpot, 0, false); } rs_close($rs); } } else { // update (=create) grade for a single hotpot if ($grades = hotpot_get_user_grades($hotpot, $userid)) { hotpot_grade_item_update($hotpot, $grades); } else { if ($userid && $nullifnone) { // no grades for this user, but we must force the creation of a "null" grade record $grade = new object(); $grade->userid = $userid; $grade->rawgrade = null; hotpot_grade_item_update($hotpot, $grade); } else { // no grades and no userid hotpot_grade_item_update($hotpot); } } } }
/** * Update grades in central gradebook * @global object * @global object * @param object $hotpot * @param int $userid specific user only, 0 means all users * @param bool $nullifnone */ function hotpot_update_grades($hotpot, $userid = 0, $nullifnone = true) { global $CFG, $DB; require_once $CFG->libdir . '/gradelib.php'; // update (=create) grade for a single hotpot if ($grades = hotpot_get_user_grades($hotpot, $userid)) { hotpot_grade_item_update($hotpot, $grades); } else { if ($userid && $nullifnone) { // no grades for this user, but we must force the creation of a "null" grade record $grade = new object(); $grade->userid = $userid; $grade->rawgrade = null; hotpot_grade_item_update($hotpot, $grade); } else { // no grades and no userid hotpot_grade_item_update($hotpot); } } }