2009-07-07 02:26:36 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-10 06:34:20 +00:00
|
|
|
|
2012-01-06 11:52:46 +07:00
|
|
|
/**
|
|
|
|
* The gradebook outcomes report
|
|
|
|
*
|
|
|
|
* @package gradereport_outcomes
|
|
|
|
* @copyright 2007 Nicolas Connault
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2007-07-23 14:33:02 +00:00
|
|
|
include_once('../../../config.php');
|
|
|
|
require_once($CFG->libdir . '/gradelib.php');
|
2007-07-30 06:23:24 +00:00
|
|
|
require_once $CFG->dirroot.'/grade/lib.php';
|
2007-07-23 14:33:02 +00:00
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
$courseid = required_param('id', PARAM_INT); // course id
|
2007-07-23 14:33:02 +00:00
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->set_url('/grade/report/outcomes/index.php', array('id'=>$courseid));
|
2009-10-15 06:58:21 +00:00
|
|
|
|
2008-06-03 16:10:57 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invalidcourseid');
|
2007-07-23 14:33:02 +00:00
|
|
|
}
|
|
|
|
|
2012-04-22 17:41:47 +02:00
|
|
|
require_login($course);
|
2012-07-24 14:04:40 +08:00
|
|
|
$context = context_course::instance($course->id);
|
2007-07-23 14:33:02 +00:00
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
require_capability('gradereport/outcomes:view', $context);
|
|
|
|
|
2022-03-21 17:43:20 +00:00
|
|
|
if (empty($CFG->enableoutcomes)) {
|
|
|
|
redirect(course_get_url($course), get_string('outcomesdisabled', 'core_grades'));
|
|
|
|
}
|
|
|
|
|
2013-03-27 10:14:10 +08:00
|
|
|
// First make sure we have proper final grades.
|
2016-01-29 14:02:03 +08:00
|
|
|
grade_regrade_final_grades_if_required($course);
|
2007-07-30 22:56:45 +00:00
|
|
|
|
2013-03-27 10:14:10 +08:00
|
|
|
// Grab all outcomes used in course.
|
2007-07-24 10:08:46 +00:00
|
|
|
$report_info = array();
|
2007-07-31 13:34:36 +00:00
|
|
|
$outcomes = grade_outcome::fetch_all_available($courseid);
|
2007-07-24 10:08:46 +00:00
|
|
|
|
2013-03-27 10:14:10 +08:00
|
|
|
// 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.
|
2007-07-24 10:08:46 +00:00
|
|
|
foreach ($outcomes as $outcomeid => $outcome) {
|
2008-06-03 16:10:57 +00:00
|
|
|
$report_info[$outcomeid]['items'] = $DB->get_records_select('grade_items', "outcomeid = ? AND courseid = ?", array($outcomeid, $courseid));
|
2007-07-24 10:08:46 +00:00
|
|
|
$report_info[$outcomeid]['outcome'] = $outcome;
|
|
|
|
|
2013-03-27 10:14:10 +08:00
|
|
|
// Get average grades for each item.
|
2007-07-24 10:08:46 +00:00
|
|
|
if (is_array($report_info[$outcomeid]['items'])) {
|
|
|
|
foreach ($report_info[$outcomeid]['items'] as $itemid => $item) {
|
2013-03-27 10:14:10 +08:00
|
|
|
$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);
|
|
|
|
|
2008-05-29 17:27:36 +00:00
|
|
|
$sql = "SELECT itemid, AVG(finalgrade) AS avg, COUNT(finalgrade) AS count
|
2008-06-02 16:06:33 +00:00
|
|
|
FROM {grade_grades}
|
2013-03-27 10:14:10 +08:00
|
|
|
WHERE itemid = ?".
|
|
|
|
$hidesuspendedsql.
|
2015-02-11 14:14:02 +01:00
|
|
|
" GROUP BY itemid";
|
2013-03-27 10:14:10 +08:00
|
|
|
$info = $DB->get_records_sql($sql, $params);
|
2007-07-26 08:49:53 +00:00
|
|
|
|
|
|
|
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;
|
2007-07-24 10:08:46 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-23 14:33:02 +00:00
|
|
|
}
|
|
|
|
|
2007-07-31 07:26:13 +00:00
|
|
|
$html = '<table class="generaltable boxaligncenter" width="90%" cellspacing="1" cellpadding="5" summary="Outcomes Report">' . "\n";
|
MDL-13481 Strings fullname and shortname are now deprecated
This is a final cleanup commit of fullname and shortname issue. All
places where these strings were detected yet have been replaced with
proper fullnamecourse or fullnameuser or some other context specific
string.
AMOS BEGIN
CPY [fullname,core],[outcomefullname,core_grades]
CPY [shortname,core],[outcomeshortname,core_grades]
CPY [name,core],[rolefullname,core_role]
CPY [shortname,core],[roleshortname,core_role]
AMOS END
2011-02-22 10:12:10 +01:00
|
|
|
$html .= '<tr><th class="header c0" scope="col">' . get_string('outcomeshortname', 'grades') . '</th>';
|
2008-02-28 15:52:23 +00:00
|
|
|
$html .= '<th class="header c1" scope="col">' . get_string('courseavg', 'grades') . '</th>';
|
2007-07-31 07:26:13 +00:00
|
|
|
$html .= '<th class="header c2" scope="col">' . get_string('sitewide', 'grades') . '</th>';
|
|
|
|
$html .= '<th class="header c3" scope="col">' . get_string('activities', 'grades') . '</th>';
|
|
|
|
$html .= '<th class="header c4" scope="col">' . get_string('average', 'grades') . '</th>';
|
|
|
|
$html .= '<th class="header c5" scope="col">' . get_string('numberofgrades', 'grades') . '</th></tr>' . "\n";
|
2007-07-24 10:08:46 +00:00
|
|
|
|
2007-07-31 07:26:13 +00:00
|
|
|
$row = 0;
|
2007-07-24 10:08:46 +00:00
|
|
|
foreach ($report_info as $outcomeid => $outcomedata) {
|
|
|
|
$rowspan = count($outcomedata['items']);
|
2013-03-27 10:14:10 +08:00
|
|
|
// If there are no items for this outcome, rowspan will equal 0, which is not good.
|
2008-02-28 12:41:26 +00:00
|
|
|
if ($rowspan == 0) {
|
|
|
|
$rowspan = 1;
|
|
|
|
}
|
|
|
|
|
2007-07-31 07:26:13 +00:00
|
|
|
$shortname_html = '<tr class="r' . $row . '"><td class="cell c0" rowspan="' . $rowspan . '">' . $outcomedata['outcome']->shortname . "</td>\n";
|
2007-07-24 10:08:46 +00:00
|
|
|
|
|
|
|
$sitewide = get_string('no');
|
|
|
|
if (empty($outcomedata['outcome']->courseid)) {
|
|
|
|
$sitewide = get_string('yes');
|
|
|
|
}
|
|
|
|
|
2007-07-31 07:26:13 +00:00
|
|
|
$sitewide_html = '<td class="cell c2" rowspan="' . $rowspan . '">' . $sitewide . "</td>\n";
|
2007-07-24 14:26:05 +00:00
|
|
|
|
|
|
|
$outcomedata['outcome']->sum = 0;
|
|
|
|
$scale = new grade_scale(array('id' => $outcomedata['outcome']->scaleid), false);
|
2007-07-24 10:08:46 +00:00
|
|
|
|
|
|
|
$print_tr = false;
|
2007-07-24 14:26:05 +00:00
|
|
|
$items_html = '';
|
|
|
|
|
2008-02-28 12:41:26 +00:00
|
|
|
if (!empty($outcomedata['items'])) {
|
2007-07-24 10:08:46 +00:00
|
|
|
foreach ($outcomedata['items'] as $itemid => $item) {
|
|
|
|
if ($print_tr) {
|
2007-07-31 07:26:13 +00:00
|
|
|
$row++;
|
|
|
|
$items_html .= "<tr class=\"r$row\">\n";
|
2007-07-24 10:08:46 +00:00
|
|
|
}
|
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
$grade_item = new grade_item($item, false);
|
|
|
|
|
|
|
|
if ($item->itemtype == 'mod') {
|
|
|
|
$cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid);
|
2009-09-28 07:51:18 +00:00
|
|
|
$itemname = '<a href="'.$CFG->wwwroot.'/mod/'.$item->itemmodule.'/view.php?id='.$cm->id.'">'.format_string($cm->name, true, $cm->course).'</a>';
|
2007-07-30 22:56:45 +00:00
|
|
|
} else {
|
|
|
|
$itemname = $grade_item->get_name();
|
|
|
|
}
|
2007-07-24 10:08:46 +00:00
|
|
|
|
2007-07-24 14:26:05 +00:00
|
|
|
$outcomedata['outcome']->sum += $item->avg;
|
|
|
|
$gradehtml = $scale->get_nearest_item($item->avg);
|
2007-07-24 10:08:46 +00:00
|
|
|
|
2007-07-31 07:26:13 +00:00
|
|
|
$items_html .= "<td class=\"cell c3\">$itemname</td>"
|
|
|
|
. "<td class=\"cell c4\">$gradehtml ($item->avg)</td>"
|
|
|
|
. "<td class=\"cell c5\">$item->count</td></tr>\n";
|
2007-07-24 10:08:46 +00:00
|
|
|
$print_tr = true;
|
|
|
|
}
|
|
|
|
} else {
|
2007-07-31 07:26:13 +00:00
|
|
|
$items_html .= "<td class=\"cell c3\"> - </td><td class=\"cell c4\"> - </td><td class=\"cell c5\"> 0 </td></tr>\n";
|
2007-07-24 14:26:05 +00:00
|
|
|
}
|
|
|
|
|
2013-03-27 10:14:10 +08:00
|
|
|
// Calculate outcome average.
|
2007-07-24 14:26:05 +00:00
|
|
|
if (is_array($outcomedata['items'])) {
|
2007-08-10 14:58:21 +00:00
|
|
|
$count = count($outcomedata['items']);
|
|
|
|
if ($count > 0) {
|
|
|
|
$avg = $outcomedata['outcome']->sum / $count;
|
|
|
|
} else {
|
|
|
|
$avg = $outcomedata['outcome']->sum;
|
|
|
|
}
|
2007-07-24 14:26:05 +00:00
|
|
|
$avg_html = $scale->get_nearest_item($avg) . " (" . round($avg, 2) . ")\n";
|
|
|
|
} else {
|
|
|
|
$avg_html = ' - ';
|
2007-07-24 10:08:46 +00:00
|
|
|
}
|
2007-07-24 14:26:05 +00:00
|
|
|
|
2007-07-31 07:26:13 +00:00
|
|
|
$outcomeavg_html = '<td class="cell c1" rowspan="' . $rowspan . '">' . $avg_html . "</td>\n";
|
2007-07-24 14:26:05 +00:00
|
|
|
|
|
|
|
$html .= $shortname_html . $outcomeavg_html . $sitewide_html . $items_html;
|
2007-07-31 07:26:13 +00:00
|
|
|
$row++;
|
2007-07-24 10:08:46 +00:00
|
|
|
}
|
2007-07-23 14:33:02 +00:00
|
|
|
|
2014-08-05 19:41:33 -07:00
|
|
|
$html .= '</table>';
|
|
|
|
|
|
|
|
print_grade_page_head($courseid, 'report', 'outcomes');
|
|
|
|
|
|
|
|
echo $html;
|
|
|
|
|
2014-08-05 19:40:03 -07:00
|
|
|
$event = \gradereport_outcomes\event\grade_report_viewed::create(
|
2014-06-13 16:03:54 +08:00
|
|
|
array(
|
|
|
|
'context' => $context,
|
|
|
|
'courseid' => $courseid,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$event->trigger();
|
2007-07-24 14:26:05 +00:00
|
|
|
|
2009-08-06 14:12:17 +00:00
|
|
|
echo $OUTPUT->footer();
|