]> git.mjollnir.org Git - moodle.git/commitdiff
New function make_grades_menu() for easily making an array of grades
authormoodler <moodler>
Mon, 18 Aug 2003 05:10:35 +0000 (05:10 +0000)
committermoodler <moodler>
Mon, 18 Aug 2003 05:10:35 +0000 (05:10 +0000)
lib/datalib.php
lib/moodlelib.php
lib/weblib.php
mod/assignment/submissions.php
mod/assignment/view.php

index b1acf849e37825142874606d54d25168068ebd33..324e775066f6dc7c5efd0265fd0e5b0f8b1ac94e 100644 (file)
@@ -108,7 +108,7 @@ function table_column($table, $oldfield, $field, $type="integer", $size="10",
                 $after = "AFTER `$after`";
             }
 
-            execute_sql("ALTER TABLE {$CFG->prefix}$table $operation $type $signed $default $null $after");
+            return execute_sql("ALTER TABLE {$CFG->prefix}$table $operation $type $signed $default $null $after");
             break;
 
         case "postgres7":        // From Petri Asikainen
@@ -161,7 +161,7 @@ function table_column($table, $oldfield, $field, $type="integer", $size="10",
                 }
             }
 
-            execute_sql("ALTER TABLE {$CFG->prefix}$table ALTER COLUMN $field SET DEFAULT $default");
+            return execute_sql("ALTER TABLE {$CFG->prefix}$table ALTER COLUMN $field SET DEFAULT $default");
 
             break;
 
@@ -188,7 +188,7 @@ function table_column($table, $oldfield, $field, $type="integer", $size="10",
             }
 
             execute_sql("ALTER TABLE {$CFG->prefix}$table ALTER COLUMN $field SET $null");
-            execute_sql("ALTER TABLE {$CFG->prefix}$table ALTER COLUMN $field SET $default");
+            return execute_sql("ALTER TABLE {$CFG->prefix}$table ALTER COLUMN $field SET $default");
             break;
 
     }
index 937556af4e454dcf88324ef6742460762b5cd265..8c57b8e54c5df928a5cce920fa016f212d909853 100644 (file)
@@ -1662,6 +1662,26 @@ function make_menu_from_list($list, $separator=",") {
     return $outarray;
 }
 
+function make_grades_menu($gradingtype) {
+/// Creates an array that represents all the current grades that
+/// can be chosen using the given grading type.  Negative numbers
+/// are scales, zero is no grade, and positive numbers are maximum
+/// grades.
+
+    $grades = array();
+    if ($gradingtype < 0) {
+        if ($scale = get_record("scale", "id", - $gradingtype)) {
+            return make_menu_from_list($scale->scale);
+        }
+    } else if ($gradingtype > 0) {
+        for ($i=$gradingtype; $i>=0; $i--) {
+            $grades[$i] = $i;
+        }
+        return $grades;
+    }
+    return $grades;
+}
+
 
 // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
 ?>
index 155ed61e03412585fe1a4436427662ad92264f25..7b70c1f3a17ecbe402c0aff98c194e72b721e6cd 100644 (file)
@@ -1292,6 +1292,7 @@ function print_scale_menu($courseid, $name, $current) {
                           $linkobject, 400, 500, $strscales);
 }
 
+
 function print_scale_menu_helpbutton($courseid, $scale) {
 /// Prints a help button about a scale
 /// scale is an object
index c370eb7bff30cfb65f281c8cb1b3913eb8b7e6d6..4e7208a4587cecc0306a4d6b5d9866489445d376 100644 (file)
         add_to_log($course->id, "assignment", "view submissions", "submissions.php?id=$assignment->id", "$assignment->id");
     }
 
-    $grades = array();
-
-    if ($assignment->grade < 0) {
-        $scaleid = - ($assignment->grade);
-        if ($scale = get_record("scale", "id", $scaleid)) {
-            $grades = make_menu_from_list($scale->scale);
-        }
-    } else if ($assignment->grade == 0) {
-        $grades = NULL;
-    } else {
-        for ($i=$assignment->grade; $i>=0; $i--) {
-            $grades[$i] = $i;
-        }
-    }
-
     // Submission sorting
     print_simple_box_start("CENTER", "50%");
     echo "<P align=\"CENTER\">";
 
     echo "<FORM ACTION=submissions.php METHOD=post>\n";
     
+    $grades = make_grades_menu($assignment->grade);
+
     foreach ($submissions as $submission) {
         $user = $users[$submission->userid];
         assignment_print_submission($assignment, $user, $submission, $teachers, $grades);
index 02d789e8391caa6c3be4aac38b1acfedbc17db7e..79fabdaa61e229fc241116efef7d742dc9e8ff1c 100644 (file)
@@ -81,7 +81,7 @@
             print_scale_menu_helpbutton($course->id, $scale);
             echo "<br />";
         }
-    } else if ($assignment->grade < 0) {
+    } else if ($assignment->grade > 0) {
         echo "<b>".get_string("maximumgrade")."</b>: $assignment->grade<br>";
     }