. include_once('../../../config.php'); require_once($CFG->libdir . '/gradelib.php'); require_once $CFG->dirroot.'/grade/lib.php'; $courseid = required_param('id', PARAM_INT); // course id if (!$course = get_record('course', 'id', $courseid)) { print_error('nocourseid'); } require_login($course->id); $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('gradereport/outcomes:view', $context); //first make sure we have proper final grades grade_regrade_final_grades($courseid); // Grab all outcomes used in course $report_info = array(); $outcomes = grade_outcome::fetch_all_available($courseid); // Get grade_items that use each outcome foreach ($outcomes as $outcomeid => $outcome) { $report_info[$outcomeid]['items'] = get_records_select('grade_items', "outcomeid = $outcomeid AND courseid = $courseid"); $report_info[$outcomeid]['outcome'] = $outcome; // Get average grades for each item if (is_array($report_info[$outcomeid]['items'])) { foreach ($report_info[$outcomeid]['items'] as $itemid => $item) { $sql = "SELECT itemid, AVG(finalgrade) AS avg, COUNT(finalgrade) AS count FROM {$CFG->prefix}grade_grades WHERE itemid = $itemid GROUP BY itemid"; $info = get_records_sql($sql); if (!$info) { unset($report_info[$outcomeid]['items'][$itemid]); continue; } else { $info = reset($info); $avg = round($info->avg, 2); $count = $info->count; } $report_info[$outcomeid]['items'][$itemid]->avg = $avg; $report_info[$outcomeid]['items'][$itemid]->count = $count; } } } $html = '
' . get_string('outcomename', 'grades') . ' | '; $html .= '' . get_string('courseavg', 'grades') . ' | '; $html .= '' . get_string('sitewide', 'grades') . ' | '; $html .= '' . get_string('activities', 'grades') . ' | '; $html .= '' . get_string('average', 'grades') . ' | '; $html .= '' . get_string('numberofgrades', 'grades') . ' |
---|---|---|---|---|---|
' . $outcomedata['outcome']->shortname . " | \n"; $sitewide = get_string('no'); if (empty($outcomedata['outcome']->courseid)) { $sitewide = get_string('yes'); } $sitewide_html = '' . $sitewide . " | \n"; $outcomedata['outcome']->sum = 0; $scale = new grade_scale(array('id' => $outcomedata['outcome']->scaleid), false); $print_tr = false; $items_html = ''; if (!empty($outcomedata['items'])) { foreach ($outcomedata['items'] as $itemid => $item) { if ($print_tr) { $row++; $items_html .= "||||
$itemname | " . "$gradehtml ($item->avg) | " . "$item->count | - | - | 0 | \n"; } // Calculate outcome average if (is_array($outcomedata['items'])) { $count = count($outcomedata['items']); if ($count > 0) { $avg = $outcomedata['outcome']->sum / $count; } else { $avg = $outcomedata['outcome']->sum; } $avg_html = $scale->get_nearest_item($avg) . " (" . round($avg, 2) . ")\n"; } else { $avg_html = ' - '; } $outcomeavg_html = '' . $avg_html . " | \n"; $html .= $shortname_html . $outcomeavg_html . $sitewide_html . $items_html; $row++; } $html .= '