]> git.mjollnir.org Git - moodle.git/commitdiff
moving some functions out to lib so they can be used in other reports
authortoyomoyo <toyomoyo>
Wed, 11 Jul 2007 05:07:39 +0000 (05:07 +0000)
committertoyomoyo <toyomoyo>
Wed, 11 Jul 2007 05:07:39 +0000 (05:07 +0000)
grade/report/grader/index.php
grade/report/lib.php [new file with mode: 0755]
grade/report/user/index.php

index 16e6b0aa24e0e6541d1b4ed6f4b67344318b7243..7ce5fc91c7fc40364d1a6a30b65f5e545c233e0c 100644 (file)
@@ -4,57 +4,9 @@
 
 require_once($CFG->libdir.'/tablelib.php');
 require_once($CFG->libdir.'/gradelib.php');
-
+require_once($CFG->dirroot.'/grade/report/lib.php');
 $gradeserror = array();
 
-/**
- * format grade using lang specific decimal point and thousand separator
- * the result is suitable for printing on html page
- * @param float $gradeval raw grade value pulled from db
- * @return string $gradeval formatted grade value
- */
-function get_grade_clean($gradeval) {
-    global $CFG;
-
-    if (is_null($gradeval)) {
-        $gradeval = '';
-       } else {
-        // decimal points as specified by user
-        $decimals = get_user_preferences('grade_report_decimalpoints', $CFG->grade_report_decimalpoints);
-        $gradeval = number_format($gradeval, $decimals, get_string('decpoint', 'langconfig'), get_string('thousandsep', 'langconfig'));
-    }
-
-    return $gradeval;
-
-    /*
-    // commenting this out, if this is added, we also need to find the number of decimal place preserved
-    // so it can go into number_format
-    if ($gradeval != 0) {
-        $gradeval = rtrim(trim($gradeval, "0"), ".");
-    } else {
-        $gradeval = 0;
-    }
-    */
-
-}
-
-/**
- * Given a user input grade, format it to standard format i.e. no thousand separator, and . as decimal point
- * @param string $gradeval grade value from user input, language specific format
- * @return string - grade value for storage, en format
- */
-function format_grade($gradeval) {
-
-    $decimalpt = get_string('decpoint', 'langconfig');
-    $thousandsep = get_string('thousandsep', 'langconfig');
-    // replace decimal point with '.';
-    $gradeval = str_replace($decimalpt, '.', $gradeval);
-    // thousand separator is not useful
-    $gradeval = str_replace($thousandsep, '', $gradeval);
-
-    return clean_param($gradeval, PARAM_NUMBER);
-}
-
 /**
 * Shortcut function for printing the grader report toggles.
 * @param string $type The type of toggle
diff --git a/grade/report/lib.php b/grade/report/lib.php
new file mode 100755 (executable)
index 0000000..95cea8e
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+/**
+ * format grade using lang specific decimal point and thousand separator
+ * the result is suitable for printing on html page
+ * @param float $gradeval raw grade value pulled from db
+ * @return string $gradeval formatted grade value
+ */
+function get_grade_clean($gradeval) {
+    global $CFG;
+
+    if (is_null($gradeval)) {
+        $gradeval = '';
+       } else {
+        // decimal points as specified by user
+        $decimals = get_user_preferences('grade_report_decimalpoints', $CFG->grade_report_decimalpoints);
+        $gradeval = number_format($gradeval, $decimals, get_string('decpoint', 'langconfig'), get_string('thousandsep', 'langconfig'));
+    }
+
+    return $gradeval;
+
+    /*
+    // commenting this out, if this is added, we also need to find the number of decimal place preserved
+    // so it can go into number_format
+    if ($gradeval != 0) {
+        $gradeval = rtrim(trim($gradeval, "0"), ".");
+    } else {
+        $gradeval = 0;
+    }
+    */
+
+}
+
+/**
+ * Given a user input grade, format it to standard format i.e. no thousand separator, and . as decimal point
+ * @param string $gradeval grade value from user input, language specific format
+ * @return string - grade value for storage, en format
+ */
+function format_grade($gradeval) {
+
+    $decimalpt = get_string('decpoint', 'langconfig');
+    $thousandsep = get_string('thousandsep', 'langconfig');
+    // replace decimal point with '.';
+    $gradeval = str_replace($decimalpt, '.', $gradeval);
+    // thousand separator is not useful
+    $gradeval = str_replace($thousandsep, '', $gradeval);
+
+    return clean_param($gradeval, PARAM_NUMBER);
+}
+?>
\ No newline at end of file
index fef2ecd753920eecd7abeef1d2074efc520c4ec2..6920fb8d9ab0281e4b2cb9a18fd050630dd95024 100644 (file)
@@ -4,7 +4,7 @@
 
 require_once($CFG->libdir.'/tablelib.php');
 include_once($CFG->libdir.'/gradelib.php');
-
+require_once($CFG->dirroot.'/grade/report/lib.php');
 // get the params
 $courseid = required_param('id', PARAM_INT);
 if (!$userid = optional_param('user', 0, PARAM_INT)) {
@@ -40,7 +40,7 @@ $numusers = count(get_role_users(@implode(',', $CFG->gradebookroles), $context))
 
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'user-grade');
-    $table->set_attribute('class', 'generaltable generalbox');
+    $table->set_attribute('class', 'boxaligncenter generaltable');
 
     // not sure tables should be sortable or not, because if we allow it then sorted resutls distort grade category structure and sortorder
     $table->set_control_variables(array(
@@ -114,7 +114,7 @@ $numusers = count(get_role_users(@implode(',', $CFG->gradebookroles), $context))
                 }
             } else {
                 // normal grade, or text, just display
-                $data[] = $grade_grades->finalgrade;
+                $data[] = get_grade_clean($grade_grades->finalgrade);
             }
 
             /// prints percentage
@@ -122,7 +122,7 @@ $numusers = count(get_role_users(@implode(',', $CFG->gradebookroles), $context))
             if ($grade_item->gradetype == GRADE_TYPE_VALUE) {
                 // processing numeric grade
                 if ($grade_grades->finalgrade) {
-                    $percentage = (($grade_grades->finalgrade / $grade_item->grademax) * 100).'%';
+                    $percentage = get_grade_clean(($grade_grades->finalgrade / $grade_item->grademax) * 100).'%';
                 } else {
                     $percentage = '-';
                 }
@@ -131,7 +131,7 @@ $numusers = count(get_role_users(@implode(',', $CFG->gradebookroles), $context))
                 // processing scale grade
                 $scale = get_record('scale', 'id', $grade_item->scaleid);
                 $scalevals = explode(",", $scale->scale);
-                $percentage = (($grade_grades->finalgrade) / count($scalevals) * 100).'%';
+                $percentage = get_grade_clean(($grade_grades->finalgrade) / count($scalevals) * 100).'%';
 
             } else {
                 // text grade
@@ -161,11 +161,13 @@ $numusers = count(get_role_users(@implode(',', $CFG->gradebookroles), $context))
             } else {
                 $data[] = '&nbsp;';
             }
-
             $table->add_data($data);
         }
+        
+        //echo "<div><table class='boxaligncenter'><tr><td>asdfas</td></tr></table></div>";
         $table->print_html();
     } else {
         notify(get_string('nogradeitem', 'grades'));
     }
+    
 ?>