From fdc47ee6c9b71c2f366d492d768339bf974cfb9c Mon Sep 17 00:00:00 2001 From: moodler Date: Mon, 18 Aug 2003 05:10:35 +0000 Subject: [PATCH] New function make_grades_menu() for easily making an array of grades --- lib/datalib.php | 6 +++--- lib/moodlelib.php | 20 ++++++++++++++++++++ lib/weblib.php | 1 + mod/assignment/submissions.php | 17 ++--------------- mod/assignment/view.php | 2 +- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/lib/datalib.php b/lib/datalib.php index b1acf849e3..324e775066 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -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; } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 937556af4e..8c57b8e54c 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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: ?> diff --git a/lib/weblib.php b/lib/weblib.php index 155ed61e03..7b70c1f3a1 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -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 diff --git a/mod/assignment/submissions.php b/mod/assignment/submissions.php index c370eb7bff..4e7208a458 100644 --- a/mod/assignment/submissions.php +++ b/mod/assignment/submissions.php @@ -126,21 +126,6 @@ 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 "

"; @@ -154,6 +139,8 @@ echo "

\n"; + $grades = make_grades_menu($assignment->grade); + foreach ($submissions as $submission) { $user = $users[$submission->userid]; assignment_print_submission($assignment, $user, $submission, $teachers, $grades); diff --git a/mod/assignment/view.php b/mod/assignment/view.php index 02d789e839..79fabdaa61 100644 --- a/mod/assignment/view.php +++ b/mod/assignment/view.php @@ -81,7 +81,7 @@ print_scale_menu_helpbutton($course->id, $scale); echo "
"; } - } else if ($assignment->grade < 0) { + } else if ($assignment->grade > 0) { echo "".get_string("maximumgrade").": $assignment->grade
"; } -- 2.39.5