// allow setting of outcomes on module items too
$options = array(0=>get_string('usenooutcome', 'grades'));
- if ($outcomes = grade_outcome::fetch_all(array('courseid'=>$COURSE->id))) {
+
+ if ($outcomes = grade_outcome::fetch_all(array('courseid'=>$COURSE->id), true)) {
foreach ($outcomes as $outcome) {
- $options[$scale->id] = $outcome->get_name();
+ $options[$outcome->id] = $outcome->get_name();
}
}
+
$mform->addElement('select', 'outcomeid', get_string('outcome', 'grades'), $options);
$options = array(GRADE_TYPE_NONE=>get_string('typenone', 'grades'),
- GRADE_TYPE_VALUE=>get_string('typevalue', 'grades'),
- GRADE_TYPE_SCALE=>get_string('typescale', 'grades'),
- GRADE_TYPE_TEXT=>get_string('typetext', 'grades'));
+ GRADE_TYPE_VALUE=>get_string('typevalue', 'grades'),
+ GRADE_TYPE_SCALE=>get_string('typescale', 'grades'),
+ GRADE_TYPE_TEXT=>get_string('typetext', 'grades'));
+
$mform->addElement('select', 'gradetype', get_string('gradetype', 'grades'), $options);
$mform->setDefault('gradetype', GRADE_TYPE_VALUE);
}
$scaleval = round($this->get_grade_clean($finalavg, $decimalpoints));
- $scales_array = get_records_list('scale', 'id', $item->scaleid);
- $scale = $scales_array[$item->scaleid];
- $scales = explode(",", $scale->scale);
-
- // this could be a 0 when summed and rounded, e.g, 1, no grade, no grade, no grade
- if ($scaleval < 1) {
- $scaleval = 1;
- }
-
- $gradehtml = $scales[$scaleval-1];
+ $scale_object = new grade_scale(array('id' => $item->scaleid), false);
+ $gradehtml = $scale_object->get_nearest_item($scaleval);
$rawvalue = $scaleval;
} else {
$gradeval = $this->get_grade_clean($sum/$count_array[$item->id], $decimalpoints);
$html = '<table border="1" summary="Outcomes Report">' . "\n";
$html .= '<tr><th>' . get_string('outcomename', 'grades') . '</th>';
+$html .= '<th>' . get_string('overallavg', 'grades') . '</th>';
$html .= '<th>' . get_string('sitewide', 'grades') . '</th>';
$html .= '<th>' . get_string('activities', 'grades') . '</th>';
$html .= '<th>' . get_string('average', 'grades') . '</th>';
foreach ($report_info as $outcomeid => $outcomedata) {
$rowspan = count($outcomedata['items']);
- $html .= '<td rowspan="' . $rowspan . '">' . $outcomedata['outcome']->shortname . "</td>\n";
+ $shortname_html = '<tr><td rowspan="' . $rowspan . '">' . $outcomedata['outcome']->shortname . "</td>\n";
$sitewide = get_string('no');
if (empty($outcomedata['outcome']->courseid)) {
$sitewide = get_string('yes');
}
- $html .= '<td rowspan="' . $rowspan . '">' . $sitewide . "</td>\n";
+ $sitewide_html = '<td rowspan="' . $rowspan . '">' . $sitewide . "</td>\n";
+
+ $outcomedata['outcome']->sum = 0;
+ $scale = new grade_scale(array('id' => $outcomedata['outcome']->scaleid), false);
$print_tr = false;
+ $items_html = '';
+
if (is_array($outcomedata['items'])) {
foreach ($outcomedata['items'] as $itemid => $item) {
if ($print_tr) {
- $html .= '<tr>';
+ $items_html .= "<tr>\n";
}
$cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid);
$itemname = '<a href="'.$CFG->wwwroot.'/mod/'.$item->itemmodule.'/view.php?id='.$cm->id.'">'.$item->itemname.'</a>';
- // Obtain nearest scale item from average
- $scales_array = get_records_list('scale', 'id', $outcomedata['outcome']->scaleid);
- $scale = $scales_array[$outcomedata['outcome']->scaleid];
- $scales = explode(",", $scale->scale);
-
- // this could be a 0 when summed and rounded, e.g, 1, no grade, no grade, no grade
- if ($item->avg < 1) {
- $item->avg = 1;
- }
-
- $gradehtml = $scales[$item->avg-1];
+ $outcomedata['outcome']->sum += $item->avg;
+ $gradehtml = $scale->get_nearest_item($item->avg);
- $html .= "<td>$itemname</td><td>$gradehtml ($item->avg)</td><td>$item->count</td></tr>\n";
+ $items_html .= "<td>$itemname</td><td>$gradehtml ($item->avg)</td><td>$item->count</td></tr>\n";
$print_tr = true;
}
} else {
- $html .= "<td> - </td><td> - </td><td> 0 </td>";
+ $items_html .= "<td> - </td><td> - </td><td> 0 </td></tr>\n";
+ }
+
+ // Calculate outcome average
+ if (is_array($outcomedata['items'])) {
+ $avg = $outcomedata['outcome']->sum / count($outcomedata['items']);
+ $avg_html = $scale->get_nearest_item($avg) . " (" . round($avg, 2) . ")\n";
+ } else {
+ $avg_html = ' - ';
}
+
+ $outcomeavg_html = '<td rowspan="' . $rowspan . '">' . $avg_html . "</td>\n";
+
+ $html .= $shortname_html . $outcomeavg_html . $sitewide_html . $items_html;
}
+
$html .= '</table>';
echo $html;
print_footer($course);
$string['onascaleof'] = ' on a scale of $a->grademin to $a->grademax';
$string['operations'] = 'Operations';
$string['outcome'] = 'Outcome';
+$string['outcomes'] = 'Outcomes';
$string['outcomename'] = 'Outcome name';
$string['outcomereport'] = 'Outcome report';
$string['outcomes'] = 'Outcomes';
$string['overridden'] = 'Overridden';
+$string['overallavg'] = 'Overall average';
$string['pctoftotalgrade'] = '%% of total grade';
$string['percent'] = 'Percent';
$string['percentage'] = 'Percentage';
* @static
*
* @param array $params associative arrays varname=>value
+ * @param bool $fetch_sitewide_outcomes Whether or not to also fetch all sitewide outcomes (with no courseid)
* @return array array of grade_outcome insatnces or false if none found.
*/
- function fetch_all($params) {
+ function fetch_all($params, $fetch_sitewide_outcomes=false) {
+ global $CFG;
+
if ($outcomes = grade_object::fetch_all_helper('grade_outcomes', 'grade_outcome', $params)) {
+ // Fetch sitewide outcomes if requested
+ if ($fetch_sitewide_outcomes) {
+ $sitewide_outcomes = array();
+ $records = get_records_sql("SELECT * FROM {$CFG->prefix}grade_outcomes WHERE courseid IS NULL");
+ foreach ($records as $outcomeid => $outcome) {
+ $sitewide_outcomes[$outcomeid] = new grade_outcome($outcome, false);
+ }
+ $outcomes = array_merge($sitewide_outcomes, $outcomes);
+ }
+
foreach ($outcomes as $key=>$value) {
if (!empty($outcomes[$key]->scaleid)) {
$outcomes[$key]->scale = new grade_scale(array('id'=>$outcomes[$key]->scaleid));
return $this->scale;
}
+
+ /**
+ * When called on a loaded scale object (with a valid id) and given a float grade between
+ * the grademin and grademax, this method returns the scale item that falls closest to the
+ * float given (which is usually an average of several grades on a scale). If the float falls
+ * below 1 but above 0, it will be rounded up to 1.
+ * @param float $grade
+ * @return string
+ */
+ function get_nearest_item($grade) {
+ // Obtain nearest scale item from average
+ $scales_array = get_records_list('scale', 'id', $this->id);
+ $scale = $scales_array[$this->id];
+ $scales = explode(",", $scale->scale);
+
+ // this could be a 0 when summed and rounded, e.g, 1, no grade, no grade, no grade
+ if ($grade < 1) {
+ $grade = 1;
+ }
+
+ return $scales[$grade-1];
+ }
}
?>