From 16501647cdbd424099298661522b5e68a1b0328b Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Thu, 21 Jun 2007 09:23:57 +0000 Subject: [PATCH] some grader report code --- grade/report/grader/index.php | 134 ++++++++++++++++++++++++++++++++-- 1 file changed, 128 insertions(+), 6 deletions(-) diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php index 8eb81fc7f4..4062363fdd 100644 --- a/grade/report/grader/index.php +++ b/grade/report/grader/index.php @@ -5,19 +5,141 @@ require_once($CFG->libdir.'/tablelib.php'); include_once($CFG->libdir.'/gradelib.php'); + // get the params $courseid = required_param('id', PARAM_INT); -if (!$userid = optional_param('user', 0, PARAM_INT)) { - // current user - $userid = $USER->id; +$context = get_context_instance(CONTEXT_COURSE, $courseid); +$page = optional_param('page', 0, PARAM_INT); +$sortitemid = optional_param('sortitemid', 0, PARAM_INT); // sort by which grade item + +$perpage = 10; + +// roles to be displaye in the gradebook +$gradebookroles = $CFG->gradebookroles; + +// pulls out the userids of the users to be display, and sort them +// the right outer join is needed because potentially, it is possible not +// to have the corresponding entry in grade_grades table for some users +// this is check for user roles because there could be some users with grades +// but not supposed to be displayed + +if ($sortitemid) { + + $sql = "SELECT u.id, u.firstname, u.lastname, g.itemid, g.finalgrade + FROM {$CFG->prefix}grade_grades g RIGHT OUTER JOIN + {$CFG->prefix}user u ON (u.id = g.userid AND g.itemid = $sortitemid) + LEFT JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid + WHERE ra.roleid in ($gradebookroles) + AND ra.contextid ".get_related_contexts_string($context)." + ORDER BY g.finalgrade ASC"; + $users = get_records_sql($sql, $perpage * $page, $perpage); +} else { + + // get users sorted by lastname + $users = get_role_users(@implode(',', $CFG->gradebookroles), $context, false, '', 'u.lastname ASC', false, 0, $perpage); } +print_object($users); + +// phase 2 sql, we supply the userids in this query, and get all the grades +// pulls out all the grades, this does not need to worry about paging +$sql = "SELECT g.id, g.itemid, g.userid, g.finalgrade + FROM {$CFG->prefix}grade_grades g, + {$CFG->prefix}grade_items gi + WHERE g.itemid = gi.id + AND gi.courseid = $courseid + AND g.userid in (".implode(",", array_keys($users)).")"; -$tree = new grade_tree($courseid, true); -echo $tree->display_grades(); +$grades = get_records_sql($sql); + +print_object($grades); + +$finalgrades = array(); +// needs to be formatted into an array for easy retrival +foreach ($grades as $grade) { + $finalgrades[$grade->userid][$grade->itemid] = $grade->finalgrade; + +} print_heading('Grader Report'); +if ($gtree = new grade_tree($courseid, false)) { + + // 1. Fetch all top-level categories for this course, with all children preloaded, sorted by sortorder + $tree = $gtree->tree_filled; + + if (empty($gtree->tree_filled)) { + debugging("The tree_filled array wasn't initialised, grade_tree could not display the grades correctly."); + return false; + } + + // Fetch array of students enroled in this course + if (!$context = get_context_instance(CONTEXT_COURSE, $gtree->courseid)) { + return false; + } + //$users = get_role_users(@implode(',', $CFG->gradebookroles), $context); + + $topcathtml = ' '; + $cathtml = ' '; + $itemhtml = ' '; + $items = array(); + foreach ($tree as $topcat) { + $itemcount = 0; + + foreach ($topcat['children'] as $catkey => $cat) { + $catitemcount = 0; -?> + foreach ($cat['children'] as $item) { + $itemcount++; + $catitemcount++; + $itemhtml .= '' . $item['object']->itemname . ''; + $items[] = $item; + } + + if ($cat['object'] == 'filler') { + $cathtml .= ' '; + } else { + $cat['object']->load_grade_item(); + $cathtml .= '' . $cat['object']->fullname . ''; + } + } + + if ($topcat['object'] == 'filler') { + $colspan = null; + if (!empty($topcat['colspan'])) { + $colspan = 'colspan="' . $topcat['colspan'] . '" '; + } + $topcathtml .= ' '; + } else { + $topcathtml .= '' . $topcat['object']->fullname . ''; + } + } + + $studentshtml = ''; + + foreach ($users as $userid => $user) { + $studentshtml .= '' . $user->firstname . ' ' . $user->lastname . ''; + foreach ($items as $item) { + // finalgrades[$userid][$itemid] could be null because of the outer join + // in this case it's different than a 0 + if (isset($finalgrades[$userid][$item['object']->id])) { + $studentshtml .= '' . $finalgrades[$userid][$item['object']->id] . '' . "\n"; + } else { + $studentshtml .= '-' . "\n"; + } + } + $studentshtml .= ''; + } + + $itemhtml .= ''; + $cathtml .= ''; + $topcathtml .= ''; + + $reporthtml = "$topcathtml$cathtml$itemhtml"; + $reporthtml .= $studentshtml; + $reporthtml .= "
"; + + echo $reporthtml; +} +?> \ No newline at end of file -- 2.39.5