/** * Return a small object with summary information about what a * user has done with a given particular instance of this module * Used for user activity reports. * $return->time = the time they did it * $return->info = a short text description * * @return null * @todo Finish documenting this function */ function checklist_user_outline($course, $user, $mod, $checklist) { global $DB, $CFG; $groupins_sel = ''; if (isset($CFG->enablegroupmembersonly) && $CFG->enablegroupmembersonly && $checklist->autopopulate) { $groupings = checklist_class::get_user_groupings($user->id, $checklist->course); $groupings[] = 0; $groupings_sel = ' AND grouping IN (' . implode(',', $groupings) . ') '; } $sel = 'checklist = ? AND userid = 0 AND itemoptional = ' . CHECKLIST_OPTIONAL_NO; $sel .= ' AND hidden = ' . CHECKLIST_HIDDEN_NO . $groupings_sel; $items = $DB->get_records_select('checklist_item', $sel, array($checklist->id), '', 'id'); if (!$items) { return null; } $total = count($items); list($isql, $iparams) = $DB->get_in_or_equal(array_keys($items)); $sql = "userid = ? AND item {$isql} AND "; if ($checklist->teacheredit == CHECKLIST_MARKING_STUDENT) { $sql .= 'usertimestamp > 0'; $order = 'usertimestamp DESC'; } else { $sql .= 'teachermark = ' . CHECKLIST_TEACHERMARK_YES; $order = 'teachertimestamp DESC'; } $params = array_merge(array($user->id), $iparams); $checks = $DB->get_records_select('checklist_check', $sql, $params, $order); $return = null; if ($checks) { $return = new stdClass(); $ticked = count($checks); $check = reset($checks); if ($checklist->teacheredit == CHECKLIST_MARKING_STUDENT) { $return->time = $check->usertimestamp; } else { $return->time = $check->teachertimestamp; } $percent = sprintf('%0d', $ticked * 100 / $total); $return->info = get_string('progress', 'checklist') . ': ' . $ticked . '/' . $total . ' (' . $percent . '%)'; } return $return; }
static function get_user_progress($checklistid, $userid) { global $DB, $CFG; $userid = intval($userid); // Just to be on the safe side... $checklist = $DB->get_record('checklist', array('id' => $checklistid)); if (!$checklist) { return array(false, false); } $groupings_sel = ''; if (isset($CFG->enablegroupmembersonly) && $CFG->enablegroupmembersonly && $checklist->autopopulate) { $groupings = checklist_class::get_user_groupings($userid, $checklist->course); $groupings[] = 0; $groupings_sel = ' AND grouping IN (' . implode(',', $groupings) . ') '; } $items = $DB->get_records_select('checklist_item', 'checklist = ? AND userid = 0 AND itemoptional = ' . CHECKLIST_OPTIONAL_NO . ' AND hidden = ' . CHECKLIST_HIDDEN_NO . $groupings_sel, array($checklist->id), '', 'id'); if (empty($items)) { return array(false, false); } $total = count($items); list($isql, $iparams) = $DB->get_in_or_equal(array_keys($items)); $params = array_merge(array($userid), $iparams); $sql = "userid = ? AND item {$isql} AND "; if ($checklist->teacheredit == CHECKLIST_MARKING_STUDENT) { $sql .= 'usertimestamp > 0'; } else { $sql .= 'teachermark = ' . CHECKLIST_TEACHERMARK_YES; } $ticked = $DB->count_records_select('checklist_check', $sql, $params); return array($ticked, $total); }