3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
26 include_once('../../../config.php');
27 require_once($CFG->libdir
. '/gradelib.php');
28 require_once $CFG->dirroot
.'/grade/lib.php';
30 $courseid = required_param('id', PARAM_INT
); // course id
32 if (!$course = get_record('course', 'id', $courseid)) {
33 print_error('nocourseid');
36 require_login($course->id
);
37 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
39 require_capability('gradereport/outcomes:view', $context);
42 $strgrades = get_string('grades');
43 $stroutcomes = get_string('outcomes', 'grades');
45 $navigation = grade_build_nav(__FILE__
, $stroutcomes, $course->id
);
48 print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
49 print_grade_plugin_selector($courseid, 'report', 'outcomes');
51 //first make sure we have proper final grades
52 grade_regrade_final_grades($courseid);
54 // Grab all outcomes used in course
55 $report_info = array();
56 $outcomes = grade_outcome
::fetch_all_available($courseid);
58 // Get grade_items that use each outcome
59 foreach ($outcomes as $outcomeid => $outcome) {
60 $report_info[$outcomeid]['items'] = get_records_select('grade_items', "outcomeid = $outcomeid AND courseid = $courseid");
61 $report_info[$outcomeid]['outcome'] = $outcome;
63 // Get average grades for each item
64 if (is_array($report_info[$outcomeid]['items'])) {
65 foreach ($report_info[$outcomeid]['items'] as $itemid => $item) {
66 $sql = "SELECT itemid, AVG(finalgrade) AS avg, COUNT(finalgrade) AS count
67 FROM {$CFG->prefix}grade_grades
68 WHERE itemid = $itemid
70 $info = get_records_sql($sql);
73 unset($report_info[$outcomeid]['items'][$itemid]);
77 $avg = round($info->avg
, 2);
78 $count = $info->count
;
81 $report_info[$outcomeid]['items'][$itemid]->avg
= $avg;
82 $report_info[$outcomeid]['items'][$itemid]->count
= $count;
87 $html = '<table class="generaltable boxaligncenter" width="90%" cellspacing="1" cellpadding="5" summary="Outcomes Report">' . "\n";
88 $html .= '<tr><th class="header c0" scope="col">' . get_string('outcomename', 'grades') . '</th>';
89 $html .= '<th class="header c1" scope="col">' . get_string('courseavg', 'grades') . '</th>';
90 $html .= '<th class="header c2" scope="col">' . get_string('sitewide', 'grades') . '</th>';
91 $html .= '<th class="header c3" scope="col">' . get_string('activities', 'grades') . '</th>';
92 $html .= '<th class="header c4" scope="col">' . get_string('average', 'grades') . '</th>';
93 $html .= '<th class="header c5" scope="col">' . get_string('numberofgrades', 'grades') . '</th></tr>' . "\n";
96 foreach ($report_info as $outcomeid => $outcomedata) {
97 $rowspan = count($outcomedata['items']);
98 // If there are no items for this outcome, rowspan will equal 0, which is not good
103 $shortname_html = '<tr class="r' . $row . '"><td class="cell c0" rowspan="' . $rowspan . '">' . $outcomedata['outcome']->shortname
. "</td>\n";
105 $sitewide = get_string('no');
106 if (empty($outcomedata['outcome']->courseid
)) {
107 $sitewide = get_string('yes');
110 $sitewide_html = '<td class="cell c2" rowspan="' . $rowspan . '">' . $sitewide . "</td>\n";
112 $outcomedata['outcome']->sum
= 0;
113 $scale = new grade_scale(array('id' => $outcomedata['outcome']->scaleid
), false);
118 if (!empty($outcomedata['items'])) {
119 foreach ($outcomedata['items'] as $itemid => $item) {
122 $items_html .= "<tr class=\"r$row\">\n";
125 $grade_item = new grade_item($item, false);
127 if ($item->itemtype
== 'mod') {
128 $cm = get_coursemodule_from_instance($item->itemmodule
, $item->iteminstance
, $item->courseid
);
129 $itemname = '<a href="'.$CFG->wwwroot
.'/mod/'.$item->itemmodule
.'/view.php?id='.$cm->id
.'">'.$grade_item->get_name().'</a>';
131 $itemname = $grade_item->get_name();
134 $outcomedata['outcome']->sum +
= $item->avg
;
135 $gradehtml = $scale->get_nearest_item($item->avg
);
137 $items_html .= "<td class=\"cell c3\">$itemname</td>"
138 . "<td class=\"cell c4\">$gradehtml ($item->avg)</td>"
139 . "<td class=\"cell c5\">$item->count</td></tr>\n";
143 $items_html .= "<td class=\"cell c3\"> - </td><td class=\"cell c4\"> - </td><td class=\"cell c5\"> 0 </td></tr>\n";
146 // Calculate outcome average
147 if (is_array($outcomedata['items'])) {
148 $count = count($outcomedata['items']);
150 $avg = $outcomedata['outcome']->sum
/ $count;
152 $avg = $outcomedata['outcome']->sum
;
154 $avg_html = $scale->get_nearest_item($avg) . " (" . round($avg, 2) . ")\n";
159 $outcomeavg_html = '<td class="cell c1" rowspan="' . $rowspan . '">' . $avg_html . "</td>\n";
161 $html .= $shortname_html . $outcomeavg_html . $sitewide_html . $items_html;
168 print_heading($stroutcomes);
171 print_footer($course);