. /** * The gradebook outcomes report * * @package gradereport_outcomes * @copyright 2007 Nicolas Connault * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ 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 $PAGE->set_url('/grade/report/outcomes/index.php', array('id'=>$courseid)); if (!$course = $DB->get_record('course', array('id' => $courseid))) { print_error('nocourseid'); } require_login($course); $context = context_course::instance($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); // Will exclude grades of suspended users if required. $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context); if ($showonlyactiveenrol) { $suspendedusers = get_suspended_userids($context); } // Get grade_items that use each outcome. foreach ($outcomes as $outcomeid => $outcome) { $report_info[$outcomeid]['items'] = $DB->get_records_select('grade_items', "outcomeid = ? AND courseid = ?", array($outcomeid, $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) { $params = array(); $hidesuspendedsql = ''; if ($showonlyactiveenrol && !empty($suspendedusers)) { list($notinusers, $params) = $DB->get_in_or_equal($suspendedusers, SQL_PARAMS_QM, null, false); $hidesuspendedsql = ' AND userid ' . $notinusers; } $params = array_merge(array($itemid), $params); $sql = "SELECT itemid, AVG(finalgrade) AS avg, COUNT(finalgrade) AS count FROM {grade_grades} WHERE itemid = ?". $hidesuspendedsql. "GROUP BY itemid"; $info = $DB->get_records_sql($sql, $params); 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 = '' . "\n"; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= '' . "\n"; $row = 0; foreach ($report_info as $outcomeid => $outcomedata) { $rowspan = count($outcomedata['items']); // If there are no items for this outcome, rowspan will equal 0, which is not good. if ($rowspan == 0) { $rowspan = 1; } $shortname_html = '\n"; $sitewide = get_string('no'); if (empty($outcomedata['outcome']->courseid)) { $sitewide = get_string('yes'); } $sitewide_html = '\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 .= "\n"; } $grade_item = new grade_item($item, false); if ($item->itemtype == 'mod') { $cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid); $itemname = ''.format_string($cm->name, true, $cm->course).''; } else { $itemname = $grade_item->get_name(); } $outcomedata['outcome']->sum += $item->avg; $gradehtml = $scale->get_nearest_item($item->avg); $items_html .= "" . "" . "\n"; $print_tr = true; } } else { $items_html .= "\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 = '\n"; $html .= $shortname_html . $outcomeavg_html . $sitewide_html . $items_html; $row++; } $html .= '
' . get_string('outcomeshortname', 'grades') . '' . get_string('courseavg', 'grades') . '' . get_string('sitewide', 'grades') . '' . get_string('activities', 'grades') . '' . get_string('average', 'grades') . '' . get_string('numberofgrades', 'grades') . '
' . $outcomedata['outcome']->shortname . "' . $sitewide . "
$itemname$gradehtml ($item->avg)$item->count
- - 0
' . $avg_html . "
'; print_grade_page_head($courseid, 'report', 'outcomes'); echo $html; $event = \gradereport_outcomes\event\grade_report_viewed::create( array( 'context' => $context, 'courseid' => $courseid, ) ); $event->trigger(); echo $OUTPUT->footer();