$table .= ", {$CFG->prefix}user u"; $order = "u.lastname, a.attempt, a.timefinish"; // get the attempts (at last!) $attempts = get_records_sql("SELECT {$fields} FROM {$table} WHERE {$select} ORDER BY {$order}"); } // stop now if no attempts were found if (empty($attempts)) { print_heading(get_string('noattemptstoshow', 'quiz')); exit; } // get the questions if (!($questions = get_records_select('hotpot_questions', "hotpot='{$hotpot->id}'"))) { $questions = array(); } // get grades $grades = hotpot_get_grades($hotpot, $user_ids); // get list of attempts by user and set reference to last attempt in clickreport series $users = array(); foreach ($attempts as $id => $attempt) { $userid = $attempt->userid; if (!isset($users[$userid])) { $users[$userid]->grade = isset($grades[$userid]) ? $grades[$userid] : ' '; $users[$userid]->attempts = array(); } $users[$userid]->attempts[] =& $attempts[$id]; if ($mode == 'click') { // shortcut to clickreportid (=the id of the FIRST attempt in this clickreport series) $clickreportid = $attempt->clickreportid; if (isset($cr_attempts[$clickreportid])) { // store id and finish time of LAST attempt in this clickreport series $attempts[$id]->cr_lastclick = $cr_attempts[$clickreportid]->id;
function hotpot_grades($hotpotid) { /// Must return an array of grades for a given instance of this module, /// indexed by user. It also returns a maximum allowed grade. $hotpot = get_record('hotpot', 'id', $hotpotid); $return->grades = hotpot_get_grades($hotpot); $return->maxgrade = $hotpot->grade; return $return; }
/** * Return grade for given user or all users. * * @param object $hotpot * @param int $userid optional user id, 0 means all users * @return array array of grades, false if none */ function hotpot_get_user_grades($hotpot, $userid = 0) { $grades = array(); if ($hotpotgrades = hotpot_get_grades($hotpot, $userid)) { foreach ($hotpotgrades as $hotpotuserid => $hotpotgrade) { $grades[$hotpotuserid] = new stdClass(); $grades[$hotpotuserid]->id = $hotpotuserid; $grades[$hotpotuserid]->userid = $hotpotuserid; $grades[$hotpotuserid]->rawgrade = $hotpotgrade; } } if (count($grades)) { return $grades; } else { return false; } }
/** * Update hotpot grades in the gradebook * * Needed by grade_update_mod_grades() in lib/gradelib.php * * @param stdclass $hotpot instance object with extra cmidnumber and modname property * @param integer $userid >0 update grade of specific user only, 0 means all participants * @param boolean $nullifnone TRUE = force creation of NULL grade if this user has no grade * @return boolean TRUE if successful, FALSE otherwise * @return void */ function hotpot_update_grades($hotpot = null, $userid = 0, $nullifnone = true) { global $CFG, $DB; // get hotpot object require_once $CFG->dirroot . '/mod/hotpot/locallib.php'; if ($hotpot === null) { // update/create grades for all hotpots // set up sql strings $strupdating = get_string('updatinggrades', 'mod_hotpot'); $select = 'h.*, cm.idnumber AS cmidnumber'; $from = '{hotpot} h, {course_modules} cm, {modules} m'; $where = 'h.id = cm.instance AND cm.module = m.id AND m.name = ?'; $params = array('hotpot'); // get previous record index (if any) $configname = 'update_grades'; $configvalue = get_config('mod_hotpot', $configname); if (is_numeric($configvalue)) { $i_min = intval($configvalue); } else { $i_min = 0; } if ($i_max = $DB->count_records_sql("SELECT COUNT('x') FROM {$from} WHERE {$where}", $params)) { if ($rs = $DB->get_recordset_sql("SELECT {$select} FROM {$from} WHERE {$where}", $params)) { if (defined('CLI_SCRIPT') && CLI_SCRIPT) { $bar = false; } else { $bar = new progress_bar('hotpotupgradegrades', 500, true); } $i = 0; foreach ($rs as $hotpot) { // update grade if ($i >= $i_min) { upgrade_set_timeout(); // apply for more time (3 mins) hotpot_update_grades($hotpot, $userid, $nullifnone); } // update progress bar $i++; if ($bar) { $bar->update($i, $i_max, $strupdating . ": ({$i}/{$i_max})"); } // update record index if ($i > $i_min) { set_config($configname, $i, 'mod_hotpot'); } } $rs->close(); } } // delete the record index unset_config($configname, 'mod_hotpot'); return; // finish here } // sanity check on $hotpot->id if (!isset($hotpot->id)) { return false; } $grades = hotpot_get_grades($hotpot, $userid); if (count($grades)) { 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 hotpot_grade_item_update($hotpot, (object) array('userid' => $userid, 'rawgrade' => null)); } else { // no grades and no userid hotpot_grade_item_update($hotpot); } } }