|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00018 include_once('../../../config.php'); 00019 require_once($CFG->libdir . '/gradelib.php'); 00020 require_once $CFG->dirroot.'/grade/lib.php'; 00021 00022 $courseid = required_param('id', PARAM_INT); // course id 00023 00024 $PAGE->set_url('/grade/report/outcomes/index.php', array('id'=>$courseid)); 00025 00026 if (!$course = $DB->get_record('course', array('id' => $courseid))) { 00027 print_error('nocourseid'); 00028 } 00029 00030 require_login($course->id); 00031 $context = get_context_instance(CONTEXT_COURSE, $course->id); 00032 00033 require_capability('gradereport/outcomes:view', $context); 00034 00035 //first make sure we have proper final grades 00036 grade_regrade_final_grades($courseid); 00037 00038 // Grab all outcomes used in course 00039 $report_info = array(); 00040 $outcomes = grade_outcome::fetch_all_available($courseid); 00041 00042 // Get grade_items that use each outcome 00043 foreach ($outcomes as $outcomeid => $outcome) { 00044 $report_info[$outcomeid]['items'] = $DB->get_records_select('grade_items', "outcomeid = ? AND courseid = ?", array($outcomeid, $courseid)); 00045 $report_info[$outcomeid]['outcome'] = $outcome; 00046 00047 // Get average grades for each item 00048 if (is_array($report_info[$outcomeid]['items'])) { 00049 foreach ($report_info[$outcomeid]['items'] as $itemid => $item) { 00050 $sql = "SELECT itemid, AVG(finalgrade) AS avg, COUNT(finalgrade) AS count 00051 FROM {grade_grades} 00052 WHERE itemid = ? 00053 GROUP BY itemid"; 00054 $info = $DB->get_records_sql($sql, array($itemid)); 00055 00056 if (!$info) { 00057 unset($report_info[$outcomeid]['items'][$itemid]); 00058 continue; 00059 } else { 00060 $info = reset($info); 00061 $avg = round($info->avg, 2); 00062 $count = $info->count; 00063 } 00064 00065 $report_info[$outcomeid]['items'][$itemid]->avg = $avg; 00066 $report_info[$outcomeid]['items'][$itemid]->count = $count; 00067 } 00068 } 00069 } 00070 00071 $html = '<table class="generaltable boxaligncenter" width="90%" cellspacing="1" cellpadding="5" summary="Outcomes Report">' . "\n"; 00072 $html .= '<tr><th class="header c0" scope="col">' . get_string('outcomeshortname', 'grades') . '</th>'; 00073 $html .= '<th class="header c1" scope="col">' . get_string('courseavg', 'grades') . '</th>'; 00074 $html .= '<th class="header c2" scope="col">' . get_string('sitewide', 'grades') . '</th>'; 00075 $html .= '<th class="header c3" scope="col">' . get_string('activities', 'grades') . '</th>'; 00076 $html .= '<th class="header c4" scope="col">' . get_string('average', 'grades') . '</th>'; 00077 $html .= '<th class="header c5" scope="col">' . get_string('numberofgrades', 'grades') . '</th></tr>' . "\n"; 00078 00079 $row = 0; 00080 foreach ($report_info as $outcomeid => $outcomedata) { 00081 $rowspan = count($outcomedata['items']); 00082 // If there are no items for this outcome, rowspan will equal 0, which is not good 00083 if ($rowspan == 0) { 00084 $rowspan = 1; 00085 } 00086 00087 $shortname_html = '<tr class="r' . $row . '"><td class="cell c0" rowspan="' . $rowspan . '">' . $outcomedata['outcome']->shortname . "</td>\n"; 00088 00089 $sitewide = get_string('no'); 00090 if (empty($outcomedata['outcome']->courseid)) { 00091 $sitewide = get_string('yes'); 00092 } 00093 00094 $sitewide_html = '<td class="cell c2" rowspan="' . $rowspan . '">' . $sitewide . "</td>\n"; 00095 00096 $outcomedata['outcome']->sum = 0; 00097 $scale = new grade_scale(array('id' => $outcomedata['outcome']->scaleid), false); 00098 00099 $print_tr = false; 00100 $items_html = ''; 00101 00102 if (!empty($outcomedata['items'])) { 00103 foreach ($outcomedata['items'] as $itemid => $item) { 00104 if ($print_tr) { 00105 $row++; 00106 $items_html .= "<tr class=\"r$row\">\n"; 00107 } 00108 00109 $grade_item = new grade_item($item, false); 00110 00111 if ($item->itemtype == 'mod') { 00112 $cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid); 00113 $itemname = '<a href="'.$CFG->wwwroot.'/mod/'.$item->itemmodule.'/view.php?id='.$cm->id.'">'.format_string($cm->name, true, $cm->course).'</a>'; 00114 } else { 00115 $itemname = $grade_item->get_name(); 00116 } 00117 00118 $outcomedata['outcome']->sum += $item->avg; 00119 $gradehtml = $scale->get_nearest_item($item->avg); 00120 00121 $items_html .= "<td class=\"cell c3\">$itemname</td>" 00122 . "<td class=\"cell c4\">$gradehtml ($item->avg)</td>" 00123 . "<td class=\"cell c5\">$item->count</td></tr>\n"; 00124 $print_tr = true; 00125 } 00126 } else { 00127 $items_html .= "<td class=\"cell c3\"> - </td><td class=\"cell c4\"> - </td><td class=\"cell c5\"> 0 </td></tr>\n"; 00128 } 00129 00130 // Calculate outcome average 00131 if (is_array($outcomedata['items'])) { 00132 $count = count($outcomedata['items']); 00133 if ($count > 0) { 00134 $avg = $outcomedata['outcome']->sum / $count; 00135 } else { 00136 $avg = $outcomedata['outcome']->sum; 00137 } 00138 $avg_html = $scale->get_nearest_item($avg) . " (" . round($avg, 2) . ")\n"; 00139 } else { 00140 $avg_html = ' - '; 00141 } 00142 00143 $outcomeavg_html = '<td class="cell c1" rowspan="' . $rowspan . '">' . $avg_html . "</td>\n"; 00144 00145 $html .= $shortname_html . $outcomeavg_html . $sitewide_html . $items_html; 00146 $row++; 00147 } 00148 00149 00150 00151 $html .= '</table>'; 00152 00153 print_grade_page_head($courseid, 'report', 'outcomes'); 00154 00155 00156 echo $html; 00157 echo $OUTPUT->footer(); 00158 00159