]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10550 Refactoring, fixing a few bugs in edit/item_form.php and more work into...
authornicolasconnault <nicolasconnault>
Tue, 24 Jul 2007 14:26:05 +0000 (14:26 +0000)
committernicolasconnault <nicolasconnault>
Tue, 24 Jul 2007 14:26:05 +0000 (14:26 +0000)
grade/edit/item_form.php
grade/report/grader/lib.php
grade/report/outcomes/index.php
lang/en_utf8/grades.php
lib/grade/grade_outcome.php
lib/grade/grade_scale.php

index 9a588353d984b7402d28ff25c3da0ef4dfbc6aa4..057b14f33135e75bca8d6d4508407faefdb7e865 100644 (file)
@@ -17,17 +17,20 @@ class edit_item_form extends moodleform {
 
         // 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);
 
index 64f58b05d94c26853f561ef4bb81dafdb98bcf86..b3d6cfb93c1e558f8e0f569afc406b60a91c525f 100644 (file)
@@ -783,16 +783,8 @@ class grade_report_grader extends grade_report {
                         }
 
                         $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);
index d662ecbbb5e19cf5381d8a94163f25724090f054..17c0d86ef3bb6c99bb33668f01827a1af7ed71b6 100644 (file)
@@ -74,6 +74,7 @@ foreach ($outcomes as $outcomeid => $outcome) {
 
 $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>';
@@ -81,46 +82,55 @@ $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";
+    $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);
index c0afb32281568129ea14b404596f62142aa770fe..5d20f62fbdb2119b405e24d1d280fe73335bdb38 100644 (file)
@@ -217,10 +217,12 @@ $string['numberofgrades'] = 'Number of grades';
 $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';
index b49cea09fa58a7e686f436e3e1a894f44b6eebda..b18b24e9961fe8322b0a1a3cee55e5c189d48d83 100644 (file)
@@ -103,10 +103,23 @@ class grade_outcome extends grade_object {
      * @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));
index e21a4f0fed69ed564f31c8be2bc566fc05cba284..51ee8ca760ad71b7b1c43d2ea01ad4667f193189 100644 (file)
@@ -147,5 +147,27 @@ class grade_scale extends grade_object {
 
         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];
+    }
 }
 ?>