3 include_once('../../../config.php');
4 require_once($CFG->libdir
. '/gradelib.php');
6 $courseid = required_param('id'); // course id
8 if (!$course = get_record('course', 'id', $courseid)) {
9 print_error('nocourseid');
12 require_login($course->id
);
14 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
17 $strgrades = get_string('grades');
18 $stroutcomes = get_string('outcomes', 'grades');
20 $navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot
. '/grade/index.php?id='.$courseid, 'type' => 'misc');
21 $navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc');
23 $navigation = build_navigation($navlinks);
26 print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
29 $currenttab = 'outcomereport';
32 // Grab all outcomes, distinguishing between site-level and course-level outcomes
33 $sql = "SELECT mdl_grade_outcomes.id,
34 mdl_grade_outcomes_courses.courseid,
35 mdl_grade_outcomes.shortname,
36 mdl_grade_outcomes.scaleid
37 FROM mdl_grade_outcomes
38 LEFT JOIN mdl_grade_outcomes_courses
39 ON (mdl_grade_outcomes.id = mdl_grade_outcomes_courses.outcomeid AND mdl_grade_outcomes_courses.courseid = $courseid)
40 ORDER BY mdl_grade_outcomes_courses.courseid DESC";
42 $report_info = array();
43 $outcomes = get_records_sql($sql);
45 // Get grade_items that use each outcome
46 foreach ($outcomes as $outcomeid => $outcome) {
47 $sql = "SELECT mdl_grade_items.id,
48 mdl_grade_items.itemname,
49 mdl_grade_items.itemmodule,
50 mdl_grade_items.iteminstance,
51 mdl_grade_items.itemtype,
52 mdl_grade_items.itemnumber,
53 mdl_grade_items.courseid,
54 mdl_grade_items.idnumber
56 WHERE mdl_grade_items.outcomeid = $outcomeid";
57 $report_info[$outcomeid]['items'] = get_records_sql($sql);
58 $report_info[$outcomeid]['outcome'] = $outcome;
60 // Get average grades for each item
61 if (is_array($report_info[$outcomeid]['items'])) {
62 foreach ($report_info[$outcomeid]['items'] as $itemid => $item) {
63 $sql = "SELECT id, AVG(finalgrade) AS `avg`, COUNT(finalgrade) AS `count`
65 WHERE itemid = $itemid
67 $info = get_records_sql($sql);
69 $report_info[$outcomeid]['items'][$itemid]->avg
= round($info->avg
, 2);
70 $report_info[$outcomeid]['items'][$itemid]->count
= $info->count
;
75 $html = '<table border="1" summary="Outcomes Report">' . "\n";
76 $html .= '<tr><th>' . get_string('outcomename', 'grades') . '</th>';
77 $html .= '<th>' . get_string('overallavg', 'grades') . '</th>';
78 $html .= '<th>' . get_string('sitewide', 'grades') . '</th>';
79 $html .= '<th>' . get_string('activities', 'grades') . '</th>';
80 $html .= '<th>' . get_string('average', 'grades') . '</th>';
81 $html .= '<th>' . get_string('numberofgrades', 'grades') . '</th></tr>' . "\n";
83 foreach ($report_info as $outcomeid => $outcomedata) {
84 $rowspan = count($outcomedata['items']);
85 $shortname_html = '<tr><td rowspan="' . $rowspan . '">' . $outcomedata['outcome']->shortname
. "</td>\n";
87 $sitewide = get_string('no');
88 if (empty($outcomedata['outcome']->courseid
)) {
89 $sitewide = get_string('yes');
92 $sitewide_html = '<td rowspan="' . $rowspan . '">' . $sitewide . "</td>\n";
94 $outcomedata['outcome']->sum
= 0;
95 $scale = new grade_scale(array('id' => $outcomedata['outcome']->scaleid
), false);
100 if (is_array($outcomedata['items'])) {
101 foreach ($outcomedata['items'] as $itemid => $item) {
103 $items_html .= "<tr>\n";
106 $cm = get_coursemodule_from_instance($item->itemmodule
, $item->iteminstance
, $item->courseid
);
107 $itemname = '<a href="'.$CFG->wwwroot
.'/mod/'.$item->itemmodule
.'/view.php?id='.$cm->id
.'">'.$item->itemname
.'</a>';
109 $outcomedata['outcome']->sum +
= $item->avg
;
110 $gradehtml = $scale->get_nearest_item($item->avg
);
112 $items_html .= "<td>$itemname</td><td>$gradehtml ($item->avg)</td><td>$item->count</td></tr>\n";
116 $items_html .= "<td> - </td><td> - </td><td> 0 </td></tr>\n";
119 // Calculate outcome average
120 if (is_array($outcomedata['items'])) {
121 $avg = $outcomedata['outcome']->sum
/ count($outcomedata['items']);
122 $avg_html = $scale->get_nearest_item($avg) . " (" . round($avg, 2) . ")\n";
127 $outcomeavg_html = '<td rowspan="' . $rowspan . '">' . $avg_html . "</td>\n";
129 $html .= $shortname_html . $outcomeavg_html . $sitewide_html . $items_html;
136 print_footer($course);