]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10550 Finished first draft of the outcomes report.
authornicolasconnault <nicolasconnault>
Tue, 24 Jul 2007 10:08:46 +0000 (10:08 +0000)
committernicolasconnault <nicolasconnault>
Tue, 24 Jul 2007 10:08:46 +0000 (10:08 +0000)
grade/report/outcomes/index.php
lang/en_utf8/grades.php

index 4e51060db3683db3ea934baa72f7130a1fc2f37b..d662ecbbb5e19cf5381d8a94163f25724090f054 100644 (file)
@@ -29,16 +29,100 @@ print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, ''
 $currenttab = 'outcomereport';
 include('tabs.php');
 
-// Grab outcomes in use for this course
-$outcomes = grade_outcome::fetch_all(array('courseid' => $courseid));
-foreach ($outcomes as $outcome) {
-    print_object($outcome->get_grade_info($courseid, true, true));
+// Grab all outcomes, distinguishing between site-level and course-level outcomes
+$sql = "SELECT mdl_grade_outcomes.id,
+               mdl_grade_outcomes_courses.courseid,
+               mdl_grade_outcomes.shortname,
+               mdl_grade_outcomes.scaleid
+          FROM mdl_grade_outcomes
+     LEFT JOIN mdl_grade_outcomes_courses
+            ON (mdl_grade_outcomes.id = mdl_grade_outcomes_courses.outcomeid AND mdl_grade_outcomes_courses.courseid = $courseid)
+      ORDER BY mdl_grade_outcomes_courses.courseid DESC";
+
+$report_info = array();
+$outcomes = get_records_sql($sql);
+
+// Get grade_items that use each outcome
+foreach ($outcomes as $outcomeid => $outcome) {
+    $sql = "SELECT mdl_grade_items.id,
+                   mdl_grade_items.itemname,
+                   mdl_grade_items.itemmodule,
+                   mdl_grade_items.iteminstance,
+                   mdl_grade_items.itemtype,
+                   mdl_grade_items.itemnumber,
+                   mdl_grade_items.courseid,
+                   mdl_grade_items.idnumber
+              FROM mdl_grade_items
+             WHERE mdl_grade_items.outcomeid = $outcomeid";
+    $report_info[$outcomeid]['items'] = get_records_sql($sql);
+    $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) {
+            $sql = "SELECT id, AVG(finalgrade) AS `avg`, COUNT(finalgrade) AS `count`
+                      FROM mdl_grade_grades
+                     WHERE itemid = $itemid
+                  GROUP BY itemid";
+            $info = get_records_sql($sql);
+            $info = reset($info);
+            $report_info[$outcomeid]['items'][$itemid]->avg = round($info->avg, 2);
+            $report_info[$outcomeid]['items'][$itemid]->count = $info->count;
+        }
+    }
 }
-// Grab activities that are grading against each outcome (with links to activities)
 
-// Compute average grade across all activities and users for each outcome.
+$html = '<table border="1" summary="Outcomes Report">' . "\n";
+$html .= '<tr><th>' . get_string('outcomename', 'grades') . '</th>';
+$html .= '<th>' . get_string('sitewide', 'grades') . '</th>';
+$html .= '<th>' . get_string('activities', 'grades') . '</th>';
+$html .= '<th>' . get_string('average', 'grades') . '</th>';
+$html .= '<th>' . get_string('numberofgrades', 'grades') . '</th></tr>' . "\n";
+
+foreach ($report_info as $outcomeid => $outcomedata) {
+    $rowspan = count($outcomedata['items']);
+    $html .= '<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";
+
+    $print_tr = false;
+    if (is_array($outcomedata['items'])) {
+        foreach ($outcomedata['items'] as $itemid => $item) {
+            if ($print_tr) {
+                $html .= '<tr>';
+            }
+
+            $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];
+
+            $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>";
+    }
+}
 
 
+$html .= '</table>';
+echo $html;
 print_footer($course);
 
 ?>
index 3e4f5da22fb599f1d887fa3db7eb2d2860a6bdb9..c0afb32281568129ea14b404596f62142aa770fe 100644 (file)
@@ -2,6 +2,7 @@
       // grades.php - created with Moodle 1.7 beta + (2006101003)
 
 
+$string['activities'] = 'Activities';
 $string['addcategory'] = 'Add Category';
 $string['addcategoryerror'] = 'Could not add category.';
 $string['addexceptionerror'] = 'Error occurred while adding exception for userid:gradeitem';
@@ -212,9 +213,11 @@ $string['nonweightedpct'] = 'non-weighted %%';
 $string['noselectedcategories'] = 'no categories were selected.';
 $string['noselecteditems'] = 'no items were selected.';
 $string['notteachererror'] = 'You must be a teacher to use this feature.';
+$string['numberofgrades'] = 'Number of grades';
 $string['onascaleof'] = ' on a scale of $a->grademin to $a->grademax';
 $string['operations'] = 'Operations';
 $string['outcome'] = 'Outcome';
+$string['outcomename'] = 'Outcome name';
 $string['outcomereport'] = 'Outcome report';
 $string['outcomes'] = 'Outcomes';
 $string['overridden'] = 'Overridden';
@@ -265,6 +268,7 @@ $string['showhiddenitems'] = 'Show Hidden Items';
 $string['showlocks'] = 'Show locks';
 $string['showranges'] = 'Show ranges';
 $string['showuserimage'] = 'Show user profile images';
+$string['sitewide'] = 'Site-wide';
 $string['sort'] = 'sort';
 $string['sortasc'] = 'Sort in ascending order';
 $string['sortdesc'] = 'Sort in descending order';