Permalink
Browse files

Additional information exercises page (index.php).

  • Loading branch information...
rkingdon
rkingdon committed Oct 12, 2003
1 parent 3ca5e8b commit b8968752933a201864edd1d5b04ae02bf0eda0cd
Showing with 162 additions and 89 deletions.
  1. +57 −10 mod/exercise/index.php
  2. +61 −38 mod/exercise/lib.php
  3. +44 −41 mod/exercise/view.php
View
@@ -22,6 +22,8 @@
$strtopic = get_string("topic");
$strname = get_string("name");
$strtitle = get_string("title", "exercise");
+ $strphase = get_string("phase", "exercise");
+ $strgrade = get_string("grade");
$strdeadline = get_string("deadline", "exercise");
$strsubmitted = get_string("submitted", "assignment");
@@ -35,19 +37,27 @@
$timenow = time();
if ($course->format == "weeks") {
- $table->head = array ($strweek, $strname, $strtitle, $strsubmitted, $strdeadline);
- $table->align = array ("CENTER", "LEFT", "LEFT","LEFT", "LEFT");
+ if (isteacher($course->id)) {
+ $table->head = array ($strweek, $strname, $strtitle, $strphase, $strsubmitted, $strdeadline);
+ } else {
+ $table->head = array ($strweek, $strname, $strtitle, $strgrade, $strsubmitted, $strdeadline);
+ }
+ $table->align = array ("CENTER", "LEFT", "LEFT","center","LEFT", "LEFT");
} else if ($course->format == "topics") {
- $table->head = array ($strtopic, $strname, $strtitle, $strsubmitted, $strdeadline);
- $table->align = array ("CENTER", "LEFT", "LEFT", "LEFT", "LEFT");
+ if (isteacher($course->id)) {
+ $table->head = array ($strtopic, $strname, $strtitle, $strphase, $strsubmitted, $strdeadline);
+ } else {
+ $table->head = array ($strtopic, $strname, $strtitle, $strgrade, $strsubmitted, $strdeadline);
+ }
+ $table->align = array ("CENTER", "LEFT", "LEFT", "center", "LEFT", "LEFT");
} else {
$table->head = array ($strname, $strsubmitted, $strdeadline);
$table->align = array ("LEFT", "LEFT", "LEFT");
}
foreach ($exercises as $exercise) {
if ($submissions = exercise_get_user_submissions($exercise, $USER)) {
- foreach ($submissions as $submission) {
+ foreach ($submissions as $submission) {
if ($submission->timecreated <= $exercise->deadline) {
$submitted = userdate($submission->timecreated);
}
@@ -58,26 +68,63 @@
$link = "<A HREF=\"view.php?id=$exercise->coursemodule\">$exercise->name</A>";
$title = $submission->title;
if ($course->format == "weeks" or $course->format == "topics") {
- $table->data[] = array ($exercise->section, $link, $title, $submitted, $due);
+ if (isteacher($course->id)) {
+ switch ($exercise->phase) {
+ case 1: $phase = get_string("phase1short", "exercise");
+ break;
+ case 2: $phase = get_string("phase2short", "exercise");
+ break;
+ case 3: $phase = get_string("phase3short", "exercise");
+ break;
+ case 4: $phase = get_string("phase4short", "exercise");
+ break;
+ }
+ $table->data[] = array ($exercise->section, $link, $title, $phase,
+ $submitted, $due);
+ } else {
+ if ($exercise->usemaximum) {
+ $maximum = exercise_get_best_grade($submission);
+ $grade = $maximum->grade;
+ }else { // use mean value
+ $mean = exercise_get_mean_grade($submission);
+ $grade = $mean->grade;
+ }
+ // now get the user's grading grade
+ if (!$assessments = exercise_get_user_assessments($exercise, $USER)) {
+ error("Index: assessment record not found");
+ }
+ foreach ($assessments as $assessment) {
+ // just use the first one (should only be one)
+ $gradinggrade = $assessment->gradinggrade;
+ break;
+ }
+ $overallgrade = (($gradinggrade * $EXERCISE_FWEIGHTS[$exercise->gradingweight] * $exercise->grade / COMMENTSCALE ) + ($grade * $EXERCISE_FWEIGHTS[$exercise->teacherweight] * $exercise->grade / 100.0)) / ($EXERCISE_FWEIGHTS[$exercise->gradingweight] + $EXERCISE_FWEIGHTS[$exercise->teacherweight]);
+ $table->data[] = array ($exercise->section, $link, $title,
+ number_format($overallgrade, 1), $submitted, $due);
}
+ }
else {
$table->data[] = array ($link, $submitted, $due);
- }
}
}
+ }
else {
$submitted = get_string("no");
$title = '';
$due = userdate($exercise->deadline);
$link = "<A HREF=\"view.php?id=$exercise->coursemodule\">$exercise->name</A>";
if ($course->format == "weeks" or $course->format == "topics") {
- $table->data[] = array ($exercise->section, $link, $title, $submitted, $due);
+ if (isteacher($course->id)) {
+ $table->data[] = array ($exercise->section, $link, $title, $exercise->phase,
+ $submitted, $due);
+ } else {
+ $table->data[] = array ($exercise->section, $link, $title, "0", $submitted, $due);
}
- else {
+ } else {
$table->data[] = array ($link, $submitted, $due);
- }
}
}
+ }
echo "<BR>";
print_table($table);
View
@@ -130,6 +130,18 @@ function exercise_cron () {
echo "Could not find submission $assessment->submissionid\n";
continue;
}
+ if (! $exercise = get_record("exercise", "id", $submission->exerciseid)) {
+ echo "Could not find exercise record for id $submission->exerciseid\n";
+ continue;
+ }
+ if (! $course = get_record("course", "id", "$exercise->course")) {
+ echo "Could not find course $exercise->course\n";
+ continue;
+ }
+ if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) {
+ error("Course Module ID was incorrect");
+ continue;
+ }
if (! $submissionowner = get_record("user", "id", "$submission->userid")) {
echo "Could not find user $submission->userid\n";
continue;
@@ -138,20 +150,12 @@ function exercise_cron () {
echo "Could not find user $assessment->userid\n";
continue;
}
- if (! $course = get_record("course", "id", "$assessment->course")) {
- echo "Could not find course $assessment->course\n";
- continue;
- }
if (! isstudent($course->id, $submissionowner->id) and !isteacher($course->id, $submissionowner->id)) {
continue; // Not an active participant
}
if (! isstudent($course->id, $assessmentowner->id) and !isteacher($course->id, $assessmentowner->id)) {
continue; // Not an active participant
}
- if (! $exercise = get_coursemodule_from_instance("exercise", $assessment->exerciseid, $course->id)) {
- echo "Could not find course module for exercise id $submission->exercise\n";
- continue;
- }
$strexercises = get_string("modulenameplural", "exercise");
$strexercise = get_string("modulename", "exercise");
@@ -170,17 +174,17 @@ function exercise_cron () {
$posttext .= $msg;
// "You can see it in your exercise assignment"
$posttext .= get_string("mail3", "exercise").":\n";
- $posttext .= " $CFG->wwwroot/mod/exercise/view.php?a=$exercise->id\n";
+ $posttext .= " $CFG->wwwroot/mod/exercise/view.php?id=$cm->id\n";
$posttext .= "---------------------------------------------------------------------\n";
if ($sendto->mailformat == 1) { // HTML
$posthtml = "<P><FONT FACE=sans-serif>".
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->".
"<A HREF=\"$CFG->wwwroot/mod/exercise/index.php?id=$course->id\">$strexercises</A> ->".
- "<A HREF=\"$CFG->wwwroot/mod/exercise/view.php?a=$exercise->id\">$exercise->name</A></FONT></P>";
+ "<A HREF=\"$CFG->wwwroot/mod/exercise/view.php?id=$cm->id\">$exercise->name</A></FONT></P>";
$posthtml .= "<HR><FONT FACE=sans-serif>";
$posthtml .= "<P>$msg</P>";
$posthtml .= "<P>".get_string("mail3", "exercise").
- " <A HREF=\"$CFG->wwwroot/mod/exercise/view.php?a=$exercise->id\">$exercise->name</A>.</P></FONT><HR>";
+ " <A HREF=\"$CFG->wwwroot/mod/exercise/view.php?id=$cm->id\">$exercise->name</A>.</P></FONT><HR>";
} else {
$posthtml = "";
}
@@ -210,9 +214,16 @@ function exercise_cron () {
echo "Could not find submission $assessment->submissionid\n";
continue;
}
-
- if (! $submissionowner = get_record("user", "id", "$submission->userid")) {
- echo "Could not find user $submission->userid\n";
+ if (! $exercise = get_record("exercise", "id", $submission->exerciseid)) {
+ echo "Could not find exercise record for id $submission->exerciseid\n";
+ continue;
+ }
+ if (! $course = get_record("course", "id", "$exercise->course")) {
+ echo "Could not find course $exercise->course\n";
+ continue;
+ }
+ if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) {
+ error("Course Module ID was incorrect");
continue;
}
@@ -221,24 +232,10 @@ function exercise_cron () {
continue;
}
- if (! $course = get_record("course", "id", "$assessment->course")) {
- echo "Could not find course $assessment->course\n";
- continue;
- }
-
- if (! isstudent($course->id, $submissionowner->id) and !isteacher($course->id, $submissionowner->id)) {
- continue; // Not an active participant
- }
-
if (! isstudent($course->id, $assessmentowner->id) and !isteacher($course->id, $assessmentowner->id)) {
continue; // Not an active participant
}
- if (! $exercise = get_coursemodule_from_instance("exercise", $assessment->exerciseid, $course->id)) {
- echo "Could not find course module for exercise id $submission->exercise\n";
- continue;
- }
-
$strexercises = get_string("modulenameplural", "exercise");
$strexercise = get_string("modulename", "exercise");
@@ -256,17 +253,17 @@ function exercise_cron () {
$posttext .= $msg;
// "You can see it in your exercise assignment"
$posttext .= get_string("mail3", "exercise").":\n";
- $posttext .= " $CFG->wwwroot/mod/exercise/view.php?a=$exercise->id\n";
+ $posttext .= " $CFG->wwwroot/mod/exercise/view.php?id=$cm->id\n";
$posttext .= "---------------------------------------------------------------------\n";
if ($sendto->mailformat == 1) { // HTML
$posthtml = "<P><FONT FACE=sans-serif>".
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->".
- "<A HREF=\"$CFG->wwwroot/mod/exercise/index.php?id=$course->id\">$strexercises</A> ->".
+ "<A HREF=\"$CFG->wwwroot/mod/exercise/index.php?id=$cm->id\">$strexercises</A> ->".
"<A HREF=\"$CFG->wwwroot/mod/exercise/view.php?a=$exercise->id\">$exercise->name</A></FONT></P>";
$posthtml .= "<HR><FONT FACE=sans-serif>";
$posthtml .= "<P>$msg</P>";
$posthtml .= "<P>".get_string("mail3", "exercise").
- " <A HREF=\"$CFG->wwwroot/mod/exercise/view.php?a=$exercise->id\">$exercise->name</A>.</P></FONT><HR>";
+ " <A HREF=\"$CFG->wwwroot/mod/exercise/view.php?id=$cm->id\">$exercise->name</A>.</P></FONT><HR>";
} else {
$posthtml = "";
}
@@ -335,10 +332,10 @@ function exercise_grades($exerciseid) {
if (!$exercise = get_record("exercise", "id", $exerciseid)) {
error("Exercise record not found");
- }
+ }
if (! $course = get_record("course", "id", $exercise->course)) {
error("Course is misconfigured");
- }
+ }
// calculate scaling factor
$scaling = $exercise->grade / (100.0 * ($EXERCISE_FWEIGHTS[$exercise->gradingweight] +
@@ -350,27 +347,27 @@ function exercise_grades($exerciseid) {
foreach ($bestgrades as $bestgrade) {
$return->grades[$bestgrade->userid] = $bestgrade->grade *
$EXERCISE_FWEIGHTS[$exercise->teacherweight] * $scaling;
- }
}
}
+ }
else { // use mean values
if ($meangrades = exercise_get_mean_submission_grades($exercise)) {
foreach ($meangrades as $meangrade) {
$return->grades[$meangrade->userid] = $meangrade->grade *
$EXERCISE_FWEIGHTS[$exercise->teacherweight] * $scaling;
- }
}
}
+ }
// now get the users grading grades
if ($assessments = exercise_get_teacher_submission_assessments($exercise)) {
foreach ($assessments as $assessment) {
// add the grading grade if the student's work has been assessed
if (isset($return->grades[$assessment->userid])) {
$return->grades[$assessment->userid] += $assessment->gradinggrade *
$EXERCISE_FWEIGHTS[$exercise->gradingweight] * $scaling * 100.0 / COMMENTSCALE;
- }
}
}
+ }
$return->maxgrade = get_field("exercise", "grade", "id", "$exerciseid");
return $return;
}
@@ -981,12 +978,25 @@ function exercise_get_assessments($submission) {
}
+///////////////////////////////////////////////////////////////////////////////////////////////
+function exercise_get_best_grade($submission) {
+// Returns the best grade of students' submission (there may, occassionally be more than one assessment)
+ global $CFG;
+
+ return get_record_sql("SELECT MAX(a.grade) grade FROM
+ {$CFG->prefix}exercise_assessments a
+ WHERE a.submissionid = $submission->id
+ GROUP BY a.submissionid");
+}
+
+
///////////////////////////////////////////////////////////////////////////////////////////////
function exercise_get_best_submission_grades($exercise) {
// Returns the grades of students' best submissions
global $CFG;
- return get_records_sql("SELECT DISTINCT MAX(a.grade) grade, u.userid FROM {$CFG->prefix}exercise_submissions s,
+ return get_records_sql("SELECT DISTINCT MAX(a.grade) grade, u.userid FROM
+ {$CFG->prefix}exercise_submissions s,
{$CFG->prefix}exercise_assessments a, {$CFG->prefix}user_students u
WHERE u.course = $exercise->course
AND s.userid = u.userid
@@ -1015,12 +1025,25 @@ function exercise_get_grade_logs($course, $timestart) {
}
+///////////////////////////////////////////////////////////////////////////////////////////////
+function exercise_get_mean_grade($submission) {
+// Returns the mean grade of students' submission (may, very occassionally, be more than one assessment)
+ global $CFG;
+
+ return get_record_sql("SELECT AVG(a.grade) grade FROM
+ {$CFG->prefix}exercise_assessments a
+ WHERE a.submissionid = $submission->id
+ GROUP BY a.submissionid");
+}
+
+
///////////////////////////////////////////////////////////////////////////////////////////////
function exercise_get_mean_submission_grades($exercise) {
// Returns the mean grades of students' submissions
global $CFG;
- return get_records_sql("SELECT DISTINCT AVG(a.grade) grade, u.userid FROM {$CFG->prefix}exercise_submissions s,
+ return get_records_sql("SELECT DISTINCT AVG(a.grade) grade, u.userid FROM
+ {$CFG->prefix}exercise_submissions s,
{$CFG->prefix}exercise_assessments a, {$CFG->prefix}user_students u
WHERE u.course = $exercise->course
AND s.userid = u.userid
Oops, something went wrong.

0 comments on commit b896875

Please sign in to comment.