Skip to content
Browse files

Additional information exercises page (index.php).

  • Loading branch information...
1 parent 3ca5e8b commit b8968752933a201864edd1d5b04ae02bf0eda0cd rkingdon committed
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
67 mod/exercise/index.php
@@ -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,11 +37,19 @@
$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");
@@ -47,7 +57,7 @@
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
99 mod/exercise/lib.php
@@ -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,17 +347,17 @@ 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) {
@@ -368,9 +365,9 @@ function exercise_grades($exerciseid) {
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;
}
@@ -982,11 +979,24 @@ 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
@@ -1016,11 +1026,24 @@ 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
View
85 mod/exercise/view.php
@@ -58,43 +58,44 @@
// has the assignment any elements
if (count_records("exercise_elements", "exerciseid", $exercise->id)) {
$action = "teachersview";
- }
+ }
else {
redirect("assessments.php?action=editelements&id=$cm->id");
- }
}
}
+ }
elseif (!isguest()) { // it's a student then
if (!$cm->visible) {
notice(get_string("activityiscurrentlyhidden"));
- }
+ }
switch ($exercise->phase) {
case 0 :
case 1 : $action = 'notavailable'; break;
case 2 : $action = 'studentsview'; break;
case 3 : $action = 'notavailable'; break;
case 4 : $action = 'displayfinalgrade';
- }
}
+ }
else { // it's a guest, oh no!
$action = 'notavailable';
- }
+ }
- /*********************** close exercise for student assessments and submissions (move to phase 3) (for teachers)**/
+ /************** close exercise for student assessments and submissions (phase 3) (for teachers)**/
if ($action == 'closeexercise') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
- }
+ }
- // move tp phase 3
+ // move to phase 3
set_field("exercise", "phase", 3, "id", "$exercise->id");
+ add_to_log($course->id, "exercise", "close", "view.php?id=$cm->id", "$exercise->id");
redirect("view.php?id=$cm->id", get_string("movingtophase", "exercise", 3));
- }
+ }
- /******************* display final grade (for students) ************************************/
+ /****************** display final grade (for students) ************************************/
elseif ($action == 'displayfinalgrade' ) {
// get the final weights from the database
@@ -118,11 +119,11 @@
if ($ownassessments = exercise_get_user_assessments($exercise, $USER)) {
foreach ($ownassessments as $ownassessment) {
break; // there should only be one
- }
}
+ }
else {
$ownassessment->gradinggrade = 0;
- }
+ }
foreach ($submissions as $submission) {
if ($assessments = exercise_get_assessments($submission)) {
foreach ($assessments as $assessment) { // (normally there should only be one
@@ -134,40 +135,40 @@
/ COMMENTSCALE )) * $exercise->grade) /
($EXERCISE_FWEIGHTS[$teacherweight] + $EXERCISE_FWEIGHTS[$gradingweight]), 1).
"</td></TR>\n";
- }
}
}
}
+ }
echo "</TABLE><BR CLEAR=ALL>\n";
exercise_print_league_table($exercise);
- }
+ }
- /*********************** make final grades available (for teachers only)**************/
+ /****************** make final grades available (for teachers only)**************/
elseif ($action == 'makeleaguetableavailable') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
- }
+ }
set_field("exercise", "phase", 4, "id", "$exercise->id");
+ add_to_log($course->id, "exercise", "display", "view.php?id=$cm->id", "$exercise->id");
redirect("view.php?id=$cm->id", get_string("movingtophase", "exercise", 4));
- add_to_log($course->id, "exercise", "display grades", "view.php?a=$exercise->id", "$exercise->id");
- }
+ }
/*********************** assignment not available (for students)***********************/
elseif ($action == 'notavailable') {
print_heading(get_string("notavailable", "exercise"));
- }
+ }
- /*********************** open exercise for student assessments and submissions (move to phase 2) (for teachers)**/
+ /****************** open exercise for student assessments and submissions (phase 2) (for teachers)**/
elseif ($action == 'openexercise') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
- }
+ }
// move to phase 2, check that teacher has made enough submissions
if (exercise_count_teacher_submissions($exercise) == 0) {
@@ -175,32 +176,33 @@
}
else {
set_field("exercise", "phase", 2, "id", "$exercise->id");
- redirect("view.php?id=$cm->id", get_string("movingtophase", "exercise", 2));
add_to_log($course->id, "exercise", "open", "view.php?id=$cm->id", "$exercise->id");
- }
+ redirect("view.php?id=$cm->id", get_string("movingtophase", "exercise", 2));
}
+ }
- /*********************** set up assignment (move back to phase 1) (for teachers)***********************/
+ /****************** set up assignment (move back to phase 1) (for teachers)***********************/
elseif ($action == 'setupassignment') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
- }
+ }
set_field("exercise", "phase", 1, "id", "$exercise->id");
+ add_to_log($course->id, "exercise", "set up", "view.php?id=$cm->id", "$exercise->id");
redirect("view.php?id=$cm->id", get_string("movingtophase", "exercise", 1));
- }
+ }
- /*********************** student's view could be in 1 of 4 stages ***********************/
+ /****************** student's view could be in 1 of 4 stages ***********************/
elseif ($action == 'studentsview') {
exercise_print_assignment_info($exercise);
// in Stage 1 - the student must make an assessment (linked to the teacher's exercise/submission
if (!exercise_test_user_assessments($exercise, $USER)) {
print_heading(get_string("pleaseviewtheexercise", "exercise", $course->teacher));
exercise_list_teacher_submissions($exercise, $USER);
- }
+ }
// in stage 2? - submit own first attempt
else {
// show assessment the teacher's examples, there may be feedback from teacher
@@ -210,8 +212,9 @@
// print upload form
print_heading(get_string("pleasesubmityourwork", "exercise").":");
exercise_print_upload_form($exercise);
- }
- // in stage 3? - awaiting grading of assessment and assessment of work by teacher, may resubmit if allowed
+ }
+ // in stage 3? - awaiting grading of assessment and assessment of work by teacher,
+ // may resubmit if allowed
else {
print_heading(get_string("yourassessment", "exercise"));
exercise_list_teacher_submissions($exercise, $USER);
@@ -224,18 +227,18 @@
print_heading(get_string("pleasesubmityourwork", "exercise").":");
exercise_print_upload_form($exercise);
echo "<hr size=\"1\" noshade>";
- }
}
}
}
+ }
- /*********************** submission of assignment by teacher only***********************/
+ /****************** submission of assignment by teacher only***********************/
elseif ($action == 'submitassignment') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
- }
+ }
exercise_print_assignment_info($exercise);
@@ -247,7 +250,7 @@
// print upload form
print_heading(get_string("submitexercisedescription", "exercise").":");
exercise_print_upload_form($exercise);
- }
+ }
/****************** teacher's view - display admin page (current phase options) ************/
@@ -255,7 +258,7 @@
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
- }
+ }
print_heading_with_help(get_string("managingassignment", "exercise"), "managing", "exercise");
@@ -307,16 +310,16 @@
case 4: // show final grades
print_heading("<A HREF=\"submissions.php?id=$cm->id&action=displayfinalgrades\">".
get_string("displayoffinalgrades", "exercise")."</A>");
- }
+ }
print_heading("<A HREF=\"submissions.php?id=$cm->id&action=adminlist\">".
get_string("administration")."</A>");
- }
+ }
- /*************** no man's land **************************************/
- else {
- error("Fatal Error: Unknown Action: ".$action."\n");
- }
+ /*************** no man's land **************************************/
+ else {
+ error("Fatal Error: Unknown Action: ".$action."\n");
+ }
print_footer($course);

0 comments on commit b896875

Please sign in to comment.
Something went wrong with that request. Please try again.