From: gustav_delius Date: Tue, 8 Jun 2004 21:23:26 +0000 (+0000) Subject: fixed problems with undefined $USER->id in recent activity block when no user logged in. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5e607236f39c8e6e4a7211f6932ca3b0bf5ab001;p=moodle.git fixed problems with undefined $USER->id in recent activity block when no user logged in. --- diff --git a/mod/dialogue/lib.php b/mod/dialogue/lib.php index b8697c076d..706ea48d8d 100644 --- a/mod/dialogue/lib.php +++ b/mod/dialogue/lib.php @@ -36,35 +36,35 @@ function dialogue_cron () { if (! $userfrom = get_record("user", "id", "$entry->userid")) { echo "Could not find user $entry->userid\n"; continue; - } - // get conversation record - if(!$conversation = get_record("dialogue_conversations", "id", $entry->conversationid)) { - echo "Could not find conversation $entry->conversationid\n"; - } - if ($userfrom->id == $conversation->userid) { - if (!$userto = get_record("user", "id", $conversation->recipientid)) { - echo "Could not find use $conversation->recipientid\n"; - } - } - else { - if (!$userto = get_record("user", "id", $conversation->userid)) { - echo "Could not find use $conversation->userid\n"; - } - } + } + // get conversation record + if(!$conversation = get_record("dialogue_conversations", "id", $entry->conversationid)) { + echo "Could not find conversation $entry->conversationid\n"; + } + if ($userfrom->id == $conversation->userid) { + if (!$userto = get_record("user", "id", $conversation->recipientid)) { + echo "Could not find use $conversation->recipientid\n"; + } + } + else { + if (!$userto = get_record("user", "id", $conversation->userid)) { + echo "Could not find use $conversation->userid\n"; + } + } $USER->lang = $userto->lang; if (! $dialogue = get_record("dialogue", "id", $conversation->dialogueid)) { echo "Could not find dialogue id $conversation->dialogueid\n"; continue; - } - if (! $course = get_record("course", "id", "$dialogue->course")) { + } + if (! $course = get_record("course", "id", "$dialogue->course")) { echo "Could not find course $dialogue->course\n"; continue; - } - if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { - echo "Course Module ID was incorrect\n"; - } + } + if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { + echo "Course Module ID was incorrect\n"; + } if (! isstudent($course->id, $userfrom->id) and !isteacher($course->id, $userfrom->id)) { continue; // Not an active participant @@ -73,9 +73,9 @@ function dialogue_cron () { continue; // Not an active participant } - $strdialogues = get_string("modulenameplural", "dialogue"); - $strdialogue = get_string("modulename", "dialogue"); - + $strdialogues = get_string("modulenameplural", "dialogue"); + $strdialogue = get_string("modulename", "dialogue"); + unset($dialogueinfo); $dialogueinfo->userfrom = "$userfrom->firstname $userfrom->lastname"; $dialogueinfo->dialogue = "$dialogue->name"; @@ -145,108 +145,108 @@ function dialogue_delete_instance($id) { function dialogue_print_recent_activity($course, $isteacher, $timestart) { global $CFG; - // have a look for new entries + // have a look for new entries $addentrycontent = false; - if ($logs = dialogue_get_add_entry_logs($course, $timestart)) { - // got some, see if any belong to a visible module - foreach ($logs as $log) { - // Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->dialogueid; - //Obtain the visible property from the instance - if (instance_is_visible("dialogue",$tempmod)) { - $addentrycontent = true; - break; - } - } - // if we got some "live" ones then output them - if ($addentrycontent) { - $strftimerecent = get_string("strftimerecent"); - print_headline(get_string("newdialogueentries", "dialogue").":"); - foreach ($logs as $log) { - //Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->dialogueid; - //Obtain the visible property from the instance - if (instance_is_visible("dialogue",$tempmod)) { - $date = userdate($log->time, $strftimerecent); - echo "

$date - $log->firstname $log->lastname
"; - echo "\"wwwroot/mod/dialogue/$log->url\">"; - echo "$log->name"; - echo "\"

"; - } - } - } - } - - // have a look for open conversations + if ($logs = dialogue_get_add_entry_logs($course, $timestart)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->dialogueid; + //Obtain the visible property from the instance + if (instance_is_visible("dialogue",$tempmod)) { + $addentrycontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($addentrycontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("newdialogueentries", "dialogue").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->dialogueid; + //Obtain the visible property from the instance + if (instance_is_visible("dialogue",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + echo "

$date - $log->firstname $log->lastname
"; + echo "\"wwwroot/mod/dialogue/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } + + // have a look for open conversations $opencontent = false; - if ($logs = dialogue_get_open_conversations($course)) { - // got some, see if any belong to a visible module - foreach ($logs as $log) { - // Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->dialogueid; - //Obtain the visible property from the instance - if (instance_is_visible("dialogue",$tempmod)) { - $opencontent = true; - break; - } - } - // if we got some "live" ones then output them - if ($opencontent) { - $strftimerecent = get_string("strftimerecent"); - print_headline(get_string("opendialogueentries", "dialogue").":"); - foreach ($logs as $log) { - //Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->dialogueid; - //Obtain the visible property from the instance - if (instance_is_visible("dialogue",$tempmod)) { - $date = userdate($log->time, $strftimerecent); - echo "

$date - $log->firstname $log->lastname
"; - echo "\"wwwroot/mod/dialogue/$log->url\">"; - echo "$log->name"; - echo "\"

"; - } - } - } - } - - // have a look for closed conversations - $closedcontent = false; + if ($logs = dialogue_get_open_conversations($course)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->dialogueid; + //Obtain the visible property from the instance + if (instance_is_visible("dialogue",$tempmod)) { + $opencontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($opencontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("opendialogueentries", "dialogue").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->dialogueid; + //Obtain the visible property from the instance + if (instance_is_visible("dialogue",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + echo "

$date - $log->firstname $log->lastname
"; + echo "\"wwwroot/mod/dialogue/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } + + // have a look for closed conversations + $closedcontent = false; if ($logs = dialogue_get_closed_logs($course, $timestart)) { - // got some, see if any belong to a visible module - foreach ($logs as $log) { - // Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->dialogueid; - //Obtain the visible property from the instance - if (instance_is_visible("dialogue",$tempmod)) { - $closedcontent = true; - break; - } - } - // if we got some "live" ones then output them - if ($closedcontent) { - $strftimerecent = get_string("strftimerecent"); - print_headline(get_string("modulenameplural", "dialogue").":"); - foreach ($logs as $log) { - //Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->dialogueid; - //Obtain the visible property from the instance - if (instance_is_visible("dialogue",$tempmod)) { - $date = userdate($log->time, $strftimerecent); - echo "

$date - ".get_string("namehascloseddialogue", "dialogue", - "$log->firstname $log->lastname")."
"; - echo "\"wwwroot/mod/dialogue/$log->url\">"; - echo "$log->name"; - echo "\"

"; - } - } - } - } + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->dialogueid; + //Obtain the visible property from the instance + if (instance_is_visible("dialogue",$tempmod)) { + $closedcontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($closedcontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("modulenameplural", "dialogue").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->dialogueid; + //Obtain the visible property from the instance + if (instance_is_visible("dialogue",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + echo "

$date - ".get_string("namehascloseddialogue", "dialogue", + "$log->firstname $log->lastname")."
"; + echo "\"wwwroot/mod/dialogue/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } return $addentrycontent or $closedcontent; } @@ -269,40 +269,40 @@ function dialogue_update_instance($dialogue) { function dialogue_user_complete($course, $user, $mod, $dialogue) { if ($conversations = dialogue_get_conversations($dialogue, $user)) { - print_simple_box_start(); - $table->head = array (get_string("dialoguewith", "dialogue"), + print_simple_box_start(); + $table->head = array (get_string("dialoguewith", "dialogue"), get_string("numberofentries", "dialogue"), get_string("lastentry", "dialogue"), get_string("status", "dialogue")); - $table->width = "100%"; - $table->align = array ("left", "center", "left", "left"); - $table->size = array ("*", "*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - foreach ($conversations as $conversation) { - if ($user->id != $conversation->userid) { - if (!$with = get_record("user", "id", $conversation->userid)) { - error("User's record not found"); - } - } - else { - if (!$with = get_record("user", "id", $conversation->recipientid)) { - error("User's record not found"); - } - } - $total = dialogue_count_entries($dialogue, $conversation); - $byuser = dialogue_count_entries($dialogue, $conversation, $user); - if ($conversation->closed) { - $status = get_string("closed", "dialogue"); - } else { - $status = get_string("open", "dialogue"); - } - $table->data[] = array("$with->firstname $with->lastname", $byuser." ". + $table->width = "100%"; + $table->align = array ("left", "center", "left", "left"); + $table->size = array ("*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + foreach ($conversations as $conversation) { + if ($user->id != $conversation->userid) { + if (!$with = get_record("user", "id", $conversation->userid)) { + error("User's record not found"); + } + } + else { + if (!$with = get_record("user", "id", $conversation->recipientid)) { + error("User's record not found"); + } + } + $total = dialogue_count_entries($dialogue, $conversation); + $byuser = dialogue_count_entries($dialogue, $conversation, $user); + if ($conversation->closed) { + $status = get_string("closed", "dialogue"); + } else { + $status = get_string("open", "dialogue"); + } + $table->data[] = array("$with->firstname $with->lastname", $byuser." ". get_string("of", "dialogue")." ".$total, userdate($conversation->timemodified), $status); - } - print_table($table); - print_simple_box_end(); - } + } + print_table($table); + print_simple_box_end(); + } else { print_string("noentry", "dialogue"); } @@ -313,11 +313,11 @@ function dialogue_user_complete($course, $user, $mod, $dialogue) { function dialogue_user_outline($course, $user, $mod, $dialogue) { if ($entries = dialogue_get_user_entries($dialogue, $user)) { $result->info = count($entries); - foreach ($entries as $entry) { - // dialogue_get_user_entries returns the most recent entry first - $result->time = $entry->timecreated; - break; - } + foreach ($entries as $entry) { + // dialogue_get_user_entries returns the most recent entry first + $result->time = $entry->timecreated; + break; + } return $result; } return NULL; @@ -332,49 +332,49 @@ function dialogue_count_all_needing_replies_self($user = '') { // function requested by Williams Castillo 17 Oct 2003 global $USER; - if ($user) { - return count_records_select("dialogue_conversations", "(userid = $user->id OR + if ($user) { + return count_records_select("dialogue_conversations", "(userid = $user->id OR recipientid = $user->id) AND lastid != $user->id AND closed = 0"); } else { - return count_records_select("dialogue_conversations", "(userid = $USER->id OR + return count_records_select("dialogue_conversations", "(userid = $USER->id OR recipientid = $USER->id) AND lastid != $USER->id AND closed = 0"); - } + } } ////////////////////////////////////////////////////////////////////////////////////// function dialogue_count_closed($dialogue, $user) { - - return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND + + return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND (userid = $user->id OR recipientid = $user->id) AND closed = 1"); - } + } ////////////////////////////////////////////////////////////////////////////////////// function dialogue_count_entries($dialogue, $conversation, $user = '') { - - if (empty($user)) { - return count_records_select("dialogue_entries", "conversationid = $conversation->id"); - } - else { - return count_records_select("dialogue_entries", "conversationid = $conversation->id AND + + if (empty($user)) { + return count_records_select("dialogue_entries", "conversationid = $conversation->id"); + } + else { + return count_records_select("dialogue_entries", "conversationid = $conversation->id AND userid = $user->id"); - } + } } ////////////////////////////////////////////////////////////////////////////////////// function dialogue_count_open($dialogue, $user) { - - return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND + + return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND (userid = $user->id OR recipientid = $user->id) AND closed = 0"); } ////////////////////////////////////////////////////////////////////////////////////// function dialogue_count_needing_replies_other($dialogue, $user) { -// count [conversations] needing replies [from] other [person] - return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND +// count [conversations] needing replies [from] other [person] + return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND (userid = $user->id OR recipientid = $user->id) AND lastid = $user->id AND closed = 0"); } @@ -382,8 +382,8 @@ function dialogue_count_needing_replies_other($dialogue, $user) { ////////////////////////////////////////////////////////////////////////////////////// function dialogue_count_needing_replies_self($dialogue, $user) { // count [conversations] needing replies [from] self - - return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND + + return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND (userid = $user->id OR recipientid = $user->id) AND lastid != $user->id AND closed = 0"); } @@ -484,25 +484,25 @@ function dialogue_get_available_users($dialogue) { ////////////////////////////////////////////////////////////////////////////////////// function dialogue_get_available_students($dialogue) { global $USER; - + if (! $course = get_record("course", "id", $dialogue->course)) { error("Course is misconfigured"); } // get the students on this course... - if ($users = get_course_students($course->id, "u.firstname, u.lastname")) { - foreach ($users as $otheruser) { - // ...exclude self and... - if ($USER->id != $otheruser->id) { - // ...any already in any open conversations unless multiple conversations allowed - if ($dialogue->multipleconversations or count_records_select("dialogue_conversations", + if ($users = get_course_students($course->id, "u.firstname, u.lastname")) { + foreach ($users as $otheruser) { + // ...exclude self and... + if ($USER->id != $otheruser->id) { + // ...any already in any open conversations unless multiple conversations allowed + if ($dialogue->multipleconversations or count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND ((userid = $USER->id AND recipientid = $otheruser->id) OR (userid = $otheruser->id AND recipientid = $USER->id)) AND closed = 0") == 0) { - $names[$otheruser->id] = "$otheruser->firstname $otheruser->lastname"; - } - } - } - } + $names[$otheruser->id] = "$otheruser->firstname $otheruser->lastname"; + } + } + } + } if (isset($names)) { return $names; } @@ -513,30 +513,30 @@ global $USER; ////////////////////////////////////////////////////////////////////////////////////// function dialogue_get_available_teachers($dialogue) { global $USER; - + if (! $course = get_record("course", "id", $dialogue->course)) { error("Course is misconfigured"); } // get the teachers on this course... - if ($users = get_course_teachers($course->id, "u.firstname, u.lastname")) { - // $names[0] = "-----------------------"; - foreach ($users as $otheruser) { + if ($users = get_course_teachers($course->id, "u.firstname, u.lastname")) { + // $names[0] = "-----------------------"; + foreach ($users as $otheruser) { // ...exclude self and ... - if ($USER->id != $otheruser->id) { + if ($USER->id != $otheruser->id) { // ...any already in open conversations unless multiple conversations allowed - if ($dialogue->multipleconversations or count_records_select("dialogue_conversations", + if ($dialogue->multipleconversations or count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND ((userid = $USER->id AND recipientid = $otheruser->id) OR (userid = $otheruser->id AND recipientid = $USER->id)) AND closed = 0") == 0) { - $names[$otheruser->id] = "$otheruser->firstname $otheruser->lastname"; - } - } - } - } - if (isset($names)) { - return $names; - } - return; + $names[$otheruser->id] = "$otheruser->firstname $otheruser->lastname"; + } + } + } + } + if (isset($names)) { + return $names; + } + return; } @@ -544,8 +544,8 @@ global $USER; ////////////////////////////////////////////////////////////////////////////////////// function dialogue_get_conversations($dialogue, $user, $condition = '', $order = '') { global $CFG; - - if (!empty($condition)) { + + if (!empty($condition)) { $condition = ' AND '.$condition; } if (empty($order)) { @@ -584,31 +584,37 @@ function dialogue_get_user_entries($dialogue, $user) { ////////////////////////////////////////////////////////////////////////////////////// function dialogue_get_add_entry_logs($course, $timestart) { - // get the "add entry" entries and add the first and last names, we are not interested in the entries - // make by this user (the last condition)! - global $CFG, $USER; + // get the "add entry" entries and add the first and last names, we are not interested in the entries + // make by this user (the last condition)! + global $CFG, $USER; + if (empty($USER->id)) { + return false; + } return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, e.dialogueid, d.name FROM {$CFG->prefix}log l, - {$CFG->prefix}dialogue d, - {$CFG->prefix}dialogue_conversations c, + {$CFG->prefix}dialogue d, + {$CFG->prefix}dialogue_conversations c, {$CFG->prefix}dialogue_entries e, {$CFG->prefix}user u WHERE l.time > $timestart AND l.course = $course->id AND l.module = 'dialogue' - AND l.action = 'add entry' - AND e.id = l.info - AND c.id = e.conversationid + AND l.action = 'add entry' + AND e.id = l.info + AND c.id = e.conversationid AND (c.userid = $USER->id or c.recipientid = $USER->id) - AND d.id = e.dialogueid - AND u.id = e.userid - AND e.userid != $USER->id"); + AND d.id = e.dialogueid + AND u.id = e.userid + AND e.userid != $USER->id"); } ////////////////////////////////////////////////////////////////////////////////////// function dialogue_get_open_conversations($course) { - // get the conversations which are waiting for a response for this user. + // get the conversations which are waiting for a response for this user. // Add the first and last names of the other participant - global $CFG, $USER; + global $CFG, $USER; + if (empty($USER->id)) { + return false; + } if ($conversations = get_records_sql("SELECT d.name dialoguename, c.id, c.dialogueid, c.timemodified, c.lastid FROM {$CFG->prefix}dialogue d, {$CFG->prefix}dialogue_conversations c WHERE d.course = $course->id @@ -630,7 +636,7 @@ function dialogue_get_open_conversations($course) { $entry[$conversation->id]->firstname = $user->firstname; $entry[$conversation->id]->lastname = $user->lastname; $entry[$conversation->id]->name = $conversation->dialoguename; - } + } return $entry; } return; @@ -639,21 +645,24 @@ function dialogue_get_open_conversations($course) { ////////////////////////////////////////////////////////////////////////////////////// function dialogue_get_closed_logs($course, $timestart) { - // get the "closed" entries and add the first and last names, we are not interested in the entries - // make by this user (the last condition)! - global $CFG, $USER; + // get the "closed" entries and add the first and last names, we are not interested in the entries + // make by this user (the last condition)! + global $CFG, $USER; + if (empty($USER->id)) { + return false; + } return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, c.dialogueid, d.name FROM {$CFG->prefix}log l, - {$CFG->prefix}dialogue d, - {$CFG->prefix}dialogue_conversations c, + {$CFG->prefix}dialogue d, + {$CFG->prefix}dialogue_conversations c, {$CFG->prefix}user u WHERE l.time > $timestart AND l.course = $course->id AND l.module = 'dialogue' - AND l.action = 'closed' - AND c.id = l.info + AND l.action = 'closed' + AND c.id = l.info AND (c.userid = $USER->id or c.recipientid = $USER->id) - AND d.id = c.dialogueid - AND u.id = c.lastid - AND c.lastid != $USER->id"); + AND d.id = c.dialogueid + AND u.id = c.lastid + AND c.lastid != $USER->id"); } @@ -663,59 +672,59 @@ function dialogue_get_closed_logs($course, $timestart) { function dialogue_list_conversations_closed($dialogue) { // list the closed for the current user global $USER; - - if (! $course = get_record("course", "id", $dialogue->course)) { + + if (! $course = get_record("course", "id", $dialogue->course)) { error("Course is misconfigured"); } if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { error("Course Module ID was incorrect"); } - + if ($conversations = dialogue_get_conversations($dialogue, $USER, "closed = 1")) { // reorder the conversations by (other) name foreach ($conversations as $conversation) { - if ($USER->id != $conversation->userid) { - if (!$with = get_record("user", "id", $conversation->userid)) { - error("User's record not found"); - } - } - else { - if (!$with = get_record("user", "id", $conversation->recipientid)) { - error("User's record not found"); - } - } + if ($USER->id != $conversation->userid) { + if (!$with = get_record("user", "id", $conversation->userid)) { + error("User's record not found"); + } + } + else { + if (!$with = get_record("user", "id", $conversation->recipientid)) { + error("User's record not found"); + } + } $names[$conversation->id] = "$with->firstname $with->lastname"; } asort($names); - print_simple_box_start(); - $table->head = array (get_string("dialoguewith", "dialogue"), get_string("subject", "dialogue"), + print_simple_box_start(); + $table->head = array (get_string("dialoguewith", "dialogue"), get_string("subject", "dialogue"), get_string("numberofentries", "dialogue"), get_string("lastentry", "dialogue"), get_string("status", "dialogue")); - $table->width = "100%"; - $table->align = array ("left", "left", "center", "left", "left"); - $table->size = array ("*", "*", "*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; + $table->width = "100%"; + $table->align = array ("left", "left", "center", "left", "left"); + $table->size = array ("*", "*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; - foreach ($names as $cid=>$name) { + foreach ($names as $cid=>$name) { if (!$conversation = get_record("dialogue_conversations", "id", $cid)) { error("Closed conversations: could not find conversation record"); } - $total = dialogue_count_entries($dialogue, $conversation); - $byuser = dialogue_count_entries($dialogue, $conversation, $USER); - if ($conversation->closed) { - $status = get_string("closed", "dialogue"); - } else { - $status = get_string("open", "dialogue"); - } - $table->data[] = array("id&action=showdialogues&cid=$conversation->id\">". - "$name", $conversation->subject, $byuser." ".get_string("of", "dialogue")." ".$total, - userdate($conversation->timemodified), $status); - } - print_table($table); - print_simple_box_end(); - } + $total = dialogue_count_entries($dialogue, $conversation); + $byuser = dialogue_count_entries($dialogue, $conversation, $USER); + if ($conversation->closed) { + $status = get_string("closed", "dialogue"); + } else { + $status = get_string("open", "dialogue"); + } + $table->data[] = array("id&action=showdialogues&cid=$conversation->id\">". + "$name", $conversation->subject, $byuser." ".get_string("of", "dialogue")." ".$total, + userdate($conversation->timemodified), $status); + } + print_table($table); + print_simple_box_end(); + } } @@ -723,60 +732,60 @@ function dialogue_list_conversations_closed($dialogue) { function dialogue_list_conversations_other($dialogue) { // list the conversations of the current user awaiting response from the other person global $THEME, $USER; - - if (!$course = get_record("course", "id", $dialogue->course)) { + + if (!$course = get_record("course", "id", $dialogue->course)) { error("Course is misconfigured"); } if (!$cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { error("Course Module ID was incorrect"); } - + $timenow = time(); if ($conversations = dialogue_get_conversations($dialogue, $USER, "lastid = $USER->id AND closed = 0")) { // reorder the conversations by (other) name foreach ($conversations as $conversation) { - if ($USER->id != $conversation->userid) { - if (!$with = get_record("user", "id", $conversation->userid)) { - error("User's record not found"); - } - } - else { - if (!$with = get_record("user", "id", $conversation->recipientid)) { - error("User's record not found"); - } - } + if ($USER->id != $conversation->userid) { + if (!$with = get_record("user", "id", $conversation->userid)) { + error("User's record not found"); + } + } + else { + if (!$with = get_record("user", "id", $conversation->recipientid)) { + error("User's record not found"); + } + } $names[$conversation->id] = "$with->firstname $with->lastname"; } asort($names); - print_simple_box_start(); - $table->head = array (get_string("dialoguewith", "dialogue"), get_string("subject", "dialogue"), + print_simple_box_start(); + $table->head = array (get_string("dialoguewith", "dialogue"), get_string("subject", "dialogue"), get_string("numberofentries", "dialogue"), get_string("lastentry", "dialogue"), get_string("status", "dialogue")); - $table->width = "100%"; - $table->align = array ("left", "left", "center", "left", "left"); - $table->size = array ("*", "*", "*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; + $table->width = "100%"; + $table->align = array ("left", "left", "center", "left", "left"); + $table->size = array ("*", "*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; - foreach ($names as $cid=>$name) { + foreach ($names as $cid=>$name) { if (!$conversation = get_record("dialogue_conversations", "id", $cid)) { error("Closed conversations: could not find conversation record"); } - $total = dialogue_count_entries($dialogue, $conversation); - $byuser = dialogue_count_entries($dialogue, $conversation, $USER); - if ($conversation->seenon) { - $status = get_string("seen", "dialogue", format_time($timenow - $conversation->seenon)); - } else { - $status = get_string("notyetseen", "dialogue"); - } - $table->data[] = array("id&action=printdialogue&cid=$conversation->id\">". - "$name", $conversation->subject, $byuser." ".get_string("of", "dialogue")." ".$total, - userdate($conversation->timemodified), $status); - } - print_table($table); - print_simple_box_end(); - } + $total = dialogue_count_entries($dialogue, $conversation); + $byuser = dialogue_count_entries($dialogue, $conversation, $USER); + if ($conversation->seenon) { + $status = get_string("seen", "dialogue", format_time($timenow - $conversation->seenon)); + } else { + $status = get_string("notyetseen", "dialogue"); + } + $table->data[] = array("id&action=printdialogue&cid=$conversation->id\">". + "$name", $conversation->subject, $byuser." ".get_string("of", "dialogue")." ".$total, + userdate($conversation->timemodified), $status); + } + print_table($table); + print_simple_box_end(); + } } @@ -784,125 +793,125 @@ function dialogue_list_conversations_other($dialogue) { function dialogue_list_conversations_self($dialogue) { // list open conversations of the current user awaiting their reply global $THEME, $USER; - - if (! $course = get_record("course", "id", $dialogue->course)) { + + if (! $course = get_record("course", "id", $dialogue->course)) { error("Course is misconfigured"); } if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { error("Course Module ID was incorrect"); } - - $timenow = time(); - $showbutton = false; - $showemoticon = false; // never show emoticons for now - need to close or reload the popup + + $timenow = time(); + $showbutton = false; + $showemoticon = false; // never show emoticons for now - need to close or reload the popup // window to get the focus into the correct textarea on the second time round - - echo "
\n"; - echo "\n"; - echo "id\">\n"; - echo "\n"; - - // list the conversations requiring a resonse from this user in full - if ($conversations = dialogue_get_conversations($dialogue, $USER, "lastid != $USER->id AND closed = 0")) { - $showbutton = true; - print_simple_box_start("center"); - foreach ($conversations as $conversation) { + + echo "\n"; + echo "\n"; + echo "id\">\n"; + echo "\n"; + + // list the conversations requiring a resonse from this user in full + if ($conversations = dialogue_get_conversations($dialogue, $USER, "lastid != $USER->id AND closed = 0")) { + $showbutton = true; + print_simple_box_start("center"); + foreach ($conversations as $conversation) { // set seenon if required if (!$conversation->seenon) { if (!set_field("dialogue_conversations", "seenon", $timenow, "id", $conversation->id)) { error("List conversations self: could not set seenon"); } } - echo "
\n"; - echo ""; - echo ""; - - if ($entries = get_records_select("dialogue_entries", "conversationid = $conversation->id", "id")) { - foreach ($entries as $entry) { - if ($entry->userid == $USER->id) { - echo ""; + + if ($entries = get_records_select("dialogue_entries", "conversationid = $conversation->id", "id")) { + foreach ($entries as $entry) { + if ($entry->userid == $USER->id) { + echo "\n"; - } - else { - echo "\n"; + } + else { + echo "\n"; - } - } - } - - echo "\n"; - echo ""; - echo "
cellheading2\" valign=\"top\">\n"; - if ($conversation->userid == $USER->id) { - if (!$otheruser = get_record("user", "id", $conversation->recipientid)) { - error("User not found"); - } - } - else { - if (!$otheruser = get_record("user", "id", $conversation->userid)) { - error("User not found"); - } - } - // print_user_picture($user->id, $course->id, $user->picture); - echo "".get_string("dialoguewith", "dialogue", "$otheruser->firstname $otheruser->lastname"). + echo "
cellheading2\" valign=\"top\">\n"; + if ($conversation->userid == $USER->id) { + if (!$otheruser = get_record("user", "id", $conversation->recipientid)) { + error("User not found"); + } + } + else { + if (!$otheruser = get_record("user", "id", $conversation->userid)) { + error("User not found"); + } + } + // print_user_picture($user->id, $course->id, $user->picture); + echo "".get_string("dialoguewith", "dialogue", "$otheruser->firstname $otheruser->lastname"). "cellheading2\">$conversation->subject 
\n"; + echo "
cellheading2\">$conversation->subject 
\n"; echo "
\n"; - if (!$conversation->subject) { + if (!$conversation->subject) { // conversation does not have a subject, show add subject link echo "id&cid=$conversation->id&pane=2\">". - get_string("addsubject", "dialogue")."\n"; - helpbutton("addsubject", get_string("addsubject", "dialogue"), "dialogue"); + get_string("addsubject", "dialogue")."\n"; + helpbutton("addsubject", get_string("addsubject", "dialogue"), "dialogue"); echo "  | "; } - if (dialogue_count_entries($dialogue, $conversation)) { - echo "id&cid=$conversation->id&pane=1\">". - get_string("close", "dialogue")."\n"; - helpbutton("closedialogue", get_string("close", "dialogue"), "dialogue"); - } - else { - echo " "; - } - echo "
\n"; - echo text_to_html("".get_string("onyouwrote", "dialogue", + if (dialogue_count_entries($dialogue, $conversation)) { + echo "id&cid=$conversation->id&pane=1\">". + get_string("close", "dialogue")."\n"; + helpbutton("closedialogue", get_string("close", "dialogue"), "dialogue"); + } + else { + echo " "; + } + echo "
\n"; + echo text_to_html("".get_string("onyouwrote", "dialogue", userdate($entry->timecreated)).":
".$entry->text); - echo "
body\">\n"; - echo text_to_html("".get_string("onwrote", "dialogue", + echo "
body\">\n"; + echo text_to_html("".get_string("onwrote", "dialogue", userdate($entry->timecreated)." ".$otheruser->firstname). ":
".$entry->text); - echo "
\n"; - if ($entries) { - echo "".get_string("typereply", "dialogue")."\n"; - } - else { - echo "".get_string("typefirstentry", "dialogue")."\n"; - } - echo "
\n"; - helpbutton("writing", get_string("helpwriting"), "dialogue", true, true); - echo "
"; - if ($showemoticon) { - emoticonhelpbutton("replies", "reply$conversation->id"); - $showemoticon = false; - } - echo "
\n"; - // use a cumbersome name on the textarea as the emoticonhelp doesn't like an "array" name - echo "\n"; - echo "

\n"; - } - print_simple_box_end(); - if ($showbutton) { - echo "
\n"; - echo "".get_string("sendmailmessages", "dialogue").": \n"; - if ($dialogue->maildefault) { - echo " \n"; - } - else { - echo " \n"; - } - helpbutton("sendmail", get_string("sendmailmessages", "dialogue"), "dialogue"); - echo "
\n"; - } - echo "
\n"; - } + echo "\n"; + } + } + } + + echo "\n"; + if ($entries) { + echo "".get_string("typereply", "dialogue")."\n"; + } + else { + echo "".get_string("typefirstentry", "dialogue")."\n"; + } + echo "\n"; + echo "\n"; + helpbutton("writing", get_string("helpwriting"), "dialogue", true, true); + echo "
"; + if ($showemoticon) { + emoticonhelpbutton("replies", "reply$conversation->id"); + $showemoticon = false; + } + echo "\n"; + // use a cumbersome name on the textarea as the emoticonhelp doesn't like an "array" name + echo "\n"; + echo ""; + echo "
\n"; + } + print_simple_box_end(); + if ($showbutton) { + echo "
\n"; + echo "".get_string("sendmailmessages", "dialogue").": \n"; + if ($dialogue->maildefault) { + echo " \n"; + } + else { + echo " \n"; + } + helpbutton("sendmail", get_string("sendmailmessages", "dialogue"), "dialogue"); + echo "
\n"; + } + echo "\n"; + } } @@ -910,23 +919,23 @@ function dialogue_list_conversations_self($dialogue) { function dialogue_print_conversation($dialogue, $conversation) { // print a conversation and allow a new entry global $THEME, $USER; - - if (! $course = get_record("course", "id", $dialogue->course)) { + + if (! $course = get_record("course", "id", $dialogue->course)) { error("Course is misconfigured"); } if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { error("Course Module ID was incorrect"); } - - $timenow = time(); - $showbutton = false; - $showemoticon = false; // never show emoticons for now - need to close or reload the popup + + $timenow = time(); + $showbutton = false; + $showemoticon = false; // never show emoticons for now - need to close or reload the popup // window to get the focus into the correct textarea on the second time round - - echo "
\n"; - echo "\n"; - echo "id\">\n"; - echo "\n"; + + echo "\n"; + echo "\n"; + echo "id\">\n"; + echo "\n"; $showbutton = true; print_simple_box_start("center", "", $THEME->cellcontent2); @@ -991,20 +1000,20 @@ function dialogue_print_conversation($dialogue, $conversation) { echo "\n"; echo ""; echo "
\n"; - print_simple_box_end(); - if ($showbutton) { - echo "
\n"; - echo "".get_string("sendmailmessages", "dialogue").": \n"; - if ($dialogue->maildefault) { - echo " \n"; - } - else { - echo " \n"; - } - helpbutton("sendmail", get_string("sendmailmessages", "dialogue"), "dialogue"); - echo "
\n"; - } - echo "
\n"; + print_simple_box_end(); + if ($showbutton) { + echo "
\n"; + echo "".get_string("sendmailmessages", "dialogue").": \n"; + if ($dialogue->maildefault) { + echo " \n"; + } + else { + echo " \n"; + } + helpbutton("sendmail", get_string("sendmailmessages", "dialogue"), "dialogue"); + echo "
\n"; + } + echo "\n"; } @@ -1012,26 +1021,26 @@ function dialogue_print_conversation($dialogue, $conversation) { function dialogue_print_tabbed_heading($tabs) { // Prints a tabbed heading where one of the tabs highlighted. // $tabs is an object with several properties. -// $tabs->names is an array of tab names -// $tabs->urls is an array of links -// $tabs->align is an array of column alignments (defaults to "center") -// $tabs->size is an array of column sizes -// $tabs->wrap is an array of "nowrap"s or nothing -// $tabs->highlight is an index (zero based) of "active" heading . -// $tabs->width is an percentage of the page (defualts to 80%) -// $tabs->cellpadding padding on each cell (defaults to 5) - - global $CFG, $THEME; - +// $tabs->names is an array of tab names +// $tabs->urls is an array of links +// $tabs->align is an array of column alignments (defaults to "center") +// $tabs->size is an array of column sizes +// $tabs->wrap is an array of "nowrap"s or nothing +// $tabs->highlight is an index (zero based) of "active" heading . +// $tabs->width is an percentage of the page (defualts to 80%) +// $tabs->cellpadding padding on each cell (defaults to 5) + + global $CFG, $THEME; + if (isset($tabs->names)) { foreach ($tabs->names as $key => $name) { if (!empty($tabs->urls[$key])) { - $url =$tabs->urls[$key]; - if ($tabs->highlight == $key) { - $tabcontents[$key] = "$name"; - } else { - $tabcontents[$key] = "$name"; - } + $url =$tabs->urls[$key]; + if ($tabs->highlight == $key) { + $tabcontents[$key] = "$name"; + } else { + $tabcontents[$key] = "$name"; + } } else { $tabcontents[$key] = "$name"; } @@ -1052,43 +1061,43 @@ function dialogue_print_tabbed_heading($tabs) { if (!empty($tabs->names)) { echo ""; - echo "". - "wwwroot/pix/spacer.gif\" alt=\"\">\n"; + echo "". + "wwwroot/pix/spacer.gif\" alt=\"\">\n"; foreach ($tabcontents as $key => $tab) { if (isset($align[$key])) { - $alignment = "align=\"$align[$key]\""; - } else { + $alignment = "align=\"$align[$key]\""; + } else { $alignment = "align=\"center\""; } if (isset($size[$key])) { $width = "width=\"$size[$key]\""; } else { - $width = ""; - } + $width = ""; + } if (isset($wrap[$key])) { - $wrapping = "no wrap"; - } else { + $wrapping = "no wrap"; + } else { $wrapping = ""; } - if ($key == $tabs->highlight) { - echo "cellheading2\">$tab\n"; - } else { - echo "cellheading\">$tab\n"; - } - echo "". - "wwwroot/pix/spacer.gif\" alt=\"\">\n"; + if ($key == $tabs->highlight) { + echo "cellheading2\">$tab\n"; + } else { + echo "cellheading\">$tab\n"; + } + echo "". + "wwwroot/pix/spacer.gif\" alt=\"\">\n"; } echo "\n"; } else { - echo "No names specified\n"; - } - // bottom stripe - $ncells = count($tabs->names)*2 +1; - $height = 2; - echo "cellheading2\">". - "wwwroot/pix/spacer.gif\" alt=\"\">\n"; + echo "No names specified\n"; + } + // bottom stripe + $ncells = count($tabs->names)*2 +1; + $height = 2; + echo "cellheading2\">". + "wwwroot/pix/spacer.gif\" alt=\"\">\n"; echo "\n"; - // print_simple_box_end(); + // print_simple_box_end(); return true; } @@ -1098,55 +1107,55 @@ function dialogue_print_tabbed_heading($tabs) { ////////////////////////////////////////////////////////////////////////////////////// function dialogue_show_conversation($dialogue, $conversation) { global $THEME, $USER; - - if (! $course = get_record("course", "id", $dialogue->course)) { + + if (! $course = get_record("course", "id", $dialogue->course)) { error("Course is misconfigured"); } if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { error("Course Module ID was incorrect"); } - - $timenow = time(); - print_simple_box_start("center"); - echo "
\n"; - - echo ""; - echo "\n"; + } + } + } + echo "
cellheading2\" valign=\"top\">\n"; - if ($conversation->userid == $USER->id) { - if (!$otheruser = get_record("user", "id", $conversation->recipientid)) { - error("User not found"); - } - } - else { - if (!$otheruser = get_record("user", "id", $conversation->userid)) { - error("User not found"); - } - } - // print_user_picture($user->id, $course->id, $user->picture); - echo "".get_string("dialoguewith", "dialogue", "$otheruser->firstname $otheruser->lastname"). + + $timenow = time(); + print_simple_box_start("center"); + echo "
\n"; + + echo ""; + echo ""; - echo ""; + echo ""; - if ($entries = get_records_select("dialogue_entries", "conversationid = $conversation->id", "id")) { - foreach ($entries as $entry) { - if ($entry->userid == $USER->id) { - echo "\n"; - } - else { - echo "\n"; + } + else { + echo "\n"; - } - } - } - echo "
cellheading2\" valign=\"top\">\n"; + if ($conversation->userid == $USER->id) { + if (!$otheruser = get_record("user", "id", $conversation->recipientid)) { + error("User not found"); + } + } + else { + if (!$otheruser = get_record("user", "id", $conversation->userid)) { + error("User not found"); + } + } + // print_user_picture($user->id, $course->id, $user->picture); + echo "".get_string("dialoguewith", "dialogue", "$otheruser->firstname $otheruser->lastname"). "cellheading2\" valign=\"top\">$conversation->subject 
cellheading2\" valign=\"top\">$conversation->subject 
\n"; - echo text_to_html("".get_string("onyouwrote", "dialogue", + if ($entries = get_records_select("dialogue_entries", "conversationid = $conversation->id", "id")) { + foreach ($entries as $entry) { + if ($entry->userid == $USER->id) { + echo "
\n"; + echo text_to_html("".get_string("onyouwrote", "dialogue", userdate($entry->timecreated)). - ":
".$entry->text); - echo "
body\">\n"; - echo text_to_html("".get_string("onwrote", "dialogue", + ":
".$entry->text); + echo "
body\">\n"; + echo text_to_html("".get_string("onwrote", "dialogue", userdate($entry->timecreated)." ".$otheruser->firstname).":
".$entry->text); - echo "

\n"; - print_simple_box_end(); - print_continue("view.php?id=$cm->id&pane=3"); + echo "

\n"; + print_simple_box_end(); + print_continue("view.php?id=$cm->id&pane=3"); } @@ -1154,29 +1163,29 @@ function dialogue_show_conversation($dialogue, $conversation) { function dialogue_show_other_conversations($dialogue, $conversation) { // prints the other CLOSED conversations for this pair of users global $THEME; - - if (! $course = get_record("course", "id", $dialogue->course)) { + + if (! $course = get_record("course", "id", $dialogue->course)) { error("Course is misconfigured"); } if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { error("Course Module ID was incorrect"); } - - if (!$user = get_record("user", "id", $conversation->userid)) { - error("User not found"); - } - if (!$otheruser = get_record("user", "id", $conversation->recipientid)) { - error("User not found"); - } - - if ($conversations = get_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND - ((userid = $user->id AND recipientid = $otheruser->id) OR (userid = $otheruser->id AND + + if (!$user = get_record("user", "id", $conversation->userid)) { + error("User not found"); + } + if (!$otheruser = get_record("user", "id", $conversation->recipientid)) { + error("User not found"); + } + + if ($conversations = get_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND + ((userid = $user->id AND recipientid = $otheruser->id) OR (userid = $otheruser->id AND recipientid = $user->id)) AND closed = 1", "timemodified DESC")) { - if (count($conversations) > 1) { - $timenow = time(); - foreach ($conversations as $otherconversation) { - if ($conversation->id != $otherconversation->id) { - // for this conversation work out which is the other user + if (count($conversations) > 1) { + $timenow = time(); + foreach ($conversations as $otherconversation) { + if ($conversation->id != $otherconversation->id) { + // for this conversation work out which is the other user if ($otherconversation->userid == $user->id) { if (!$otheruser = get_record("user", "id", $otherconversation->recipientid)) { error("Show other conversations: could not get user record"); @@ -1188,40 +1197,40 @@ function dialogue_show_other_conversations($dialogue, $conversation) { } } print_simple_box_start("center"); - echo "
\n"; - - echo ""; - echo "\n"; + } + } + } + + echo "
cellheading2\" VALIGN=TOP>\n"; - // print_user_picture($otheruser->id, $course->id, $otheruser->picture); - echo "".get_string("dialoguewith", "dialogue", + echo "
\n"; + + echo ""; + echo ""; echo ""; - if ($entries = get_records_select("dialogue_entries", + if ($entries = get_records_select("dialogue_entries", "conversationid = $otherconversation->id", "id")) { - foreach ($entries as $entry) { - if ($entry->userid == $user->id) { - echo "\n"; - } - else { - echo "\n"; + } + else { + echo "\n"; - } - } - } - - echo "
cellheading2\" VALIGN=TOP>\n"; + // print_user_picture($otheruser->id, $course->id, $otheruser->picture); + echo "".get_string("dialoguewith", "dialogue", "$otheruser->firstname $otheruser->lastname")."cellheading2\" valign=\"top\">$otherconversation->subject 
\n"; - echo text_to_html("".get_string("onyouwrote", "dialogue", + foreach ($entries as $entry) { + if ($entry->userid == $user->id) { + echo "
\n"; + echo text_to_html("".get_string("onyouwrote", "dialogue", userdate($entry->timecreated)).":
".$entry->text); - echo "
body\">\n"; - echo text_to_html("".get_string("onwrote", "dialogue", + echo "
body\">\n"; + echo text_to_html("".get_string("onwrote", "dialogue", userdate($entry->timecreated)." ".$otheruser->firstname). ":
".$entry->text); - echo "

\n"; - print_simple_box_end(); - } + echo "

\n"; + print_simple_box_end(); + } } - print_continue("view.php?id=$cm->id&pane=3"); + print_continue("view.php?id=$cm->id&pane=3"); } - } + } } diff --git a/mod/exercise/lib.php b/mod/exercise/lib.php index 08f8ae3e08..4d8cc22dda 100644 --- a/mod/exercise/lib.php +++ b/mod/exercise/lib.php @@ -8,29 +8,29 @@ $EXERCISE_TYPE = array (0 => get_string("notgraded", "exercise"), 1 => get_string("accumulative", "exercise"), 2 => get_string("errorbanded", "exercise"), 3 => get_string("criterion", "exercise"), - 4 => get_string("rubric", "exercise") ); + 4 => get_string("rubric", "exercise") ); $EXERCISE_SCALES = array( - 0 => array( 'name' => get_string("scaleyes", "exercise"), 'type' => 'radio', 'size' => 2, 'start' => get_string("yes"), 'end' => get_string("no")), - 1 => array( 'name' => get_string("scalepresent", "exercise"), 'type' => 'radio', 'size' => 2, 'start' => get_string("present", "exercise"), 'end' => get_string("absent", "exercise")), - 2 => array( 'name' => get_string("scalecorrect", "exercise"), 'type' => 'radio', 'size' => 2, 'start' => get_string("correct", "exercise"), 'end' => get_string("incorrect", "exercise")), - 3 => array( 'name' => get_string("scalegood3", "exercise"), 'type' => 'radio', 'size' => 3, 'start' => get_string("good", "exercise"), 'end' => get_string("poor", "exercise")), - 4 => array( 'name' => get_string("scaleexcellent4", "exercise"), 'type' => 'radio', 'size' => 4, 'start' => get_string("excellent", "exercise"), 'end' => get_string("verypoor", "exercise")), - 5 => array( 'name' => get_string("scaleexcellent5", "exercise"), 'type' => 'radio', 'size' => 5, 'start' => get_string("excellent", "exercise"), 'end' => get_string("verypoor", "exercise")), - 6 => array( 'name' => get_string("scaleexcellent7", "exercise"), 'type' => 'radio', 'size' => 7, 'start' => get_string("excellent", "exercise"), 'end' => get_string("verypoor", "exercise")), - 7 => array( 'name' => get_string("scale10", "exercise"), 'type' => 'selection', 'size' => 10), - 8 => array( 'name' => get_string("scale20", "exercise"), 'type' => 'selection', 'size' => 20), - 9 => array( 'name' => get_string("scale100", "exercise"), 'type' => 'selection', 'size' => 100)); + 0 => array( 'name' => get_string("scaleyes", "exercise"), 'type' => 'radio', 'size' => 2, 'start' => get_string("yes"), 'end' => get_string("no")), + 1 => array( 'name' => get_string("scalepresent", "exercise"), 'type' => 'radio', 'size' => 2, 'start' => get_string("present", "exercise"), 'end' => get_string("absent", "exercise")), + 2 => array( 'name' => get_string("scalecorrect", "exercise"), 'type' => 'radio', 'size' => 2, 'start' => get_string("correct", "exercise"), 'end' => get_string("incorrect", "exercise")), + 3 => array( 'name' => get_string("scalegood3", "exercise"), 'type' => 'radio', 'size' => 3, 'start' => get_string("good", "exercise"), 'end' => get_string("poor", "exercise")), + 4 => array( 'name' => get_string("scaleexcellent4", "exercise"), 'type' => 'radio', 'size' => 4, 'start' => get_string("excellent", "exercise"), 'end' => get_string("verypoor", "exercise")), + 5 => array( 'name' => get_string("scaleexcellent5", "exercise"), 'type' => 'radio', 'size' => 5, 'start' => get_string("excellent", "exercise"), 'end' => get_string("verypoor", "exercise")), + 6 => array( 'name' => get_string("scaleexcellent7", "exercise"), 'type' => 'radio', 'size' => 7, 'start' => get_string("excellent", "exercise"), 'end' => get_string("verypoor", "exercise")), + 7 => array( 'name' => get_string("scale10", "exercise"), 'type' => 'selection', 'size' => 10), + 8 => array( 'name' => get_string("scale20", "exercise"), 'type' => 'selection', 'size' => 20), + 9 => array( 'name' => get_string("scale100", "exercise"), 'type' => 'selection', 'size' => 100)); $EXERCISE_EWEIGHTS = array( 0 => -4.0, 1 => -2.0, 2 => -1.5, 3 => -1.0, 4 => -0.75, 5 => -0.5, 6 => -0.25, - 7 => 0.0, 8 => 0.25, 9 => 0.5, 10 => 0.75, 11=> 1.0, 12 => 1.5, 13=> 2.0, 14 => 4.0); + 7 => 0.0, 8 => 0.25, 9 => 0.5, 10 => 0.75, 11=> 1.0, 12 => 1.5, 13=> 2.0, 14 => 4.0); $EXERCISE_FWEIGHTS = array( 0 => 0, 1 => 0.1, 2 => 0.25, 3 => 0.5, 4 => 0.75, 5 => 1.0, 6 => 1.5, - 7 => 2.0, 8 => 3.0, 9 => 5.0, 10 => 7.5, 11=> 10.0); + 7 => 2.0, 8 => 3.0, 9 => 5.0, 10 => 7.5, 11=> 10.0); if (!defined("COMMENTSCALE")) { - define("COMMENTSCALE", 20); - } + define("COMMENTSCALE", 20); + } /*** Standard Moodle functions ****************** function exercise_add_instance($exercise) @@ -54,8 +54,8 @@ function exercise_add_instance($exercise) { $exercise->timemodified = time(); $exercise->deadline = make_timestamp($exercise->deadlineyear, - $exercise->deadlinemonth, $exercise->deadlineday, $exercise->deadlinehour, - $exercise->deadlineminute); + $exercise->deadlinemonth, $exercise->deadlineday, $exercise->deadlinehour, + $exercise->deadlineminute); return insert_record("exercise", $exercise); } @@ -90,13 +90,13 @@ function exercise_choose_from_menu ($options, $name, $selected="", $nothing="cho if ($value == $selected) { $output .= " SELECTED"; } - // stop zero label being replaced by array index value + // stop zero label being replaced by array index value // if ($label) { // $output .= ">$label\n"; // } else { // $output .= ">$value\n"; - // } - $output .= ">$label\n"; + // } + $output .= ">$label\n"; } } @@ -119,115 +119,115 @@ function exercise_cron () { $cutofftime = time() - $CFG->maxeditingtime; - // look for new assessments - if ($assessments = exercise_get_unmailed_assessments($cutofftime)) { + // look for new assessments + if ($assessments = exercise_get_unmailed_assessments($cutofftime)) { $timenow = time(); foreach ($assessments as $assessment) { - echo "Processing exercise assessment $assessment->id\n"; - if (! $submission = get_record("exercise_submissions", "id", "$assessment->submissionid")) { - 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; - } + echo "Processing exercise assessment $assessment->id\n"; + if (! $submission = get_record("exercise_submissions", "id", "$assessment->submissionid")) { + 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; - } - if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) { - echo "Could not find user $assessment->userid\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 - } - - $strexercises = get_string("modulenameplural", "exercise"); - $strexercise = get_string("modulename", "exercise"); - - // it's an assessment, tell the submission owner - $USER->lang = $submissionowner->lang; - $sendto = $submissionowner; - // "Your assignment \"$submission->title\" has been assessed by" - $msg = get_string("mail1", "exercise", $submission->title)." $assessmentowner->firstname $assessmentowner->lastname.\n"; - // "The comments and grade can be seen in the exercise assignment '$exercise->name' - $msg .= get_string("mail2", "exercise", $exercise->name)."\n\n"; - - $postsubject = "$course->shortname: $strexercises: $exercise->name"; - $posttext = "$course->shortname -> $strexercises -> $exercise->name\n"; - $posttext .= "---------------------------------------------------------------------\n"; - $posttext .= $msg; - // "You can see it in your exercise assignment" - $posttext .= get_string("mail3", "exercise").":\n"; - $posttext .= " $CFG->wwwroot/mod/exercise/view.php?id=$cm->id\n"; - $posttext .= "---------------------------------------------------------------------\n"; - if ($sendto->mailformat == 1) { // HTML - $posthtml = "

". - "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". - "wwwroot/mod/exercise/index.php?id=$course->id\">$strexercises ->". - "wwwroot/mod/exercise/view.php?id=$cm->id\">$exercise->name

"; - $posthtml .= "
"; - $posthtml .= "

$msg

"; - $posthtml .= "

".get_string("mail3", "exercise"). - " wwwroot/mod/exercise/view.php?id=$cm->id\">$exercise->name.


"; - } else { - $posthtml = ""; - } - - if (!$teacher = get_teacher($course->id)) { - echo "Error: can not find teacher for course $course->id!\n"; - } - - if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { - echo "Error: exercise cron: Could not send out mail for id $submission->id to user $sendto->id ($sendto->email)\n"; - } - if (! set_field("exercise_assessments", "mailed", "1", "id", "$assessment->id")) { - echo "Could not update the mailed field for id $assessment->id\n"; - } - } - } - - // look for new gradings - if ($assessments = exercise_get_unmailed_graded_assessments($cutofftime)) { + if (! $submissionowner = get_record("user", "id", "$submission->userid")) { + echo "Could not find user $submission->userid\n"; + continue; + } + if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) { + echo "Could not find user $assessment->userid\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 + } + + $strexercises = get_string("modulenameplural", "exercise"); + $strexercise = get_string("modulename", "exercise"); + + // it's an assessment, tell the submission owner + $USER->lang = $submissionowner->lang; + $sendto = $submissionowner; + // "Your assignment \"$submission->title\" has been assessed by" + $msg = get_string("mail1", "exercise", $submission->title)." $assessmentowner->firstname $assessmentowner->lastname.\n"; + // "The comments and grade can be seen in the exercise assignment '$exercise->name' + $msg .= get_string("mail2", "exercise", $exercise->name)."\n\n"; + + $postsubject = "$course->shortname: $strexercises: $exercise->name"; + $posttext = "$course->shortname -> $strexercises -> $exercise->name\n"; + $posttext .= "---------------------------------------------------------------------\n"; + $posttext .= $msg; + // "You can see it in your exercise assignment" + $posttext .= get_string("mail3", "exercise").":\n"; + $posttext .= " $CFG->wwwroot/mod/exercise/view.php?id=$cm->id\n"; + $posttext .= "---------------------------------------------------------------------\n"; + if ($sendto->mailformat == 1) { // HTML + $posthtml = "

". + "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". + "wwwroot/mod/exercise/index.php?id=$course->id\">$strexercises ->". + "wwwroot/mod/exercise/view.php?id=$cm->id\">$exercise->name

"; + $posthtml .= "
"; + $posthtml .= "

$msg

"; + $posthtml .= "

".get_string("mail3", "exercise"). + " wwwroot/mod/exercise/view.php?id=$cm->id\">$exercise->name.


"; + } else { + $posthtml = ""; + } + + if (!$teacher = get_teacher($course->id)) { + echo "Error: can not find teacher for course $course->id!\n"; + } + + if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { + echo "Error: exercise cron: Could not send out mail for id $submission->id to user $sendto->id ($sendto->email)\n"; + } + if (! set_field("exercise_assessments", "mailed", "1", "id", "$assessment->id")) { + echo "Could not update the mailed field for id $assessment->id\n"; + } + } + } + + // look for new gradings + if ($assessments = exercise_get_unmailed_graded_assessments($cutofftime)) { $timenow = time(); foreach ($assessments as $assessment) { echo "Processing exercise assessment $assessment->id (graded)\n"; - if (! $submission = get_record("exercise_submissions", "id", "$assessment->submissionid")) { + if (! $submission = get_record("exercise_submissions", "id", "$assessment->submissionid")) { 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 (! $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 (! $assessmentowner = get_record("user", "id", "$assessment->userid")) { + if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) { echo "Could not find user $assessment->userid\n"; continue; } @@ -239,39 +239,39 @@ function exercise_cron () { $strexercises = get_string("modulenameplural", "exercise"); $strexercise = get_string("modulename", "exercise"); - // it's a grading tell the assessment owner - $USER->lang = $assessmentowner->lang; - $sendto = $assessmentowner; - // Your assessment of the assignment \"$submission->title\" has by reviewed - $msg = get_string("mail6", "exercise", $submission->title).".\n"; - // The comments given by the $course->teacher can be seen in the exercise Assignment - $msg .= get_string("mail7", "exercise", $course->teacher)." '$exercise->name'.\n\n"; + // it's a grading tell the assessment owner + $USER->lang = $assessmentowner->lang; + $sendto = $assessmentowner; + // Your assessment of the assignment \"$submission->title\" has by reviewed + $msg = get_string("mail6", "exercise", $submission->title).".\n"; + // The comments given by the $course->teacher can be seen in the exercise Assignment + $msg .= get_string("mail7", "exercise", $course->teacher)." '$exercise->name'.\n\n"; - $postsubject = "$course->shortname: $strexercises: $exercise->name"; + $postsubject = "$course->shortname: $strexercises: $exercise->name"; $posttext = "$course->shortname -> $strexercises -> $exercise->name\n"; $posttext .= "---------------------------------------------------------------------\n"; $posttext .= $msg; - // "You can see it in your exercise assignment" - $posttext .= get_string("mail3", "exercise").":\n"; - $posttext .= " $CFG->wwwroot/mod/exercise/view.php?id=$cm->id\n"; + // "You can see it in your exercise assignment" + $posttext .= get_string("mail3", "exercise").":\n"; + $posttext .= " $CFG->wwwroot/mod/exercise/view.php?id=$cm->id\n"; $posttext .= "---------------------------------------------------------------------\n"; if ($sendto->mailformat == 1) { // HTML - $posthtml = "

". - "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". - "wwwroot/mod/exercise/index.php?id=$cm->id\">$strexercises ->". - "wwwroot/mod/exercise/view.php?a=$exercise->id\">$exercise->name

"; - $posthtml .= "
"; - $posthtml .= "

$msg

"; - $posthtml .= "

".get_string("mail3", "exercise"). - " wwwroot/mod/exercise/view.php?id=$cm->id\">$exercise->name.


"; + $posthtml = "

". + "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". + "wwwroot/mod/exercise/index.php?id=$cm->id\">$strexercises ->". + "wwwroot/mod/exercise/view.php?a=$exercise->id\">$exercise->name

"; + $posthtml .= "
"; + $posthtml .= "

$msg

"; + $posthtml .= "

".get_string("mail3", "exercise"). + " wwwroot/mod/exercise/view.php?id=$cm->id\">$exercise->name.


"; } else { $posthtml = ""; } - if (!$teacher = get_teacher($course->id)) { - echo "Error: can not find teacher for course $course->id!\n"; - } - + if (!$teacher = get_teacher($course->id)) { + echo "Error: can not find teacher for course $course->id!\n"; + } + if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { echo "Error: exercise cron: Could not send out mail for id $submission->id to user $sendto->id ($sendto->email)\n"; } @@ -293,8 +293,8 @@ function exercise_delete_instance($id) { if (! $exercise = get_record("exercise", "id", "$id")) { return false; } - - // delete all the associated records in the exercise tables, start positive... + + // delete all the associated records in the exercise tables, start positive... $result = true; if (! delete_records("exercise_grades", "exerciseid", "$exercise->id")) { @@ -329,45 +329,45 @@ function exercise_delete_instance($id) { function exercise_grades($exerciseid) { /// Must return an array of grades, indexed by user, and a max grade. global $EXERCISE_FWEIGHTS; - - if (!$exercise = get_record("exercise", "id", $exerciseid)) { - error("Exercise record not found"); - } - if (! $course = get_record("course", "id", $exercise->course)) { + + 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] + - $EXERCISE_FWEIGHTS[$exercise->teacherweight])); - // how to handle multiple submissions? - if ($exercise->usemaximum) { - // first get the teacher's grade for the best submission - if ($bestgrades = exercise_get_best_submission_grades($exercise)) { - foreach ($bestgrades as $grade) { - $usergrade[$grade->userid] = $grade->grade * - $EXERCISE_FWEIGHTS[$exercise->teacherweight] * $scaling; - } - } - } - else { // use mean values - if ($meangrades = exercise_get_mean_submission_grades($exercise)) { - foreach ($meangrades as $grade) { - $usergrade[$grade->userid] = $grade->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($usergrade[$assessment->userid])) { - $usergrade[$assessment->userid] += $assessment->gradinggrade * - $EXERCISE_FWEIGHTS[$exercise->gradingweight] * $scaling * 100.0 / COMMENTSCALE; - } - } - } + // calculate scaling factor + $scaling = $exercise->grade / (100.0 * ($EXERCISE_FWEIGHTS[$exercise->gradingweight] + + $EXERCISE_FWEIGHTS[$exercise->teacherweight])); + // how to handle multiple submissions? + if ($exercise->usemaximum) { + // first get the teacher's grade for the best submission + if ($bestgrades = exercise_get_best_submission_grades($exercise)) { + foreach ($bestgrades as $grade) { + $usergrade[$grade->userid] = $grade->grade * + $EXERCISE_FWEIGHTS[$exercise->teacherweight] * $scaling; + } + } + } + else { // use mean values + if ($meangrades = exercise_get_mean_submission_grades($exercise)) { + foreach ($meangrades as $grade) { + $usergrade[$grade->userid] = $grade->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($usergrade[$assessment->userid])) { + $usergrade[$assessment->userid] += $assessment->gradinggrade * + $EXERCISE_FWEIGHTS[$exercise->gradingweight] * $scaling * 100.0 / COMMENTSCALE; + } + } + } // tidy the numbers and set up the return array if (isset($usergrade)) { foreach ($usergrade as $userid => $g) { @@ -384,111 +384,111 @@ global $EXERCISE_FWEIGHTS; function exercise_print_recent_activity($course, $isteacher, $timestart) { global $CFG; - // have a look for new submissions (only show to teachers) + // have a look for new submissions (only show to teachers) $submitcontent = false; - if ($isteacher) { - if ($logs = exercise_get_submit_logs($course, $timestart)) { - // got some, see if any belong to a visible module - foreach ($logs as $log) { - // Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->exerciseid; - //Obtain the visible property from the instance - if (instance_is_visible("exercise",$tempmod)) { - $submitcontent = true; - break; - } - } - // if we got some "live" ones then output them - if ($submitcontent) { - $strftimerecent = get_string("strftimerecent"); - print_headline(get_string("exercisesubmissions", "exercise").":"); - foreach ($logs as $log) { - //Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->exerciseid; - //Obtain the visible property from the instance - if (instance_is_visible("exercise",$tempmod)) { - $date = userdate($log->time, $strftimerecent); - echo "

$date - $log->firstname $log->lastname
"; - echo "\"wwwroot/mod/exercise/$log->url\">"; - echo "$log->name"; - echo "\"

"; - } - } - } - } - } - - // have a look for new assessment gradings for this user + if ($isteacher) { + if ($logs = exercise_get_submit_logs($course, $timestart)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->exerciseid; + //Obtain the visible property from the instance + if (instance_is_visible("exercise",$tempmod)) { + $submitcontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($submitcontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("exercisesubmissions", "exercise").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->exerciseid; + //Obtain the visible property from the instance + if (instance_is_visible("exercise",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + echo "

$date - $log->firstname $log->lastname
"; + echo "\"wwwroot/mod/exercise/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } + } + + // have a look for new assessment gradings for this user $gradecontent = false; - if ($logs = exercise_get_grade_logs($course, $timestart)) { - // got some, see if any belong to a visible module - foreach ($logs as $log) { - // Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->exerciseid; - //Obtain the visible property from the instance - if (instance_is_visible("exercise",$tempmod)) { - $gradecontent = true; - break; - } - } - // if we got some "live" ones then output them - if ($gradecontent) { - $strftimerecent = get_string("strftimerecent"); - print_headline(get_string("exercisefeedback", "exercise").":"); - foreach ($logs as $log) { - //Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->exerciseid; - //Obtain the visible property from the instance - if (instance_is_visible("exercise",$tempmod)) { - $date = userdate($log->time, $strftimerecent); - echo "

$date - $log->firstname $log->lastname
"; - echo "\"wwwroot/mod/exercise/$log->url\">"; - echo "$log->name"; - echo "\"

"; - } - } - } - } - - // have a look for new assessments for this user + if ($logs = exercise_get_grade_logs($course, $timestart)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->exerciseid; + //Obtain the visible property from the instance + if (instance_is_visible("exercise",$tempmod)) { + $gradecontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($gradecontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("exercisefeedback", "exercise").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->exerciseid; + //Obtain the visible property from the instance + if (instance_is_visible("exercise",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + echo "

$date - $log->firstname $log->lastname
"; + echo "\"wwwroot/mod/exercise/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } + + // have a look for new assessments for this user $assesscontent = false; - if (!$isteacher) { // teachers only need to see submissions - if ($logs = exercise_get_assess_logs($course, $timestart)) { - // got some, see if any belong to a visible module - foreach ($logs as $log) { - // Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->exerciseid; - //Obtain the visible property from the instance - if (instance_is_visible("exercise",$tempmod)) { - $assesscontent = true; - break; - } - } - // if we got some "live" ones then output them - if ($assesscontent) { - $strftimerecent = get_string("strftimerecent"); - print_headline(get_string("exerciseassessments", "exercise").":"); - foreach ($logs as $log) { - //Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->exerciseid; - //Obtain the visible property from the instance - if (instance_is_visible("exercise",$tempmod)) { - $date = userdate($log->time, $strftimerecent); - echo "

$date - $log->firstname $log->lastname
"; - echo "\"wwwroot/mod/exercise/$log->url\">"; - echo "$log->name"; - echo "\"

"; - } - } - } - } - } + if (!$isteacher) { // teachers only need to see submissions + if ($logs = exercise_get_assess_logs($course, $timestart)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->exerciseid; + //Obtain the visible property from the instance + if (instance_is_visible("exercise",$tempmod)) { + $assesscontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($assesscontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("exerciseassessments", "exercise").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->exerciseid; + //Obtain the visible property from the instance + if (instance_is_visible("exercise",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + echo "

$date - $log->firstname $log->lastname
"; + echo "\"wwwroot/mod/exercise/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } + } return $submitcontent or $gradecontent or $assesscontent; } @@ -502,8 +502,8 @@ function exercise_update_instance($exercise) { $exercise->timemodified = time(); $exercise->deadline = make_timestamp($exercise->deadlineyear, - $exercise->deadlinemonth, $exercise->deadlineday, $exercise->deadlinehour, - $exercise->deadlineminute); + $exercise->deadlinemonth, $exercise->deadlineday, $exercise->deadlinehour, + $exercise->deadlineminute); $exercise->id = $exercise->instance; @@ -515,30 +515,30 @@ function exercise_update_instance($exercise) { function exercise_user_complete($course, $user, $mod, $exercise) { if ($submissions = exercise_get_user_submissions($exercise, $user)) { print_simple_box_start(); - $table->head = array (get_string("submission", "exercise"), get_string("submitted", "exercise"), - get_string("assessed", "exercise"), get_string("grade")); - $table->width = "100%"; - $table->align = array ("left", "left", "left", "center"); - $table->size = array ("*", "*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - foreach ($submissions as $submission) { - if ($assessments = exercise_get_assessments($submission)) { - // should only be one but we'll loop anyway - foreach ($assessments as $assessment) { - $table->data[] = array(exercise_print_submission_title($exercise, $submission), + $table->head = array (get_string("submission", "exercise"), get_string("submitted", "exercise"), + get_string("assessed", "exercise"), get_string("grade")); + $table->width = "100%"; + $table->align = array ("left", "left", "left", "center"); + $table->size = array ("*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + foreach ($submissions as $submission) { + if ($assessments = exercise_get_assessments($submission)) { + // should only be one but we'll loop anyway + foreach ($assessments as $assessment) { + $table->data[] = array(exercise_print_submission_title($exercise, $submission), userdate($submission->timecreated), userdate($assessment->timecreated), $assessment->grade * $exercise->grade / 100.0); - } - } else { + } + } else { // submission not yet assessed (by teacher) - $table->data[] = array(exercise_print_submission_title($exercise, $submission), + $table->data[] = array(exercise_print_submission_title($exercise, $submission), userdate($submission->timecreated), get_string("notassessedyet", "exercise"), 0); } } - print_table($table); - print_simple_box_end(); + print_table($table); + print_simple_box_end(); } else { print_string("nosubmissions", "exercise"); } @@ -548,11 +548,11 @@ function exercise_user_complete($course, $user, $mod, $exercise) { /*******************************************************************/ function exercise_user_outline($course, $user, $mod, $exercise) { if ($submissions = exercise_get_user_submissions($exercise, $user)) { - $result->info = count($submissions)." ".get_string("submissions", "exercise"); - foreach ($submissions as $submission) { // the first one is the most recent one - $result->time = $submission->timecreated; - break; - } + $result->info = count($submissions)." ".get_string("submissions", "exercise"); + foreach ($submissions as $submission) { // the first one is the most recent one + $result->time = $submission->timecreated; + break; + } return $result; } return NULL; @@ -664,47 +664,47 @@ function exercise_test_user_assessments($exercise, $user) { /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_copy_assessment($assessment, $submission, $withfeedback = false) { - // adds a copy of the given assessment for the submission specified to the exercise_assessemnts table. - // The grades and optionally the comments are added to the exercise_grades table. Returns the new - // assessment object - global $USER; - + // adds a copy of the given assessment for the submission specified to the exercise_assessemnts table. + // The grades and optionally the comments are added to the exercise_grades table. Returns the new + // assessment object + global $USER; + $yearfromnow = time() + 365 * 86400; - $newassessment->exerciseid = $assessment->exerciseid; - $newassessment->submissionid = $submission->id; - $newassessment->userid = $USER->id; - $newassessment->timecreated = $yearfromnow; - $newassessment->timegraded = 0; - $newassessment->grade = $assessment->grade; - if ($withfeedback) { - $newassessment->generalcomment = addslashes($assessment->generalcomment); - $newassessment->teachercomment = addslashes($assessment->teachercomment); - } - if (!$newassessment->id = insert_record("exercise_assessments", $newassessment)) { - error("Copy Assessment: Could not insert exercise assessment!"); - } - - if ($grades = get_records("exercise_grades", "assessmentid", $assessment->id)) { - foreach ($grades as $grade) { + $newassessment->exerciseid = $assessment->exerciseid; + $newassessment->submissionid = $submission->id; + $newassessment->userid = $USER->id; + $newassessment->timecreated = $yearfromnow; + $newassessment->timegraded = 0; + $newassessment->grade = $assessment->grade; + if ($withfeedback) { + $newassessment->generalcomment = addslashes($assessment->generalcomment); + $newassessment->teachercomment = addslashes($assessment->teachercomment); + } + if (!$newassessment->id = insert_record("exercise_assessments", $newassessment)) { + error("Copy Assessment: Could not insert exercise assessment!"); + } + + if ($grades = get_records("exercise_grades", "assessmentid", $assessment->id)) { + foreach ($grades as $grade) { unset($grade->id); // clear id, insert record now seems to believe it! if (!$withfeedback) { - $grade->feedback = ''; - } + $grade->feedback = ''; + } else { $grade->feedback = addslashes($grade->feedback); // $grade->feedback = $grade->feedback; } - $grade->assessmentid = $newassessment->id; - if (!$grade->id = insert_record("exercise_grades", $grade)) { - error("Copy Assessment: Could not insert exercise grade!"); - } - } - } - if ($withfeedback) { + $grade->assessmentid = $newassessment->id; + if (!$grade->id = insert_record("exercise_grades", $grade)) { + error("Copy Assessment: Could not insert exercise grade!"); + } + } + } + if ($withfeedback) { // remove the slashes from comments as the new assessment record is used // in assessments and in lib - $newassessment->generalcomment = stripslashes($assessment->generalcomment); - $newassessment->teachercomment = stripslashes($assessment->teachercomment); + $newassessment->generalcomment = stripslashes($assessment->generalcomment); + $newassessment->teachercomment = stripslashes($assessment->teachercomment); } return $newassessment; @@ -714,232 +714,232 @@ function exercise_copy_assessment($assessment, $submission, $withfeedback = fals /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_all_submissions_for_assessment($exercise, $user) { - // looks at all submissions and deducts the number which has been assessed by this user - $n = 0; - if ($submissions = get_records_select("exercise_submissions", "exerciseid = $exercise->id AND timecreated > 0")) { - $n =count($submissions); - foreach ($submissions as $submission) { - $n -= count_records("exercise_assessments", "submissionid", $submission->id, "userid", $user->id); - } - } - return $n; - } + // looks at all submissions and deducts the number which has been assessed by this user + $n = 0; + if ($submissions = get_records_select("exercise_submissions", "exerciseid = $exercise->id AND timecreated > 0")) { + $n =count($submissions); + foreach ($submissions as $submission) { + $n -= count_records("exercise_assessments", "submissionid", $submission->id, "userid", $user->id); + } + } + return $n; + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_assessments($submission) { - // Return the (cold) assessments for this submission, - global $CFG; - - $timethen = time() - $CFG->maxeditingtime; + // Return the (cold) assessments for this submission, + global $CFG; + + $timethen = time() - $CFG->maxeditingtime; return count_records_select("exercise_assessments", "submissionid = $submission->id AND - timecreated < $timethen"); + timecreated < $timethen"); } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_assessments_by_teacher($exercise, $teacher) { - // Return the number of assessments done by a teacher - + // Return the number of assessments done by a teacher + return count_records_select("exercise_assessments", "exerciseid = $exercise->id AND - userid = $teacher->id"); + userid = $teacher->id"); } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_student_submissions($exercise) { - global $CFG; - - return count_records_sql("SELECT count(*) FROM {$CFG->prefix}exercise_submissions s, {$CFG->prefix}user_students u - WHERE u.course = $exercise->course + global $CFG; + + return count_records_sql("SELECT count(*) FROM {$CFG->prefix}exercise_submissions s, {$CFG->prefix}user_students u + WHERE u.course = $exercise->course AND s.userid = u.userid AND s.exerciseid = $exercise->id - AND timecreated > 0"); - } + AND timecreated > 0"); + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_teacher_assessments($exercise, $user) { - // returns the number of assessments made by teachers on user's submissions - - $n = 0; - if ($submissions = exercise_get_user_submissions($exercise, $user)) { - foreach ($submissions as $submission) { - if ($assessments = exercise_get_assessments($submission)) { - foreach ($assessments as $assessment) { - // count only teacher assessments - if (isteacher($exercise->course, $assessment->userid)) { - $n++; - } - } - } - } - } - return $n; - } + // returns the number of assessments made by teachers on user's submissions + + $n = 0; + if ($submissions = exercise_get_user_submissions($exercise, $user)) { + foreach ($submissions as $submission) { + if ($assessments = exercise_get_assessments($submission)) { + foreach ($assessments as $assessment) { + // count only teacher assessments + if (isteacher($exercise->course, $assessment->userid)) { + $n++; + } + } + } + } + } + return $n; + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_teacher_submissions($exercise) { - - return count_records("exercise_submissions", "isexercise", 1, "exerciseid", $exercise->id); - } + + return count_records("exercise_submissions", "isexercise", 1, "exerciseid", $exercise->id); + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_teacher_submissions_for_assessment($exercise, $user) { - $n = 0; - if ($submissions = exercise_get_teacher_submissions($exercise)) { - $n =count($submissions); - foreach ($submissions as $submission) { - $n -= count_records("exercise_assessments", "submissionid", $submission->id, "userid", $user->id); - } - } - return $n; - } + $n = 0; + if ($submissions = exercise_get_teacher_submissions($exercise)) { + $n =count($submissions); + foreach ($submissions as $submission) { + $n -= count_records("exercise_assessments", "submissionid", $submission->id, "userid", $user->id); + } + } + return $n; + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_unassessed_student_submissions($exercise) { // returns the number of students submissions which have not been assessed by a teacher - global $CFG; - + global $CFG; + if (! $course = get_record("course", "id", $exercise->course)) { error("Course is misconfigured"); } - $timenow = time(); - $n = 0; - if ($submissions = exercise_get_student_submissions($exercise)) { - foreach ($submissions as $submission) { - // only look at "cold" submissions - if ($submission->timecreated < $timenow - $CFG->maxeditingtime) { - $teacherassessed = false; - if ($assessments = exercise_get_assessments($submission)) { - foreach ($assessments as $assessment) { - // exercise_get_assessments only returns "cold" assessments, look for one made by a teacher - if (isteacher($course->id, $assessment->userid)) { - $teacherassessed = true; - break; // no need to look further - } - } - } - if (!$teacherassessed) { - $n++; - } - } - } - } - return $n; + $timenow = time(); + $n = 0; + if ($submissions = exercise_get_student_submissions($exercise)) { + foreach ($submissions as $submission) { + // only look at "cold" submissions + if ($submission->timecreated < $timenow - $CFG->maxeditingtime) { + $teacherassessed = false; + if ($assessments = exercise_get_assessments($submission)) { + foreach ($assessments as $assessment) { + // exercise_get_assessments only returns "cold" assessments, look for one made by a teacher + if (isteacher($course->id, $assessment->userid)) { + $teacherassessed = true; + break; // no need to look further + } + } + } + if (!$teacherassessed) { + $n++; + } + } + } + } + return $n; } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_ungraded_assessments_student($exercise) { - // function returns the number of ungraded assessments by students of STUDENT submissions + // function returns the number of ungraded assessments by students of STUDENT submissions $n = 0; - if ($submissions = exercise_get_student_submissions($exercise)) { - foreach ($submissions as $submission) { - if ($assessments = exercise_get_assessments($submission)) { - foreach ($assessments as $assessment) { - if ($assessment->timegraded == 0) { - // ignore teacher assessments - if (!isteacher($exercise->course, $assessment->userid)) { - $n++; - } - } - } - } - } - } - return $n; - } + if ($submissions = exercise_get_student_submissions($exercise)) { + foreach ($submissions as $submission) { + if ($assessments = exercise_get_assessments($submission)) { + foreach ($assessments as $assessment) { + if ($assessment->timegraded == 0) { + // ignore teacher assessments + if (!isteacher($exercise->course, $assessment->userid)) { + $n++; + } + } + } + } + } + } + return $n; + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_ungraded_assessments_teacher($exercise) { - // function returns the number of ungraded assessments by students of TEACHER submissions - global $CFG; - - $timenow = time(); - $n = 0; - if ($submissions = exercise_get_teacher_submissions($exercise)) { - foreach ($submissions as $submission) { - if ($assessments = exercise_get_assessments($submission)) { - foreach ($assessments as $assessment) { - if ($assessment->timegraded == 0) { - // ignore teacher assessments - if (!isteacher($exercise->course, $assessment->userid)) { - // must have created a little time ago - if (($timenow - $assessment->timecreated) > $CFG->maxeditingtime) { - $n++; - } - } - } - } - } - } - } - return $n; - } + // function returns the number of ungraded assessments by students of TEACHER submissions + global $CFG; + + $timenow = time(); + $n = 0; + if ($submissions = exercise_get_teacher_submissions($exercise)) { + foreach ($submissions as $submission) { + if ($assessments = exercise_get_assessments($submission)) { + foreach ($assessments as $assessment) { + if ($assessment->timegraded == 0) { + // ignore teacher assessments + if (!isteacher($exercise->course, $assessment->userid)) { + // must have created a little time ago + if (($timenow - $assessment->timecreated) > $CFG->maxeditingtime) { + $n++; + } + } + } + } + } + } + } + return $n; + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_user_assessments($exercise, $user, $stype = "all") { - // returns the number of assessments allocated/made by a user, all of them, or just those for the student or teacher submissions - // the student's self assessments are included in the count - // the maxeditingtime is NOT taken into account here also allocated assessments which have not yet - // been done are counted as well - - $n = 0; - if ($assessments = exercise_get_user_assessments($exercise, $user)) { - foreach ($assessments as $assessment) { - switch ($stype) { - case "all" : - $n++; - break; - case "student" : - $submission = get_record("exercise_submissions", "id", $assessment->submissionid); - if (isstudent($exercise->course, $submission->userid)) { - $n++; - } - break; - case "teacher" : - $submission = get_record("exercise_submissions", "id", $assessment->submissionid); - if (isteacher($exercise->course, $submission->userid)) { - $n++; - } - break; - } - } - } - return $n; - } + // returns the number of assessments allocated/made by a user, all of them, or just those for the student or teacher submissions + // the student's self assessments are included in the count + // the maxeditingtime is NOT taken into account here also allocated assessments which have not yet + // been done are counted as well + + $n = 0; + if ($assessments = exercise_get_user_assessments($exercise, $user)) { + foreach ($assessments as $assessment) { + switch ($stype) { + case "all" : + $n++; + break; + case "student" : + $submission = get_record("exercise_submissions", "id", $assessment->submissionid); + if (isstudent($exercise->course, $submission->userid)) { + $n++; + } + break; + case "teacher" : + $submission = get_record("exercise_submissions", "id", $assessment->submissionid); + if (isteacher($exercise->course, $submission->userid)) { + $n++; + } + break; + } + } + } + return $n; + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_user_assessments_done($exercise, $user) { - // returns the number of assessments actually done by a user - // the student's self assessments are included in the count - // the maxeditingtime is NOT taken into account here - - $n = 0; - $timenow = time(); - if ($assessments = exercise_get_user_assessments($exercise, $user)) { - foreach ($assessments as $assessment) { - if ($assessment->timecreated < $timenow) { - $n++; - } - } - } - return $n; + // returns the number of assessments actually done by a user + // the student's self assessments are included in the count + // the maxeditingtime is NOT taken into account here + + $n = 0; + $timenow = time(); + if ($assessments = exercise_get_user_assessments($exercise, $user)) { + foreach ($assessments as $assessment) { + if ($assessment->timecreated < $timenow) { + $n++; + } + } + } + return $n; } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_count_user_submissions($exercise, $user) { - // returns the number of submissions make by this user - return count_records("exercise_submissions", "exerciseid", $exercise->id, "userid", $user->id); + // returns the number of submissions make by this user + return count_records("exercise_submissions", "exerciseid", $exercise->id, "userid", $user->id); } @@ -947,18 +947,18 @@ function exercise_count_user_submissions($exercise, $user) { function exercise_delete_submitted_files($exercise, $submission) { // Deletes the files in the exercise area for this submission - if ($basedir = exercise_file_area($exercise, $submission)) { - if ($files = get_directory_list($basedir)) { - foreach ($files as $file) { - if (unlink("$basedir/$file")) { - notify("Existing file '$file' has been deleted!"); - } - else { - notify("Attempt to delete file $basedir/$file has failed!"); - } - } - } - } + if ($basedir = exercise_file_area($exercise, $submission)) { + if ($files = get_directory_list($basedir)) { + foreach ($files as $file) { + if (unlink("$basedir/$file")) { + notify("Existing file '$file' has been deleted!"); + } + else { + notify("Attempt to delete file $basedir/$file has failed!"); + } + } + } + } } @@ -968,22 +968,22 @@ function exercise_delete_user_files($exercise, $user, $exception) { // EXCEPT for any file named $exception if (!$submissions = exercise_get_submissions($exercise, $user)) { - notify("No submissions!"); - return; - } - foreach ($submissions as $submission) { - if ($basedir = exercise_file_area($exercise, $submission)) { - if ($files = get_directory_list($basedir)) { - foreach ($files as $file) { - if ($file != $exception) { - unlink("$basedir/$file"); - notify("Existing file '$file' has been deleted!"); - } - } - } - } - } - } + notify("No submissions!"); + return; + } + foreach ($submissions as $submission) { + if ($basedir = exercise_file_area($exercise, $submission)) { + if ($files = get_directory_list($basedir)) { + foreach ($files as $file) { + if ($file != $exception) { + unlink("$basedir/$file"); + notify("Existing file '$file' has been deleted!"); + } + } + } + } + } + } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1003,92 +1003,97 @@ function exercise_file_area_name($exercise, $submission) { /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_assess_logs($course, $timestart) { - // get the "assess" entries for this user and add the first and last names... - global $CFG, $USER; - - $timethen = time() - $CFG->maxeditingtime; + // get the "assess" entries for this user and add the first and last names... + global $CFG, $USER; + if (empty($USER->id)) { + return false; + } + $timethen = time() - $CFG->maxeditingtime; return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, a.exerciseid, e.name FROM {$CFG->prefix}log l, - {$CFG->prefix}exercise e, - {$CFG->prefix}exercise_submissions s, - {$CFG->prefix}exercise_assessments a, - {$CFG->prefix}user u + {$CFG->prefix}exercise e, + {$CFG->prefix}exercise_submissions s, + {$CFG->prefix}exercise_assessments a, + {$CFG->prefix}user u WHERE l.time > $timestart AND l.time < $timethen - AND l.course = $course->id AND l.module = 'exercise' AND l.action = 'assess' - AND a.id = l.info AND s.id = a.submissionid AND s.userid = $USER->id - AND u.id = a.userid AND e.id = a.exerciseid"); + AND l.course = $course->id AND l.module = 'exercise' AND l.action = 'assess' + AND a.id = l.info AND s.id = a.submissionid AND s.userid = $USER->id + AND u.id = a.userid AND e.id = a.exerciseid"); } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_assessments($submission) { - // Return all assessments for this submission provided they are after the editing time, + // Return all assessments for this submission provided they are after the editing time, // ordered oldest first, newest last - global $CFG; + global $CFG; - $timenow = time(); + $timenow = time(); return get_records_select("exercise_assessments", "(submissionid = $submission->id) AND - (timecreated < $timenow - $CFG->maxeditingtime)", "timecreated ASC"); + (timecreated < $timenow - $CFG->maxeditingtime)", "timecreated ASC"); } /////////////////////////////////////////////////////////////////////////////////////////////// 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 + 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"); + 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 u.userid, MAX(a.grade) grade FROM + global $CFG; + + return get_records_sql("SELECT DISTINCT u.userid, MAX(a.grade) grade FROM {$CFG->prefix}exercise_submissions s, - {$CFG->prefix}exercise_assessments a, {$CFG->prefix}user_students u + {$CFG->prefix}exercise_assessments a, {$CFG->prefix}user_students u WHERE u.course = $exercise->course AND s.userid = u.userid - AND s.exerciseid = $exercise->id + AND s.exerciseid = $exercise->id AND s.late = 0 - AND a.submissionid = s.id - GROUP BY u.userid"); + AND a.submissionid = s.id + GROUP BY u.userid"); } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_grade_logs($course, $timestart) { - // get the "grade" entries for this user and add the first and last names... - global $CFG, $USER; - - $timethen = time() - $CFG->maxeditingtime; + // get the "grade" entries for this user and add the first and last names... + global $CFG, $USER; + if (empty($USER->id)) { + return false; + } + + $timethen = time() - $CFG->maxeditingtime; return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, a.exerciseid, e.name FROM {$CFG->prefix}log l, - {$CFG->prefix}exercise e, - {$CFG->prefix}exercise_submissions s, - {$CFG->prefix}exercise_assessments a, - {$CFG->prefix}user u + {$CFG->prefix}exercise e, + {$CFG->prefix}exercise_submissions s, + {$CFG->prefix}exercise_assessments a, + {$CFG->prefix}user u WHERE l.time > $timestart AND l.time < $timethen - AND l.course = $course->id AND l.module = 'exercise' AND l.action = 'grade' - AND a.id = l.info AND s.id = a.submissionid AND a.userid = $USER->id - AND u.id = s.userid AND e.id = a.exerciseid"); + AND l.course = $course->id AND l.module = 'exercise' AND l.action = 'grade' + AND a.id = l.info AND s.id = a.submissionid AND a.userid = $USER->id + AND u.id = s.userid AND e.id = a.exerciseid"); } /////////////////////////////////////////////////////////////////////////////////////////////// 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 + 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"); + GROUP BY a.submissionid"); } @@ -1096,19 +1101,19 @@ function exercise_get_mean_grade($submission) { function exercise_get_mean_submission_grades($exercise) { // Returns the mean grades of students' submissions // ignores hot assessments - global $CFG; - + global $CFG; + $timenow = time(); - $grades = get_records_sql("SELECT DISTINCT u.userid, AVG(a.grade) grade FROM + $grades = get_records_sql("SELECT DISTINCT u.userid, AVG(a.grade) grade FROM {$CFG->prefix}exercise_submissions s, - {$CFG->prefix}exercise_assessments a, {$CFG->prefix}user_students u + {$CFG->prefix}exercise_assessments a, {$CFG->prefix}user_students u WHERE u.course = $exercise->course AND s.userid = u.userid - AND s.exerciseid = $exercise->id + AND s.exerciseid = $exercise->id AND s.late = 0 - AND a.submissionid = s.id + AND a.submissionid = s.id AND a.timecreated < $timenow - GROUP BY u.userid"); + GROUP BY u.userid"); return $grades; } @@ -1116,7 +1121,7 @@ function exercise_get_mean_submission_grades($exercise) { /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_student_submission($exercise, $user) { // Return a submission for a particular user - global $CFG; + global $CFG; $submission = get_record("exercise_submissions", "exerciseid", $exercise->id, "userid", $user->id); if (!empty($submission->timecreated)) { @@ -1130,176 +1135,176 @@ function exercise_get_student_submission($exercise, $user) { function exercise_get_student_submissions($exercise, $order = "") { // Return all ENROLLED student submissions // if order can grade|title|name|nothing, nothing is oldest first, youngest last - global $CFG; - - if ($order == "grade") { - // allow for multiple assessments of submissions (coming from different teachers) - return get_records_sql("SELECT s.*, AVG(a.grade) grade FROM {$CFG->prefix}exercise_submissions s, - {$CFG->prefix}user_students u, {$CFG->prefix}exercise_assessments a - WHERE u.course = $exercise->course - AND s.userid = u.userid - AND s.exerciseid = $exercise->id - AND a.submissionid = s.id - GROUP BY s.id - ORDER BY a.grade DESC"); - } - - if ($order == "title") { - $order = "s.title"; - } elseif ($order == "name") { - $order = "n.firstname, n.lastname, s.timecreated DESC"; - } else { + global $CFG; + + if ($order == "grade") { + // allow for multiple assessments of submissions (coming from different teachers) + return get_records_sql("SELECT s.*, AVG(a.grade) grade FROM {$CFG->prefix}exercise_submissions s, + {$CFG->prefix}user_students u, {$CFG->prefix}exercise_assessments a + WHERE u.course = $exercise->course + AND s.userid = u.userid + AND s.exerciseid = $exercise->id + AND a.submissionid = s.id + GROUP BY s.id + ORDER BY a.grade DESC"); + } + + if ($order == "title") { + $order = "s.title"; + } elseif ($order == "name") { + $order = "n.firstname, n.lastname, s.timecreated DESC"; + } else { $order = "s.timecreated"; } - return get_records_sql("SELECT s.* FROM {$CFG->prefix}exercise_submissions s, + return get_records_sql("SELECT s.* FROM {$CFG->prefix}exercise_submissions s, {$CFG->prefix}user_students u, {$CFG->prefix}user n WHERE u.course = $exercise->course AND s.userid = u.userid AND n.id = u.userid - AND s.exerciseid = $exercise->id - ORDER BY $order"); + AND s.exerciseid = $exercise->id + ORDER BY $order"); } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_submission_assessment($submission, $user) { - // Return the user's assessment for this submission - return get_record("exercise_assessments", "submissionid", $submission->id, "userid", $user->id); + // Return the user's assessment for this submission + return get_record("exercise_assessments", "submissionid", $submission->id, "userid", $user->id); } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_submit_logs($course, $timestart) { - // get the "submit" entries and add the first and last names... - global $CFG, $USER; - - $timethen = time() - $CFG->maxeditingtime; + // get the "submit" entries and add the first and last names... + global $CFG, $USER; + + $timethen = time() - $CFG->maxeditingtime; return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, l.info exerciseid, e.name FROM {$CFG->prefix}log l, - {$CFG->prefix}exercise e, - {$CFG->prefix}user u + {$CFG->prefix}exercise e, + {$CFG->prefix}user u WHERE l.time > $timestart AND l.time < $timethen - AND l.course = $course->id AND l.module = 'exercise' - AND l.action = 'submit' - AND e.id = l.info - AND u.id = l.userid"); + AND l.course = $course->id AND l.module = 'exercise' + AND l.action = 'submit' + AND e.id = l.info + AND u.id = l.userid"); } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_teacher_submission_assessments($exercise) { // Return all assessments on the teacher submissions, order by youngest first, oldest last - global $CFG; - + global $CFG; + return get_records_sql("SELECT a.* FROM {$CFG->prefix}exercise_submissions s, {$CFG->prefix}exercise_assessments a WHERE s.isexercise = 1 AND s.exerciseid = $exercise->id - AND a.submissionid = s.id - ORDER BY a.timecreated DESC"); + AND a.submissionid = s.id + ORDER BY a.timecreated DESC"); } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_teacher_submissions($exercise) { // Return all teacher submissions, ordered by title - global $CFG; - - return get_records_sql("SELECT s.* FROM {$CFG->prefix}exercise_submissions s - WHERE s.isexercise = 1 + global $CFG; + + return get_records_sql("SELECT s.* FROM {$CFG->prefix}exercise_submissions s + WHERE s.isexercise = 1 AND s.exerciseid = $exercise->id - ORDER BY s.title"); + ORDER BY s.title"); } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_ungraded_assessments($exercise) { - global $CFG; - // Return all assessments which have not been graded or just graded - $cutofftime =time() - $CFG->maxeditingtime; + global $CFG; + // Return all assessments which have not been graded or just graded + $cutofftime =time() - $CFG->maxeditingtime; return get_records_select("exercise_assessments", "exerciseid = $exercise->id AND (timegraded = 0 OR - timegraded > $cutofftime)", "timecreated"); - } + timegraded > $cutofftime)", "timecreated"); + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_ungraded_assessments_student($exercise) { - global $CFG; - // Return all assessments which have not been graded or just graded of student's submissions - - $cutofftime =time() - $CFG->maxeditingtime; + global $CFG; + // Return all assessments which have not been graded or just graded of student's submissions + + $cutofftime =time() - $CFG->maxeditingtime; return get_records_sql("SELECT a.* FROM {$CFG->prefix}exercise_submissions s, {$CFG->prefix}user_students u, - {$CFG->prefix}exercise_assessments a + {$CFG->prefix}exercise_assessments a WHERE u.course = $exercise->course AND s.userid = u.userid AND s.exerciseid = $exercise->id - AND a.submissionid = s.id - AND (a.timegraded = 0 OR a.timegraded > $cutofftime) - AND a.timecreated < $cutofftime - ORDER BY a.timecreated ASC"); - } + AND a.submissionid = s.id + AND (a.timegraded = 0 OR a.timegraded > $cutofftime) + AND a.timecreated < $cutofftime + ORDER BY a.timecreated ASC"); + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_ungraded_assessments_teacher($exercise) { - global $CFG; - // Return all assessments which have not been graded or just graded of teacher's submissions - - $cutofftime =time() - $CFG->maxeditingtime; + global $CFG; + // Return all assessments which have not been graded or just graded of teacher's submissions + + $cutofftime =time() - $CFG->maxeditingtime; return get_records_sql("SELECT a.* FROM {$CFG->prefix}exercise_submissions s, {$CFG->prefix}exercise_assessments a WHERE s.isexercise = 1 AND s.exerciseid = $exercise->id - AND a.submissionid = s.id - AND (a.timegraded = 0 OR a.timegraded > $cutofftime) - AND a.timecreated < $cutofftime - ORDER BY a.timecreated ASC"); - } + AND a.submissionid = s.id + AND (a.timegraded = 0 OR a.timegraded > $cutofftime) + AND a.timecreated < $cutofftime + ORDER BY a.timecreated ASC"); + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_unmailed_assessments($cutofftime) { - /// Return list of (ungraded) assessments that have not been mailed out + /// Return list of (ungraded) assessments that have not been mailed out global $CFG; return get_records_sql("SELECT a.*, g.course, g.name FROM {$CFG->prefix}exercise_assessments a, {$CFG->prefix}exercise g WHERE a.mailed = 0 - AND a.timegraded = 0 + AND a.timegraded = 0 AND a.timecreated < $cutofftime AND g.id = a.exerciseid"); } function exercise_get_unmailed_graded_assessments($cutofftime) { - /// Return list of graded assessments that have not been mailed out + /// Return list of graded assessments that have not been mailed out global $CFG; return get_records_sql("SELECT a.*, g.course, g.name FROM {$CFG->prefix}exercise_assessments a, {$CFG->prefix}exercise g WHERE a.mailed = 0 - AND a.timegraded < $cutofftime - AND a.timegraded > 0 + AND a.timegraded < $cutofftime + AND a.timegraded > 0 AND g.id = a.exerciseid"); } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_user_assessments($exercise, $user) { - // Return all the user's assessments, newest first, oldest last - return get_records_select("exercise_assessments", "exerciseid = $exercise->id AND userid = $user->id", - "timecreated DESC"); + // Return all the user's assessments, newest first, oldest last + return get_records_select("exercise_assessments", "exerciseid = $exercise->id AND userid = $user->id", + "timecreated DESC"); } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_get_user_submissions($exercise, $user) { - // return submission of user oldest first, newest last - // teachers submit "exercises" + // return submission of user oldest first, newest last + // teachers submit "exercises" if (! $course = get_record("course", "id", $exercise->course)) { error("Course is misconfigured"); } - if (isteacher($course->id, $user->id)) { - return get_records_select("exercise_submissions", + if (isteacher($course->id, $user->id)) { + return get_records_select("exercise_submissions", "exerciseid = $exercise->id AND isexercise = 1", "timecreated" ); - } + } return get_records_select("exercise_submissions", "exerciseid = $exercise->id AND userid = $user->id", "timecreated" ); } @@ -1307,44 +1312,44 @@ function exercise_get_user_submissions($exercise, $user) { /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_list_all_ungraded_assessments($exercise) { - // lists all the assessments for comment by teacher - global $CFG; - - $table->head = array (get_string("title", "exercise"), get_string("timeassessed", "exercise"), get_string("action", "exercise")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - $timenow = time(); - - if ($assessments = exercise_get_ungraded_assessments($exercise)) { - foreach ($assessments as $assessment) { - if (!isteacher($exercise->course, $assessment->userid)) { - if (($timenow - $assessment->timegraded) < $CFG->maxeditingtime) { - $action = "id&aid=$assessment->id\">". - get_string("edit", "exercise").""; - } - else { - $action = "id&aid=$assessment->id\">". - get_string("gradeassessment", "exercise").""; - } - $submission = get_record("exercise_submissions", "id", $assessment->submissionid); - $table->data[] = array(exercise_print_submission_title($exercise, $submission), - userdate($assessment->timecreated), $action); - } - } - if (isset($table->data)) { - print_table($table); - } - } - } - + // lists all the assessments for comment by teacher + global $CFG; + + $table->head = array (get_string("title", "exercise"), get_string("timeassessed", "exercise"), get_string("action", "exercise")); + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + $timenow = time(); + + if ($assessments = exercise_get_ungraded_assessments($exercise)) { + foreach ($assessments as $assessment) { + if (!isteacher($exercise->course, $assessment->userid)) { + if (($timenow - $assessment->timegraded) < $CFG->maxeditingtime) { + $action = "id&aid=$assessment->id\">". + get_string("edit", "exercise").""; + } + else { + $action = "id&aid=$assessment->id\">". + get_string("gradeassessment", "exercise").""; + } + $submission = get_record("exercise_submissions", "id", $assessment->submissionid); + $table->data[] = array(exercise_print_submission_title($exercise, $submission), + userdate($assessment->timecreated), $action); + } + } + if (isset($table->data)) { + print_table($table); + } + } + } + /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_list_submissions_for_admin($exercise) { - // list the teacher sublmissions first - global $CFG, $EXERCISE_FWEIGHTS, $THEME, $USER; - + // list the teacher sublmissions first + global $CFG, $EXERCISE_FWEIGHTS, $THEME, $USER; + if (! $course = get_record("course", "id", $exercise->course)) { error("Course is misconfigured"); } @@ -1352,7 +1357,7 @@ function exercise_list_submissions_for_admin($exercise) { error("Course Module ID was incorrect"); } - exercise_print_assignment_info($exercise); + exercise_print_assignment_info($exercise); print_heading_with_help(get_string("administration"), "administration", "exercise"); echo"

id\">". get_string("teacherassessmenttable", "exercise", $course->teacher)."

\n"; @@ -1447,30 +1452,30 @@ function exercise_list_submissions_for_admin($exercise) { } } - // list student assessments - // Get all the students... - if ($users = get_course_students($course->id, "u.firstname, u.lastname")) { - $timenow = time(); - unset($table); - $table->head = array(get_string("name"), get_string("title", "exercise"), + // list student assessments + // Get all the students... + if ($users = get_course_students($course->id, "u.firstname, u.lastname")) { + $timenow = time(); + unset($table); + $table->head = array(get_string("name"), get_string("title", "exercise"), get_string("assessed", "exercise"), get_string("action", "exercise")); - $table->align = array ("left", "left", "left", "left"); - $table->size = array ("*", "*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - $nassessments = 0; - foreach ($users as $user) { - if ($assessments = exercise_get_user_assessments($exercise, $user)) { - $title =''; - foreach ($assessments as $assessment) { - if (!$submission = get_record("exercise_submissions", "id", $assessment->submissionid)) { - error("exercise_list_submissions_for_admin: Submission record not found!"); - } - $title .= $submission->title; - // test for allocated assesments which have not been done - if ($assessment->timecreated < $timenow) { + $table->align = array ("left", "left", "left", "left"); + $table->size = array ("*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + $nassessments = 0; + foreach ($users as $user) { + if ($assessments = exercise_get_user_assessments($exercise, $user)) { + $title =''; + foreach ($assessments as $assessment) { + if (!$submission = get_record("exercise_submissions", "id", $assessment->submissionid)) { + error("exercise_list_submissions_for_admin: Submission record not found!"); + } + $title .= $submission->title; + // test for allocated assesments which have not been done + if ($assessment->timecreated < $timenow) { // show only warm or cold assessments - $title .= " {".number_format($assessment->grade * $exercise->grade / 100.0, 0); + $title .= " {".number_format($assessment->grade * $exercise->grade / 100.0, 0); if ($assessment->timegraded) { $title .= "/".number_format($assessment->gradinggrade * $exercise->grade / COMMENTSCALE, 0); @@ -1484,22 +1489,22 @@ function exercise_list_submissions_for_admin($exercise) { $action =""; } $nassessments++; - $table->data[] = array("$user->firstname $user->lastname", $title, + $table->data[] = array("$user->firstname $user->lastname", $title, userdate($assessment->timecreated), $action); } - } - } + } + } + } + if (isset($table->data)) { + print_heading(get_string("studentassessments", "exercise", $course->student)." [$nassessments]"); + print_table($table); + echo "

".get_string("noteonstudentassessments", "exercise")."

\n"; } - if (isset($table->data)) { - print_heading(get_string("studentassessments", "exercise", $course->student)." [$nassessments]"); - print_table($table); - echo "

".get_string("noteonstudentassessments", "exercise")."

\n"; - } } - // now the sudent submissions - unset($table); - if ($users) { + // now the sudent submissions + unset($table); + if ($users) { $table->head = array (get_string("submittedby", "exercise"), get_string("title", "exercise"), get_string("submitted", "exercise"), get_string("action", "exercise")); $table->align = array ("left", "left", "left", "left"); @@ -1555,7 +1560,7 @@ function exercise_list_submissions_for_admin($exercise) { } } } - if (isset($table->data)) { + if (isset($table->data)) { print_heading(get_string("studentsubmissions", "exercise", $course->student)." [$nsubmissions]", "center"); print_table($table); @@ -1569,98 +1574,98 @@ function exercise_list_submissions_for_admin($exercise) { /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_list_teacher_assessments($exercise, $user) { - global $CFG; - - if (! $course = get_record("course", "id", $exercise->course)) { + global $CFG; + + if (! $course = get_record("course", "id", $exercise->course)) { error("Course is misconfigured"); } - $table->head = array (get_string("title", "exercise"), get_string("action", "exercise"), get_string("comment", "exercise")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - // get user's submissions - if ($submissions = exercise_get_user_submissions($exercise, $user)) { - foreach ($submissions as $submission) { - // get the assessments - if ($assessments = exercise_get_assessments($submission)) { - foreach ($assessments as $assessment) { - if (isteacher($exercise->course, $assessment->userid)) { // assessments by teachers only - $action = "id&aid=$assessment->id\">". - get_string("view", "exercise").""; - // has teacher commented on teacher's assessment? shouldn't happen but leave test in - if ($assessment->timegraded and ($timenow - $assessment->timegraded > $CFG->maxeditingtime)) { - $comment = get_string("gradedbyteacher", "exercise", $course->teacher); - } - else { - $comment = userdate($assessment->timecreated); - } - $table->data[] = array(exercise_print_submission_title($exercise, $submission), $action, $comment); - } - } - } - } - } - if (isset($table->data)) { - print_table($table); - } - else { - echo "
".get_string("noassessmentsdone", "exercise")."
\n"; - } - } + $table->head = array (get_string("title", "exercise"), get_string("action", "exercise"), get_string("comment", "exercise")); + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + // get user's submissions + if ($submissions = exercise_get_user_submissions($exercise, $user)) { + foreach ($submissions as $submission) { + // get the assessments + if ($assessments = exercise_get_assessments($submission)) { + foreach ($assessments as $assessment) { + if (isteacher($exercise->course, $assessment->userid)) { // assessments by teachers only + $action = "id&aid=$assessment->id\">". + get_string("view", "exercise").""; + // has teacher commented on teacher's assessment? shouldn't happen but leave test in + if ($assessment->timegraded and ($timenow - $assessment->timegraded > $CFG->maxeditingtime)) { + $comment = get_string("gradedbyteacher", "exercise", $course->teacher); + } + else { + $comment = userdate($assessment->timecreated); + } + $table->data[] = array(exercise_print_submission_title($exercise, $submission), $action, $comment); + } + } + } + } + } + if (isset($table->data)) { + print_table($table); + } + else { + echo "
".get_string("noassessmentsdone", "exercise")."
\n"; + } + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_list_teacher_submissions($exercise, $user, $reassess = false) { - // always allow user to reassess if that flag is true - global $CFG; - - if (! $course = get_record("course", "id", $exercise->course)) { + // always allow user to reassess if that flag is true + global $CFG; + + if (! $course = get_record("course", "id", $exercise->course)) { error("Course is misconfigured"); } - if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { - error("Course Module ID was incorrect"); - } + if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { + error("Course Module ID was incorrect"); + } - $strexercises = get_string("modulenameplural", "exercise"); + $strexercises = get_string("modulenameplural", "exercise"); $strexercise = get_string("modulename", "exercise"); - // get any assessment this user has done (could include hot one) - if (!$assessment = get_record_select("exercise_assessments", "exerciseid = $exercise->id - AND userid = $user->id")) { - // the user has not yet assessed this exercise, set up a hot assessment record for this user for one + // get any assessment this user has done (could include hot one) + if (!$assessment = get_record_select("exercise_assessments", "exerciseid = $exercise->id + AND userid = $user->id")) { + // the user has not yet assessed this exercise, set up a hot assessment record for this user for one // of the teacher submissions, first count the number of assessments for each teacher submission... - if ($submissions = exercise_get_teacher_submissions($exercise)) { - mt_srand ((float)microtime()*1000000); // initialise random number generator - foreach ($submissions as $submission) { - $n = count_records("exercise_assessments", "submissionid", $submission->id); - // ...OK to have zero, we add a small random number to randomise things... - $nassessments[$submission->id] = $n + mt_rand(0, 99) / 100; - } - // ...put the submissions with the lowest number of assessments first... - asort($nassessments); - reset($nassessments); - foreach ($nassessments as $submissionid => $n) { // break out of loop after the first element - $submission = get_record("exercise_submissions", "id", $submissionid); - // ... provided the user has NOT already assessed that submission... - if (!$assessment = exercise_get_submission_assessment($submission, $user)) { - $yearfromnow = time() + 365 * 86400; - // ...create one and set timecreated way in the future, reset when record is updated - $assessment->exerciseid = $exercise->id; - $assessment->submissionid = $submission->id; - $assessment->userid = $user->id; - $assessment->grade = -1; // set impossible grade - $assessment->timecreated = $yearfromnow; - if (!$assessment->id = insert_record("exercise_assessments", $assessment)) { - error("Could not insert exercise assessment!"); - } - break; - } - } - } - } else { + if ($submissions = exercise_get_teacher_submissions($exercise)) { + mt_srand ((float)microtime()*1000000); // initialise random number generator + foreach ($submissions as $submission) { + $n = count_records("exercise_assessments", "submissionid", $submission->id); + // ...OK to have zero, we add a small random number to randomise things... + $nassessments[$submission->id] = $n + mt_rand(0, 99) / 100; + } + // ...put the submissions with the lowest number of assessments first... + asort($nassessments); + reset($nassessments); + foreach ($nassessments as $submissionid => $n) { // break out of loop after the first element + $submission = get_record("exercise_submissions", "id", $submissionid); + // ... provided the user has NOT already assessed that submission... + if (!$assessment = exercise_get_submission_assessment($submission, $user)) { + $yearfromnow = time() + 365 * 86400; + // ...create one and set timecreated way in the future, reset when record is updated + $assessment->exerciseid = $exercise->id; + $assessment->submissionid = $submission->id; + $assessment->userid = $user->id; + $assessment->grade = -1; // set impossible grade + $assessment->timecreated = $yearfromnow; + if (!$assessment->id = insert_record("exercise_assessments", $assessment)) { + error("Could not insert exercise assessment!"); + } + break; + } + } + } + } else { // get hold of the teacher submission if (!$submission = get_record("exercise_submissions", "id", $assessment->submissionid)) { error("List teacher submissions: submission record not found"); @@ -1675,100 +1680,100 @@ function exercise_list_teacher_submissions($exercise, $user, $reassess = false) print_simple_box_end(); print_simple_box_end(); - $table->head = array (get_string("action", "exercise"), get_string("assessed", "exercise"), + $table->head = array (get_string("action", "exercise"), get_string("assessed", "exercise"), get_string("comment", "exercise")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - // now list user's assessments (but only list those which come from teacher submissions) - print_heading(get_string("yourassessment", "exercise")); - if ($assessments = exercise_get_user_assessments($exercise, $user)) { - $timenow = time(); - foreach ($assessments as $assessment) { - if (!$submission = get_record("exercise_submissions", "id", $assessment->submissionid)) { - error ("exercise_list_teacher_submissions: unable to get submission"); - } - // submission from a teacher, i.e an exercise submission? - if ($submission->isexercise) { - $comment = ''; - if ($reassess) { // just show re-assess - $action = "id&sid=$submission->id\">". - get_string("reassess", "exercise").""; - } - else { // reassess is false - assessment is a "normal state" - // user assessment has three states: record created but not assessed (date created + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + // now list user's assessments (but only list those which come from teacher submissions) + print_heading(get_string("yourassessment", "exercise")); + if ($assessments = exercise_get_user_assessments($exercise, $user)) { + $timenow = time(); + foreach ($assessments as $assessment) { + if (!$submission = get_record("exercise_submissions", "id", $assessment->submissionid)) { + error ("exercise_list_teacher_submissions: unable to get submission"); + } + // submission from a teacher, i.e an exercise submission? + if ($submission->isexercise) { + $comment = ''; + if ($reassess) { // just show re-assess + $action = "id&sid=$submission->id\">". + get_string("reassess", "exercise").""; + } + else { // reassess is false - assessment is a "normal state" + // user assessment has three states: record created but not assessed (date created // in the future); just assessed but still editable; and "static" (may or may not // have been graded by teacher, that is shown in the comment) - if ($assessment->timecreated > $timenow) { // user needs to assess this submission - $action = "id&sid=$submission->id\">". - get_string("assess", "exercise").""; - } - elseif ($assessment->timecreated > ($timenow - $CFG->maxeditingtime)) { + if ($assessment->timecreated > $timenow) { // user needs to assess this submission + $action = "id&sid=$submission->id\">". + get_string("assess", "exercise").""; + } + elseif ($assessment->timecreated > ($timenow - $CFG->maxeditingtime)) { // there's still time left to edit... - $action = "id&sid=$submission->id\">". - get_string("edit", "exercise").""; - } - else { - $action = "id&aid=$assessment->id\">" - .get_string("view", "exercise").""; - } - } - // show the date if in the past (otherwise the user hasn't done the assessment yet - $assessmentdate = ''; - if ($assessment->timecreated < $timenow) { - $assessmentdate = userdate($assessment->timecreated); - // if user has submitted work, see if teacher has graded assessment - if (exercise_count_user_submissions($exercise, $user) > 0) { - if ($assessment->timegraded and (($timenow - $assessment->timegraded) > $CFG->maxeditingtime)) { - $comment .= get_string("thereisfeedbackfromthe", "exercise", $course->teacher); - } - else { - $comment .= get_string("awaitingfeedbackfromthe", "exercise", $course->teacher); - } - } - } - $table->data[] = array($action, $assessmentdate, $comment); - } - } - print_table($table); + $action = "id&sid=$submission->id\">". + get_string("edit", "exercise").""; + } + else { + $action = "id&aid=$assessment->id\">" + .get_string("view", "exercise").""; + } + } + // show the date if in the past (otherwise the user hasn't done the assessment yet + $assessmentdate = ''; + if ($assessment->timecreated < $timenow) { + $assessmentdate = userdate($assessment->timecreated); + // if user has submitted work, see if teacher has graded assessment + if (exercise_count_user_submissions($exercise, $user) > 0) { + if ($assessment->timegraded and (($timenow - $assessment->timegraded) > $CFG->maxeditingtime)) { + $comment .= get_string("thereisfeedbackfromthe", "exercise", $course->teacher); + } + else { + $comment .= get_string("awaitingfeedbackfromthe", "exercise", $course->teacher); + } + } + } + $table->data[] = array($action, $assessmentdate, $comment); + } + } + print_table($table); } } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_list_unassessed_student_submissions($exercise, $user) { - // list the student submissions not assessed by the teacher - global $CFG; - - $timenow = time(); - - if (! $course = get_record("course", "id", $exercise->course)) { + // list the student submissions not assessed by the teacher + global $CFG; + + $timenow = time(); + + if (! $course = get_record("course", "id", $exercise->course)) { error("Course is misconfigured"); } - if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { - error("Course Module ID was incorrect"); - } + if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { + error("Course Module ID was incorrect"); + } - $table->head = array (get_string("title", "exercise"), get_string("submittedby", "exercise"), - get_string("submitted", "exercise"), get_string("action", "exercise"), + $table->head = array (get_string("title", "exercise"), get_string("submittedby", "exercise"), + get_string("submitted", "exercise"), get_string("action", "exercise"), get_string("comment", "exercise")); - $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; + $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; // get all the submissions, oldest first, youngest last - if ($submissions = exercise_get_student_submissions($exercise)) { - foreach ($submissions as $submission) { - // only consider "cold" submissions - if ($submission->timecreated < $timenow - $CFG->maxeditingtime) { - $comment = ""; - // see if student has already submitted - $submissionowner = get_record("user", "id", $submission->userid); - if (exercise_count_user_submissions($exercise, $submissionowner) == 1) { - // it's the student's first submission + if ($submissions = exercise_get_student_submissions($exercise)) { + foreach ($submissions as $submission) { + // only consider "cold" submissions + if ($submission->timecreated < $timenow - $CFG->maxeditingtime) { + $comment = ""; + // see if student has already submitted + $submissionowner = get_record("user", "id", $submission->userid); + if (exercise_count_user_submissions($exercise, $submissionowner) == 1) { + // it's the student's first submission // see if there are no cold assessments for this submission if (!exercise_count_assessments($submission)) { // now see if the teacher has already assessed this submission @@ -1812,53 +1817,53 @@ function exercise_list_unassessed_student_submissions($exercise, $user) { // there's no student assessment, odd!! } } - } - // this is student's second... submission - else { - $teacherassessed = false; - $warm = false; - if ($assessments = get_records("exercise_assessments", "submissionid", $submission->id)) { - foreach ($assessments as $assessment) { - if (isteacher($course->id, $assessment->userid)) { - $teacherassessed = true; + } + // this is student's second... submission + else { + $teacherassessed = false; + $warm = false; + if ($assessments = get_records("exercise_assessments", "submissionid", $submission->id)) { + foreach ($assessments as $assessment) { + if (isteacher($course->id, $assessment->userid)) { + $teacherassessed = true; if (!$teacher = get_record("user", "id", $assessment->userid)) { error("List unassessed student submissions: teacher record not found"); } $comment = get_string("resubmissionfor", "exercise", "$teacher->firstname $teacher->lastname"); - if ($assessment->timecreated > $timenow - $CFG->maxeditingtime) { - $warm = true; - } - break; // no need to look further - } - } - } - if ($teacherassessed and $warm) { - // last chance salon - $action = "id&sid=$submission->id\">". - get_string("edit", "exercise").""; + if ($assessment->timecreated > $timenow - $CFG->maxeditingtime) { + $warm = true; + } + break; // no need to look further + } + } + } + if ($teacherassessed and $warm) { + // last chance salon + $action = "id&sid=$submission->id\">". + get_string("edit", "exercise").""; $timegap = get_string("ago", "exercise", format_time($submission->timecreated - $timenow)); if ($submission->late) { $timegap = "".$timegap.""; } - $table->data[] = array(exercise_print_submission_title($exercise, $submission), - $submissionowner->firstname." ".$submissionowner->lastname, + $table->data[] = array(exercise_print_submission_title($exercise, $submission), + $submissionowner->firstname." ".$submissionowner->lastname, $timegap, $action, $comment); - } - if (!$teacherassessed) { - // no teacher's assessment + } + if (!$teacherassessed) { + // no teacher's assessment // find who did the previous assessment - if (!$submissions = exercise_get_user_submissions($exercise, $submissionowner)) { - error("List unassessed student submissions: submission records not found"); - } + if (!$submissions = exercise_get_user_submissions($exercise, $submissionowner)) { + error("List unassessed student submissions: submission records not found"); + } // get the oldest submission, exercise_get_user_submissions returns that first - foreach ($submissions as $tempsubmission) { + foreach ($submissions as $tempsubmission) { $prevsubmission = $tempsubmission; - break; - } - // get the teacher's assessment of the student's previous submission - if ($assessments = get_records("exercise_assessments", "submissionid", + break; + } + // get the teacher's assessment of the student's previous submission + if ($assessments = get_records("exercise_assessments", "submissionid", $prevsubmission->id)) { foreach ($assessments as $assessment) { if (isteacher($course->id, $assessment->userid)) { @@ -1867,152 +1872,152 @@ function exercise_list_unassessed_student_submissions($exercise, $user) { } $comment = get_string("resubmissionfor", "exercise", "$teacher->firstname $teacher->lastname"); - break; // no need to look further + break; // no need to look further - } + } } } - $action = "id&sid=$submission->id\">". - get_string("assess", "exercise").""; + $action = "id&sid=$submission->id\">". + get_string("assess", "exercise").""; $timegap = get_string("ago", "exercise", format_time($submission->timecreated - $timenow)); if ($submission->late) { $timegap = "".$timegap.""; } - $table->data[] = array(exercise_print_submission_title($exercise, $submission), - $submissionowner->firstname." ".$submissionowner->lastname, + $table->data[] = array(exercise_print_submission_title($exercise, $submission), + $submissionowner->firstname." ".$submissionowner->lastname, $timegap, $action, $comment); - } - } - } - } - if (isset($table->data)) { - print_table($table); - } + } + } + } + } + if (isset($table->data)) { + print_table($table); + } } } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_list_unassessed_teacher_submissions($exercise, $user) { - // list the teacher submissions not assessed by this user - global $CFG; - - $table->head = array (get_string("title", "exercise"), get_string("action", "exercise"), get_string("comment", "exercise")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - if ($submissions = exercise_get_teacher_submissions($exercise)) { - foreach ($submissions as $submission) { - $comment = ""; - // see if user already graded this assessment - if ($assessment = get_record_select("exercise_assessments", "submissionid = $submission->id - AND userid = $user->id")) { - $timenow = time(); - if (($timenow - $assessment->timecreated < $CFG->maxeditingtime)) { - // last chance salon - $action = "id&sid=$submission->id\">". - get_string("edit", "exercise").""; - $table->data[] = array(exercise_print_submission_title($exercise, $submission), $action, $comment); - } - } - else { // no assessment - $action = "id&sid=$submission->id\">". - get_string("assess", "exercise").""; - $table->data[] = array(exercise_print_submission_title($exercise, $submission), $action, $comment); - } - } - if (isset($table->data)) { - print_table($table); - } - } - } + // list the teacher submissions not assessed by this user + global $CFG; + + $table->head = array (get_string("title", "exercise"), get_string("action", "exercise"), get_string("comment", "exercise")); + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + if ($submissions = exercise_get_teacher_submissions($exercise)) { + foreach ($submissions as $submission) { + $comment = ""; + // see if user already graded this assessment + if ($assessment = get_record_select("exercise_assessments", "submissionid = $submission->id + AND userid = $user->id")) { + $timenow = time(); + if (($timenow - $assessment->timecreated < $CFG->maxeditingtime)) { + // last chance salon + $action = "id&sid=$submission->id\">". + get_string("edit", "exercise").""; + $table->data[] = array(exercise_print_submission_title($exercise, $submission), $action, $comment); + } + } + else { // no assessment + $action = "id&sid=$submission->id\">". + get_string("assess", "exercise").""; + $table->data[] = array(exercise_print_submission_title($exercise, $submission), $action, $comment); + } + } + if (isset($table->data)) { + print_table($table); + } + } + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_list_ungraded_assessments($exercise, $stype) { - global $CFG; - - if (! $course = get_record("course", "id", $exercise->course)) { + global $CFG; + + if (! $course = get_record("course", "id", $exercise->course)) { error("Course is misconfigured"); } - if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { - error("Course Module ID was incorrect"); - } - - // lists all the assessments of student submissions for grading by teacher - $table->head = array (get_string("title", "exercise"), get_string("submittedby", "exercise"), - get_string("assessor", "exercise"), get_string("timeassessed", "exercise"), get_string("action", "exercise")); - $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - $timenow = time(); - - switch ($stype) { - case "student" : - $assessments = exercise_get_ungraded_assessments_student($exercise); - break; - case "teacher" : - $assessments = exercise_get_ungraded_assessments_teacher($exercise); - break; - } - if ($assessments) { - foreach ($assessments as $assessment) { - if (!isteacher($exercise->course, $assessment->userid)) { // don't let teacher grade their own assessments - if (($timenow - $assessment->timegraded) < $CFG->maxeditingtime) { - $action = "id&stype=$stype&aid=$assessment->id\">". - get_string("edit", "exercise").""; - } - else { - $action = "id&stype=$stype&aid=$assessment->id\">". - get_string("grade", "exercise").""; - } - $submission = get_record("exercise_submissions", "id", $assessment->submissionid); - $submissionowner = get_record("user", "id", $submission->userid); - $assessor = get_record("user", "id", $assessment->userid); - $table->data[] = array(exercise_print_submission_title($exercise, $submission), - $submissionowner->firstname." ".$submissionowner->lastname, - $assessor->firstname." ".$assessor->lastname, userdate($assessment->timecreated), $action); - } - } - if (isset($table->data)) { - print_table($table); - } - } - } - + if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + // lists all the assessments of student submissions for grading by teacher + $table->head = array (get_string("title", "exercise"), get_string("submittedby", "exercise"), + get_string("assessor", "exercise"), get_string("timeassessed", "exercise"), get_string("action", "exercise")); + $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + $timenow = time(); + + switch ($stype) { + case "student" : + $assessments = exercise_get_ungraded_assessments_student($exercise); + break; + case "teacher" : + $assessments = exercise_get_ungraded_assessments_teacher($exercise); + break; + } + if ($assessments) { + foreach ($assessments as $assessment) { + if (!isteacher($exercise->course, $assessment->userid)) { // don't let teacher grade their own assessments + if (($timenow - $assessment->timegraded) < $CFG->maxeditingtime) { + $action = "id&stype=$stype&aid=$assessment->id\">". + get_string("edit", "exercise").""; + } + else { + $action = "id&stype=$stype&aid=$assessment->id\">". + get_string("grade", "exercise").""; + } + $submission = get_record("exercise_submissions", "id", $assessment->submissionid); + $submissionowner = get_record("user", "id", $submission->userid); + $assessor = get_record("user", "id", $assessment->userid); + $table->data[] = array(exercise_print_submission_title($exercise, $submission), + $submissionowner->firstname." ".$submissionowner->lastname, + $assessor->firstname." ".$assessor->lastname, userdate($assessment->timecreated), $action); + } + } + if (isset($table->data)) { + print_table($table); + } + } + } + /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_list_user_submissions($exercise, $user) { - global $CFG; - - if (! $course = get_record("course", "id", $exercise->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { - error("Course Module ID was incorrect"); - } - - $timenow = time(); - $table->head = array (get_string("title", "exercise"), get_string("action", "exercise"), - get_string("submitted", "exercise"), get_string("assessment", "exercise")); - $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - if ($submissions = exercise_get_user_submissions($exercise, $user)) { + global $CFG; + + if (! $course = get_record("course", "id", $exercise->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + $timenow = time(); + $table->head = array (get_string("title", "exercise"), get_string("action", "exercise"), + get_string("submitted", "exercise"), get_string("assessment", "exercise")); + $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + if ($submissions = exercise_get_user_submissions($exercise, $user)) { foreach ($submissions as $submission) { - $action = ''; - $comment = ''; - // allow user to delete submission if it's warm - if ($submission->timecreated > $timenow - $CFG->maxeditingtime) { - $action = "id&sid=$submission->id\">". - get_string("delete", "exercise").""; - } + $action = ''; + $comment = ''; + // allow user to delete submission if it's warm + if ($submission->timecreated > $timenow - $CFG->maxeditingtime) { + $action = "id&sid=$submission->id\">". + get_string("delete", "exercise").""; + } // if this is a teacher's submission (an exercise descrription) ignore any assessments if (!$submission->isexercise) { // get the teacher assessments (could be more than one, if unlikely, when multiple teachers) @@ -2040,655 +2045,675 @@ function exercise_list_user_submissions($exercise, $user) { } } } - if (!$comment and isstudent($course->id, $user->id)) { - $comment = get_string("awaitingassessmentbythe", "exercise", $course->teacher); - } + if (!$comment and isstudent($course->id, $user->id)) { + $comment = get_string("awaitingassessmentbythe", "exercise", $course->teacher); + } $submissiondate = userdate($submission->timecreated); if ($submission->late) { $submissiondate = "".$submissiondate.""; } - $table->data[] = array(exercise_print_submission_title($exercise, $submission), $action, - $submissiondate, $comment); - } - print_table($table); - } + $table->data[] = array(exercise_print_submission_title($exercise, $submission), $action, + $submissiondate, $comment); + } + print_table($table); + } } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_print_assessment_form($exercise, $assessment = false, $allowchanges = false, $returnto = '') { - // prints several variants of the assessment form - global $CFG, $THEME, $USER, $EXERCISE_SCALES, $EXERCISE_EWEIGHTS; - - if (! $course = get_record("course", "id", $exercise->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { - error("Course Module ID was incorrect"); - } - - $timenow = time(); - - if ($assessment) { - - if (!$submission = get_record("exercise_submissions", "id", $assessment->submissionid)) { - error ("exercise_print_assessment_form: Submission record not found"); - } - // test if this assessment is from a teacher or student. + // prints several variants of the assessment form + global $CFG, $THEME, $USER, $EXERCISE_SCALES, $EXERCISE_EWEIGHTS; + + if (! $course = get_record("course", "id", $exercise->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + $timenow = time(); + + if ($assessment) { + + if (!$submission = get_record("exercise_submissions", "id", $assessment->submissionid)) { + error ("exercise_print_assessment_form: Submission record not found"); + } + // test if this assessment is from a teacher or student. // Teacher's assessments are more complicated as we need to go back a couple of steps // to find the exercise. Student's assessments are directly associated with an exercise. - if (isteacher($course->id, $assessment->userid)) { - // A teacher's assessment, requires getting the student's assessment(s) + if (isteacher($course->id, $assessment->userid)) { + // A teacher's assessment, requires getting the student's assessment(s) // and finding which of those assessments which comes from a teacher submission, // that is the exercise - $exercisefound = false; - if (!$submissionowner = get_record("user", "id", $submission->userid)) { - error ("exercise_print_assessment_form: User record not found"); - } - if ($initialassessments = exercise_get_user_assessments($exercise, $submissionowner)) { - // should only be one but we'll loop anyway - foreach($initialassessments as $initialassessment) { - if (!$teachersubmission = get_record("exercise_submissions", "id", $initialassessment->submissionid)) { - error ("exercise_print_assessment_form: Teacher Submission record not found"); - } - if ($teachersubmission->isexercise) { - $exercisefound = true; - break; - } - } - } - if ($exercisefound) { - print_heading(get_string("theexerciseandthesubmissionby", "exercise", - "$submissionowner->firstname $submissionowner->lastname")); - echo "
-
cellcontent\">\n"; - echo exercise_print_submission_title($exercise, $teachersubmission); - echo "

\n"; - } - } - else { - // it's a student assessment, print instructions if it's their own assessment - if ($assessment->userid == $USER->id) { - print_heading_with_help(get_string("pleaseusethisform", "exercise"), "grading", "exercise"); - } - } - - echo "
-
cellcontent\">\n"; - echo exercise_print_submission_title($exercise, $submission); - echo "

\n"; - - // only show the grade if grading strategy > 0 and the grade is positive - if ($exercise->gradingstrategy and $assessment->grade >= 0) { - echo "
".get_string("thegradeis", "exercise").": ". - number_format($assessment->grade * $exercise->grade / 100.0, 2)." (". - get_string("maximumgrade")." ".number_format($exercise->grade, 0).")

\n"; - } - } - - // now print the grading form with the teacher's comments if any - // FORM is needed for Mozilla browsers, else radio bttons are not checked - ?> -
- - - - - - userid)) { - error("Exercise_print_assessment_form: could not find user record"); - } - if ($assessmentowner->id == $USER->id) { - $formtitle = get_string("yourassessment", "exercise"); - } - else { - $formtitle = get_string("assessmentby", "exercise", "$assessmentowner->firstname $assessmentowner->lastname"); - } - } - else { - $formtitle = get_string("assessmentform", "exercise"); - } - echo "
\n"; - echo "\n"; - echo " \n"; - echo "\n"; - - // get the assignment elements... - if (!$elementsraw = get_records("exercise_elements", "exerciseid", $exercise->id, "elementno ASC")) { - print_string("noteonassignmentelements", "exercise"); - } - else { - foreach ($elementsraw as $element) { - $elements[] = $element; // to renumber index 0,1,2... - } - } - - if ($assessment) { - // get any previous grades... - if ($gradesraw = get_records_select("exercise_grades", "assessmentid = $assessment->id", "elementno")) { - foreach ($gradesraw as $grade) { - $grades[] = $grade; // to renumber index 0,1,2... - } - } - } - else { - // setup dummy grades array - for($i = 0; $i < count($elementsraw); $i++) { // gives a suitable sized loop - $grades[$i]->feedback = get_string("yourfeedbackgoeshere", "exercise"); - $grades[$i]->grade = 0; - } - } - - // determine what sort of grading - switch ($exercise->gradingstrategy) { - case 0: // no grading - // now print the form - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - } - break; - - case 1: // accumulative grading - // now print the form - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - } - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - } - break; - - case 2: // error banded grading - // now run through the elements - $error = 0; - for ($i=0; $i < count($elements) - 1; $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - if (empty($grades[$i]->grade)) { - $error += $EXERCISE_EWEIGHTS[$elements[$i]->weight]; - } - } - // print the number of negative elements - // echo "\n"; - // echo "\n"; - // echo " \n"; - echo "
cellheading2\">
$formtitle

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); - echo "

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - echo text_to_html($grades[$i]->feedback); - } - echo "
cellheading2\"> 

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); - echo "

Weight: " - .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."\n"; - echo "

". get_string("grade"). ":

\n"; - - // get the appropriate scale - $scalenumber=$elements[$i]->scale; - $SCALE = (object)$EXERCISE_SCALES[$scalenumber]; - switch ($SCALE->type) { - case 'radio' : - // show selections highest first - echo "
$SCALE->start   "; - for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { - $checked = false; - if (isset($grades[$i]->grade)) { - if ($j == $grades[$i]->grade) { - $checked = true; - } - } - else { // there's no previous grade so check the lowest option - if ($j == 0) { - $checked = true; - } - } - if ($checked) { - echo "    \n"; - } - else { - echo "    \n"; - } - } - echo "   $SCALE->end
\n"; - break; - case 'selection' : - unset($numbers); - for ($j = $SCALE->size; $j >= 0; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[$i]->grade)) { - choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[$i]", 0, ""); - } - break; - - echo "

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - echo text_to_html($grades[$i]->feedback); - } - echo "
cellheading2\"> 

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); - echo "

Weight: " - .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."\n"; - echo "

". get_string("grade"). ":

\n"; - - // get the appropriate scale - yes/no scale (0) - $SCALE = (object) $EXERCISE_SCALES[0]; - switch ($SCALE->type) { - case 'radio' : - // show selections highest first - echo "
$SCALE->start   "; - for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { - $checked = false; - if (isset($grades[$i]->grade)) { - if ($j == $grades[$i]->grade) { - $checked = true; - } - } - else { // there's no previous grade so check the lowest option - if ($j == 0) { - $checked = true; - } - } - if ($checked) { - echo "    \n"; - } - else { - echo "    \n"; - } - } - echo "   $SCALE->end
\n"; - break; - case 'selection' : - unset($numbers); - for ($j = $SCALE->size; $j >= 0; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[$i]->grade)) { - choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[$i]", 0, ""); - } - break; - } - - echo "

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - if (isset($grades[$i]->feedback)) { - echo text_to_html($grades[$i]->feedback); - } - } - echo " 
cellheading2\"> 
".get_string("numberofnegativeitems", "exercise")."$negativecount
cellheading2\"> 
\n"; - // now print the grade table - echo "

".get_string("gradetable","exercise")."
\n"; - echo "
\n"; - for ($i=0; $i<=$exercise->nelements; $i++) { - if ($i == intval($error + 0.5)) { - echo "\n"; - } - else { - echo "\n"; - } - } - echo "
". - get_string("numberofnegativeresponses", "exercise"); - echo "". get_string("suggestedgrade", "exercise")."
pixpath/t/right.gif\"> $i{$elements[$i]->maxscore}
$i{$elements[$i]->maxscore}
\n"; - echo "

\n"; - break; - - case 3: // criteria grading - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - // find which criteria has been selected (saved in the zero element), if any - if (isset($grades[0]->grade)) { - $selection = $grades[0]->grade; - } - else { - $selection = 0; - } - // now run through the elements - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - if ($selection == $i) { - echo " \n"; - } - else { - echo " \n"; - } - echo "\n"; - } - echo "
". - get_string("optionaladjustment", "exercise").":\n"; - unset($numbers); - for ($j = 20; $j >= -20; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[$exercise->nelements]->grade)) { - choose_from_menu($numbers, "grade[$exercise->nelements]", $grades[$exercise->nelements]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[$exercise->nelements]", 0, ""); - } - echo "
cellheading2\"> cellheading2\">". get_string("criterion","exercise")."cellheading2\">".get_string("select", "exercise")."cellheading2\">".get_string("suggestedgrade", "exercise")."
$iplus1".text_to_html($elements[$i]->description)."{$elements[$i]->maxscore}
\n"; - echo "

\n"; - break; - - case 4: // rubric grading - // now run through the elements... - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - if (isset($grades[$i])) { - $selection = $grades[$i]->grade; - } else { - $selection = 0; - } - // ...and the rubrics - if ($rubricsraw = get_records_select("exercise_rubrics", "exerciseid = $exercise->id AND - elementno = $i", "rubricno ASC")) { - unset($rubrics); - foreach ($rubricsraw as $rubic) { - $rubrics[] = $rubic; // to renumber index 0,1,2... - } - for ($j=0; $j<5; $j++) { - if (empty($rubrics[$j]->description)) { - break; // out of inner for loop - } - echo "\n"; - if ($selection == $j) { - echo " \n"; - }else { - echo " \n"; - } - echo "\n"; - } - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - } - } - break; - } // end of outer switch - - // now get the general comment (present in all types) - echo "\n"; - switch ($exercise->gradingstrategy) { - case 0: - case 1: - case 4 : // no grading, accumulative and rubic - echo " \n"; - break; - default : - echo " \n"; - } - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - - $timenow = time(); - // the teacher's comment on the assessment - // always allow the teacher to change their comment and grade if it's not their assessment! - if (isteacher($course->id) and ($assessment->userid != $USER->id)) { - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - } - elseif ($assessment->timegraded and ($assessment->timegraded < ($timenow - $CFG->maxeditingtime))) { - // now show the teacher's comment (but not the grade) to the student if available... - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - } - - // ...and close the table, show buttons if needed... - echo "
". - get_string("optionaladjustment", "exercise")."\n"; - unset($numbers); - for ($j = 20; $j >= -20; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[1]->grade)) { - choose_from_menu($numbers, "grade[1]", $grades[1]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[1]", 0, ""); - } - echo "
".get_string("element", "exercise")." $iplus1:".text_to_html($elements[$i]->description). - "

Weight: " - .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."

cellheading2\" align=\"center\">".get_string("select", "exercise")."cellheading2\">". get_string("criterion","exercise")."
".text_to_html($rubrics[$j]->description)."

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - echo text_to_html($grades[$i]->feedback); - } - echo "
cellheading2\"> 

". get_string("generalcomment", "exercise").":

". get_string("reasonforadjustment", "exercise").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - if ($assessment) { - if (isset($assessment->generalcomment)) { - echo text_to_html($assessment->generalcomment); - } - } - else { - print_string("yourfeedbackgoeshere", "exercise"); - } - } - echo " 
cellheading2\"> 
".get_string("gradeforstudentsassessment", "exercise", $course->student). - "\n"; - // set up coment scale - for ($i=COMMENTSCALE; $i>=0; $i--) { - $num[$i] = $i; - } - choose_from_menu($num, "gradinggrade", $assessment->gradinggrade, ""); - echo "

". get_string("teacherscomment", "exercise").":

\n"; - echo "\n"; - echo "

". get_string("teacherscomment", "exercise").":

\n"; - echo text_to_html($assessment->teachercomment); - echo " 
cellheading2\"> 

\n"; - if ($assessment and $allowchanges) { - if (isteacher($course->id)) { - // ...show two buttons...to resubmit or not to resubmit - echo "student)."\" - onclick=\"document.assessmentform.submit();\">\n"; - echo "student)."\" - onclick=\"document.assessmentform.resubmit.value='1';document.assessmentform.submit();\">\n"; - } - else { - // ... show save button - echo "\n"; - } - } - echo "
\n"; - } - - -/////////////////////////////////////////////////////////////////////////////////////////////// -function exercise_print_assessments_by_user_for_admin($exercise, $user) { - - if (! $course = get_record("course", "id", $exercise->course)) { - error("Course is misconfigured"); + $exercisefound = false; + if (!$submissionowner = get_record("user", "id", $submission->userid)) { + error ("exercise_print_assessment_form: User record not found"); + } + if ($initialassessments = exercise_get_user_assessments($exercise, $submissionowner)) { + // should only be one but we'll loop anyway + foreach($initialassessments as $initialassessment) { + if (!$teachersubmission = get_record("exercise_submissions", "id", $initialassessment->submissionid)) { + error ("exercise_print_assessment_form: Teacher Submission record not found"); + } + if ($teachersubmission->isexercise) { + $exercisefound = true; + break; + } + } + } + if ($exercisefound) { + print_heading(get_string("theexerciseandthesubmissionby", "exercise", + "$submissionowner->firstname $submissionowner->lastname")); + echo "
+
cellcontent\">\n"; + echo exercise_print_submission_title($exercise, $teachersubmission); + echo "

\n"; + } + } + else { + // it's a student assessment, print instructions if it's their own assessment + if ($assessment->userid == $USER->id) { + print_heading_with_help(get_string("pleaseusethisform", "exercise"), "grading", "exercise"); + } + } + + echo "
+
cellcontent\">\n"; + echo exercise_print_submission_title($exercise, $submission); + echo "

\n"; + + // only show the grade if grading strategy > 0 and the grade is positive + if ($exercise->gradingstrategy and $assessment->grade >= 0) { + + echo "
".get_string("thegradeis", "exercise").": ". + number_format($assessment->grade * $exercise->grade / 100.0, 2)." (". + get_string("maximumgrade")." ".number_format($exercise->grade, 0).")

\n"; + } } - if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { - error("Course Module ID was incorrect"); - } - - if ($assessments =exercise_get_user_assessments($exercise, $user)) { - foreach ($assessments as $assessment) { - echo "

".get_string("assessmentby", "exercise", $user->firstname." ".$user->lastname)."

\n"; - exercise_print_assessment_form($exercise, $assessment); - echo "

id&aid=$assessment->id\">". - get_string("amend", "exercise")." ".get_string("gradeforstudentsassessment","exercise", - $course->student)."\n"; - echo " | id&aid=$assessment->id\">". - get_string("delete", "exercise")."


\n"; - } - } - } + + // now print the grading form with the teacher's comments if any + // FORM is needed for Mozilla browsers, else radio bttons are not checked + ?> +
+ + + + + + userid)) { + error("Exercise_print_assessment_form: could not find user record"); + } + if ($assessmentowner->id == $USER->id) { + $formtitle = get_string("yourassessment", "exercise"); + } + else { + $formtitle = get_string("assessmentby", "exercise", "$assessmentowner->firstname $assessmentowner->lastname"); + } + } + else { + $formtitle = get_string("assessmentform", "exercise"); + } + echo "
\n"; + echo "\n"; + echo " \n"; -/////////////////////////////////////////////////////////////////////////////////////////////// -function exercise_print_assessments_for_admin($exercise, $submission) { + echo "\n"; - if (! $course = get_record("course", "id", $exercise->course)) { - error("Course is misconfigured"); + // get the assignment elements... + if (!$elementsraw = get_records("exercise_elements", "exerciseid", $exercise->id, "elementno ASC")) { + print_string("noteonassignmentelements", "exercise"); + } + else { + foreach ($elementsraw as $element) { + $elements[] = $element; // to renumber index 0,1,2... + } } - if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { - error("Course Module ID was incorrect"); - } - - if ($assessments =exercise_get_assessments($submission)) { - foreach ($assessments as $assessment) { - if (!$user = get_record("user", "id", $assessment->userid)) { - error (" exercise_print_assessments_for_admin: unable to get user record"); - } - echo "

".get_string("assessmentby", "exercise", $user->firstname." ".$user->lastname)."

\n"; - exercise_print_assessment_form($exercise, $assessment); - echo "

id&aid=$assessment->id\">". - get_string("delete", "exercise")."


\n"; - } - } - } - -/////////////////////////////////////////////////////////////////////////////////////////////// -function exercise_print_assignment_info($exercise) { + if ($assessment) { + // get any previous grades... + if ($gradesraw = get_records_select("exercise_grades", "assessmentid = $assessment->id", "elementno")) { + foreach ($gradesraw as $grade) { + $grades[] = $grade; // to renumber index 0,1,2... + } + } + } + else { + // setup dummy grades array + for($i = 0; $i < count($elementsraw); $i++) { // gives a suitable sized loop + $grades[$i]->feedback = get_string("yourfeedbackgoeshere", "exercise"); + $grades[$i]->grade = 0; + } + } + + // determine what sort of grading + switch ($exercise->gradingstrategy) { + case 0: // no grading + // now print the form + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + } + break; + + case 1: // accumulative grading + // now print the form + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + + echo " \n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + } + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + } + break; + + case 2: // error banded grading + // now run through the elements + $error = 0; + for ($i=0; $i < count($elements) - 1; $i++) { + $iplus1 = $i+1; + echo "\n"; + + echo " \n"; + + echo " \n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + if (empty($grades[$i]->grade)) { + $error += $EXERCISE_EWEIGHTS[$elements[$i]->weight]; + } + } + // print the number of negative elements + // echo "\n"; + // echo "\n"; + // echo " \n"; + echo "
cellheading2\">
$formtitle

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); + echo "

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + echo text_to_html($grades[$i]->feedback); + } + echo "
cellheading2\"> 

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); + echo "

Weight: " + .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."\n"; + echo "

". get_string("grade"). ":

\n"; + + // get the appropriate scale + $scalenumber=$elements[$i]->scale; + $SCALE = (object)$EXERCISE_SCALES[$scalenumber]; + switch ($SCALE->type) { + case 'radio' : + // show selections highest first + echo "
$SCALE->start   "; + for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { + $checked = false; + if (isset($grades[$i]->grade)) { + if ($j == $grades[$i]->grade) { + $checked = true; + } + } + else { // there's no previous grade so check the lowest option + if ($j == 0) { + $checked = true; + } + } + if ($checked) { + echo "    \n"; + } + else { + echo "    \n"; + } + } + echo "   $SCALE->end
\n"; + break; + case 'selection' : + unset($numbers); + for ($j = $SCALE->size; $j >= 0; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[$i]->grade)) { + choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[$i]", 0, ""); + } + break; + + echo "

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + echo text_to_html($grades[$i]->feedback); + } + echo "
cellheading2\"> 

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); + echo "

Weight: " + .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."\n"; + echo "

". get_string("grade"). ":

\n"; + + // get the appropriate scale - yes/no scale (0) + $SCALE = (object) $EXERCISE_SCALES[0]; + switch ($SCALE->type) { + case 'radio' : + // show selections highest first + echo "
$SCALE->start   "; + for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { + $checked = false; + if (isset($grades[$i]->grade)) { + if ($j == $grades[$i]->grade) { + $checked = true; + } + } + else { // there's no previous grade so check the lowest option + if ($j == 0) { + $checked = true; + } + } + if ($checked) { + echo "    \n"; + } + else { + echo "    \n"; + } + } + echo "   $SCALE->end
\n"; + break; + case 'selection' : + unset($numbers); + for ($j = $SCALE->size; $j >= 0; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[$i]->grade)) { + choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[$i]", 0, ""); + } + break; + } + + echo "

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + if (isset($grades[$i]->feedback)) { + echo text_to_html($grades[$i]->feedback); + } + } + echo " 
cellheading2\"> 
".get_string("numberofnegativeitems", "exercise")."$negativecount
cellheading2\"> 
\n"; + // now print the grade table + echo "

".get_string("gradetable","exercise")."
\n"; + echo "
\n"; + for ($i=0; $i<=$exercise->nelements; $i++) { + if ($i == intval($error + 0.5)) { + echo "\n"; + } + else { + echo "\n"; + } + } + echo "
". + get_string("numberofnegativeresponses", "exercise"); + echo "". get_string("suggestedgrade", "exercise")."
pixpath/t/right.gif\"> $i{$elements[$i]->maxscore}
$i{$elements[$i]->maxscore}
\n"; + echo "

\n"; + break; + + case 3: // criteria grading + echo "\n"; - if (! $course = get_record("course", "id", $exercise->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { - error("Course Module ID was incorrect"); - } - // print standard assignment heading - $strdifference = format_time($exercise->deadline - time()); - if (($exercise->deadline - time()) < 0) { - $strdifference = "$strdifference"; - } - $strduedate = userdate($exercise->deadline)." ($strdifference)"; - print_simple_box_start("center"); - print_heading($exercise->name, "center"); - print_simple_box_start("center"); - echo "".get_string("duedate", "exercise").": $strduedate
"; - echo "".get_string("maximumgrade").": $exercise->grade
"; - echo "".get_string("handlingofmultiplesubmissions", "exercise").":"; - if ($exercise->usemaximum) { - echo get_string("usemaximum", "exercise")."
\n"; - } - else { - echo get_string("usemean", "exercise")."
\n"; - } - echo "".get_string("detailsofassessment", "exercise").": - id&action=displaygradingform\">". - get_string("specimenassessmentform", "exercise")."
"; - print_simple_box_end(); - print_simple_box_end(); - echo "
"; -} + echo " \n"; + echo " \n"; -/////////////////////////////////////////////////////////////////////////////////////////////// -function exercise_print_difference($time) { - if ($time < 0) { - $timetext = get_string("late", "assignment", format_time($time)); - return " ($timetext)"; - } else { - $timetext = get_string("early", "assignment", format_time($time)); + echo " \n"; + echo " \n"; + // find which criteria has been selected (saved in the zero element), if any + if (isset($grades[0]->grade)) { + $selection = $grades[0]->grade; + } + else { + $selection = 0; + } + // now run through the elements + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + + echo " \n"; + if ($selection == $i) { + echo " \n"; + } + else { + echo " \n"; + } + echo "\n"; + } + echo "
". + get_string("optionaladjustment", "exercise").":\n"; + unset($numbers); + for ($j = 20; $j >= -20; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[$exercise->nelements]->grade)) { + choose_from_menu($numbers, "grade[$exercise->nelements]", $grades[$exercise->nelements]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[$exercise->nelements]", 0, ""); + } + echo "
cellheading2\"> cellheading2\">". get_string("criterion","exercise")."cellheading2\">".get_string("select", "exercise")."cellheading2\">".get_string("suggestedgrade", "exercise")."
$iplus1".text_to_html($elements[$i]->description)."{$elements[$i]->maxscore}
\n"; + echo "

\n"; + break; + + case 4: // rubric grading + // now run through the elements... + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + + echo " \n"; + echo " \n"; + + if (isset($grades[$i])) { + $selection = $grades[$i]->grade; + } else { + $selection = 0; + } + // ...and the rubrics + if ($rubricsraw = get_records_select("exercise_rubrics", "exerciseid = $exercise->id AND + elementno = $i", "rubricno ASC")) { + unset($rubrics); + foreach ($rubricsraw as $rubic) { + $rubrics[] = $rubic; // to renumber index 0,1,2... + } + for ($j=0; $j<5; $j++) { + if (empty($rubrics[$j]->description)) { + break; // out of inner for loop + } + echo "\n"; + + if ($selection == $j) { + echo " \n"; + }else { + echo " \n"; + } + echo "\n"; + } + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + } + } + break; + } // end of outer switch + + // now get the general comment (present in all types) + echo "\n"; + switch ($exercise->gradingstrategy) { + case 0: + case 1: + case 4 : // no grading, accumulative and rubic + echo " \n"; + break; + default : + echo " \n"; + } + echo " \n"; + + echo "\n"; + + echo "\n"; + + echo " \n"; + + echo "\n"; + + $timenow = time(); + // the teacher's comment on the assessment + // always allow the teacher to change their comment and grade if it's not their assessment! + if (isteacher($course->id) and ($assessment->userid != $USER->id)) { + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + } + elseif ($assessment->timegraded and ($assessment->timegraded < ($timenow - $CFG->maxeditingtime))) { + // now show the teacher's comment (but not the grade) to the student if available... + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + + // ...and close the table, show buttons if needed... + echo "
". + get_string("optionaladjustment", "exercise")."\n"; + unset($numbers); + for ($j = 20; $j >= -20; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[1]->grade)) { + choose_from_menu($numbers, "grade[1]", $grades[1]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[1]", 0, ""); + } + echo "
".get_string("element", "exercise")." $iplus1:".text_to_html($elements[$i]->description). + "

Weight: " + .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."

cellheading2\" align=\"center\">".get_string("select", "exercise")."cellheading2\">". get_string("criterion","exercise")."
".text_to_html($rubrics[$j]->description)."

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + echo text_to_html($grades[$i]->feedback); + } + echo "
cellheading2\"> 

". get_string("generalcomment", "exercise").":

". get_string("reasonforadjustment", "exercise").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + if ($assessment) { + if (isset($assessment->generalcomment)) { + echo text_to_html($assessment->generalcomment); + } + } + else { + print_string("yourfeedbackgoeshere", "exercise"); + } + } + + echo " 
cellheading2\"> 
".get_string("gradeforstudentsassessment", "exercise", $course->student). + "\n"; + // set up coment scale + for ($i=COMMENTSCALE; $i>=0; $i--) { + $num[$i] = $i; + } + choose_from_menu($num, "gradinggrade", $assessment->gradinggrade, ""); + echo "

". get_string("teacherscomment", "exercise").":

\n"; + echo "\n"; + echo "

". get_string("teacherscomment", "exercise").":

\n"; + echo text_to_html($assessment->teachercomment); + echo " 
cellheading2\"> 

\n"; + if ($assessment and $allowchanges) { + if (isteacher($course->id)) { + // ...show two buttons...to resubmit or not to resubmit + echo "student)."\" + onclick=\"document.assessmentform.submit();\">\n"; + echo "student)."\" + onclick=\"document.assessmentform.resubmit.value='1';document.assessmentform.submit();\">\n"; + } + else { + // ... show save button + echo "\n"; + } + } + echo "
\n"; + } + + + +/////////////////////////////////////////////////////////////////////////////////////////////// +function exercise_print_assessments_by_user_for_admin($exercise, $user) { + + if (! $course = get_record("course", "id", $exercise->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + if ($assessments =exercise_get_user_assessments($exercise, $user)) { + foreach ($assessments as $assessment) { + echo "

".get_string("assessmentby", "exercise", $user->firstname." ".$user->lastname)."

\n"; + exercise_print_assessment_form($exercise, $assessment); + echo "

id&aid=$assessment->id\">". + get_string("amend", "exercise")." ".get_string("gradeforstudentsassessment","exercise", + $course->student)."\n"; + echo " | id&aid=$assessment->id\">". + get_string("delete", "exercise")."


\n"; + } + } + } + + +/////////////////////////////////////////////////////////////////////////////////////////////// +function exercise_print_assessments_for_admin($exercise, $submission) { + + if (! $course = get_record("course", "id", $exercise->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + if ($assessments =exercise_get_assessments($submission)) { + foreach ($assessments as $assessment) { + if (!$user = get_record("user", "id", $assessment->userid)) { + error (" exercise_print_assessments_for_admin: unable to get user record"); + } + echo "

".get_string("assessmentby", "exercise", $user->firstname." ".$user->lastname)."

\n"; + exercise_print_assessment_form($exercise, $assessment); + echo "

id&aid=$assessment->id\">". + get_string("delete", "exercise")."


\n"; + } + } + } + + +/////////////////////////////////////////////////////////////////////////////////////////////// +function exercise_print_assignment_info($exercise) { + + if (! $course = get_record("course", "id", $exercise->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { + error("Course Module ID was incorrect"); + } + // print standard assignment heading + $strdifference = format_time($exercise->deadline - time()); + if (($exercise->deadline - time()) < 0) { + $strdifference = "$strdifference"; + } + $strduedate = userdate($exercise->deadline)." ($strdifference)"; + print_simple_box_start("center"); + print_heading($exercise->name, "center"); + print_simple_box_start("center"); + echo "".get_string("duedate", "exercise").": $strduedate
"; + echo "".get_string("maximumgrade").": $exercise->grade
"; + echo "".get_string("handlingofmultiplesubmissions", "exercise").":"; + if ($exercise->usemaximum) { + echo get_string("usemaximum", "exercise")."
\n"; + } + else { + echo get_string("usemean", "exercise")."
\n"; + } + echo "".get_string("detailsofassessment", "exercise").": + id&action=displaygradingform\">". + get_string("specimenassessmentform", "exercise")."
"; + print_simple_box_end(); + print_simple_box_end(); + echo "
"; +} + + +/////////////////////////////////////////////////////////////////////////////////////////////// +function exercise_print_difference($time) { + if ($time < 0) { + $timetext = get_string("late", "assignment", format_time($time)); + return " ($timetext)"; + } else { + $timetext = get_string("early", "assignment", format_time($time)); return " ($timetext)"; } } @@ -2696,899 +2721,899 @@ function exercise_print_difference($time) { /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_print_dual_assessment_form($exercise, $assessment, $submission, $returnto = '') { - // prints the user's assessment and a blank form for the user's submission (for teachers only) - global $CFG, $THEME, $USER, $EXERCISE_SCALES, $EXERCISE_EWEIGHTS; - - if (! $course = get_record("course", "id", $exercise->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { - error("Course Module ID was incorrect"); - } - - $timenow = time(); - - if(!$submissionowner = get_record("user", "id", $submission->userid)) { - error("Print dual assessment form: User record not found"); - } - - echo "
-
cellcontent\">\n"; - if (!$teachersubmission = get_record("exercise_submissions", "id", $assessment->submissionid)) { - error ("exercise_print_assessment_form: Submission record not found"); - } - echo exercise_print_submission_title($exercise, $teachersubmission); - echo "

\n"; - - print_heading_with_help(get_string("pleasegradetheassessment", "exercise", - "$submissionowner->firstname $submissionowner->lastname"), "gradinggrade", "exercise"); - - echo "
-
cellcontent\">\n"; - echo exercise_print_submission_title($exercise, $submission); - echo "

\n"; - - // only show the grade if grading strategy > 0 and the grade is positive - if ($exercise->gradingstrategy and $assessment->grade >= 0) { - echo "
".get_string("thegradeis", "exercise").": ". - number_format($assessment->grade * $exercise->grade / 100.0, 2)." (". - get_string("maximumgrade")." ".number_format($exercise->grade, 0).")

\n"; - } - - // now print the student's assessment form with the teacher's comments if any - // in this (first) form only allow teachers to change their comment and the grading grade - // the other "active" elements in thie form are suffixed with "_0" to stop conflicts with the teacher's - // assessment form - $allowchanges = false; - - // FORM is needed for Mozilla browsers, else radio bttons are not checked - ?> -
- - - - - - - userid)) { - error("Exercise_print_dual_assessment_form: could not find user record"); - } - echo "
\n"; - echo "\n"; - echo " \n"; - echo "\n"; - - // get the assignment elements... - if (!$elementsraw = get_records("exercise_elements", "exerciseid", $exercise->id, "elementno ASC")) { - print_string("noteonassignmentelements", "exercise"); - } - else { - foreach ($elementsraw as $element) { - $elements[] = $element; // to renumber index 0,1,2... - } - } - - // get any previous grades... - if ($gradesraw = get_records_select("exercise_grades", "assessmentid = $assessment->id", "elementno")) { - foreach ($gradesraw as $grade) { - $grades[] = $grade; // to renumber index 0,1,2... - } - } - - // determine what sort of grading - switch ($exercise->gradingstrategy) { - case 0: // no grading - // now print the form - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - } - break; - - case 1: // accumulative grading - // now print the form - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - } - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - } - break; - - case 2: // error banded grading - // now run through the elements - $error = 0; - for ($i=0; $i < count($elements) - 1; $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - if (empty($grades[$i]->grade)) { - $error += $EXERCISE_EWEIGHTS[$elements[$i]->weight]; - } - } - // print the number of negative elements - // echo "\n"; - // echo "\n"; - // echo " \n"; - echo "
cellheading2\">
".get_string("assessmentby", - "exercise", "$assessmentowner->firstname $assessmentowner->lastname")."

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); - echo "

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - echo text_to_html($grades[$i]->feedback); - } - echo "
cellheading2\"> 

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); - echo "

Weight: " - .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."\n"; - echo "

". get_string("grade"). ":

\n"; - - // get the appropriate scale - $scalenumber=$elements[$i]->scale; - $SCALE = (object)$EXERCISE_SCALES[$scalenumber]; - switch ($SCALE->type) { - case 'radio' : - // show selections highest first - echo "
$SCALE->start   "; - for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { - $checked = false; - if (isset($grades[$i]->grade)) { - if ($j == $grades[$i]->grade) { - $checked = true; - } - } - else { // there's no previous grade so check the lowest option - if ($j == 0) { - $checked = true; - } - } - if ($checked) { - echo "    \n"; - } - else { - echo "    \n"; - } - } - echo "   $SCALE->end
\n"; - break; - case 'selection' : - unset($numbers); - for ($j = $SCALE->size; $j >= 0; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[$i]->grade)) { - choose_from_menu($numbers, "grade2_0[$i]", $grades[$i]->grade, ""); - } - else { - choose_from_menu($numbers, "grade2_0[$i]", 0, ""); - } - break; - - echo "

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - echo text_to_html($grades[$i]->feedback); - } - echo "
cellheading2\"> 

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); - echo "

Weight: " - .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."\n"; - echo "

". get_string("grade"). ":

\n"; - - // get the appropriate scale - yes/no scale (0) - $SCALE = (object) $EXERCISE_SCALES[0]; - switch ($SCALE->type) { - case 'radio' : - // show selections highest first - echo "
$SCALE->start   "; - for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { - $checked = false; - if (isset($grades[$i]->grade)) { - if ($j == $grades[$i]->grade) { - $checked = true; - } - } - else { // there's no previous grade so check the lowest option - if ($j == 0) { - $checked = true; - } - } - if ($checked) { - echo "    \n"; - } - else { - echo "    \n"; - } - } - echo "   $SCALE->end
\n"; - break; - case 'selection' : - unset($numbers); - for ($j = $SCALE->size; $j >= 0; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[$i]->grade)) { - choose_from_menu($numbers, "grade_0[$i]", $grades[$i]->grade, ""); - } - else { - choose_from_menu($numbers, "grade_0[$i]", 0, ""); - } - break; - } - - echo "

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - if (isset($grades[$i]->feedback)) { - echo text_to_html($grades[$i]->feedback); - } - } - echo " 
cellheading2\"> 
".get_string("numberofnegativeitems", "exercise")."$negativecount
cellheading2\"> 
\n"; - // now print the grade table - echo "

".get_string("gradetable","exercise")."
\n"; - echo "
\n"; - for ($i=0; $i<=$exercise->nelements; $i++) { - if ($i == intval($error + 0.5)) { - echo "\n"; - } - else { - echo "\n"; - } - } - echo "
". - get_string("numberofnegativeresponses", "exercise"); - echo "". get_string("suggestedgrade", "exercise")."
pixpath/t/right.gif\"> $i{$elements[$i]->maxscore}
$i{$elements[$i]->maxscore}
\n"; - echo "

\n"; - break; - - case 3: // criteria grading - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - // find which criteria has been selected (saved in the zero element), if any - if (isset($grades[0]->grade)) { - $selection = $grades[0]->grade; - } - else { - $selection = 0; - } - // now run through the elements - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - if ($selection == $i) { - echo " \n"; - } - else { - echo " \n"; - } - echo "\n"; - } - echo "
". - get_string("optionaladjustment", "exercise")."\n"; - unset($numbers); - for ($j = 20; $j >= -20; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[$exercise->nelements]->grade)) { - choose_from_menu($numbers, "grade_0[$exercise->nelements]", $grades[$exercise->nelements]->grade, ""); - } - else { - choose_from_menu($numbers, "grade_0[$exercise->nelements]", 0, ""); - } - echo "
cellheading2\"> cellheading2\">". get_string("criterion","exercise")."cellheading2\">".get_string("select", "exercise")."cellheading2\">".get_string("suggestedgrade", "exercise")."
$iplus1".text_to_html($elements[$i]->description)."{$elements[$i]->maxscore}
\n"; - echo "

\n"; - break; - - case 4: // rubric grading - // now run through the elements... - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - if (isset($grades[$i])) { - $selection = $grades[$i]->grade; - } else { - $selection = 0; - } - // ...and the rubrics - if ($rubricsraw = get_records_select("exercise_rubrics", "exerciseid = $exercise->id AND - elementno = $i", "rubricno ASC")) { - unset($rubrics); - foreach ($rubricsraw as $rubic) { - $rubrics[] = $rubic; // to renumber index 0,1,2... - } - for ($j=0; $j<5; $j++) { - if (empty($rubrics[$j]->description)) { - break; // out of inner for loop - } - echo "\n"; - if ($selection == $j) { - echo " \n"; - }else { - echo " \n"; - } - echo "\n"; - } - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - } - } - break; - } // end of outer switch - - // now get the general comment (present in all types) - echo "\n"; - switch ($exercise->gradingstrategy) { - case 0: - case 1: - case 4 : // no grading, accumulative and rubic - echo " \n"; - break; - default : - echo " \n"; - } - echo " \n"; - echo "
". - get_string("optionaladjustment", "exercise")."\n"; - unset($numbers); - for ($j = 20; $j >= -20; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[1]->grade)) { - choose_from_menu($numbers, "grade_0[1]", $grades[1]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[1]", 0, ""); - } - echo "
".get_string("element", "exercise")." $iplus1:".text_to_html($elements[$i]->description). - "

Weight: " - .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."

cellheading2\" align=\"center\">".get_string("select", "exercise")."cellheading2\">". get_string("criterion","exercise")."
".text_to_html($rubrics[$j]->description)."

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - echo text_to_html($grades[$i]->feedback); - } - echo "
cellheading2\"> 

". get_string("generalcomment", "exercise").":

". get_string("reasonforadjustment", "exercise").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - if ($assessment) { - if (isset($assessment->generalcomment)) { - echo text_to_html($assessment->generalcomment); - } - } - else { - print_string("yourfeedbackgoeshere", "exercise"); - } - } - echo " 
\n"; - - // the teacher's comment on the assessment - // always allow the teacher to change/add their comment and grade if it's not their assessment! - echo "

\n"; - if (isteacher($course->id) and ($assessment->userid != $USER->id)) { - echo "\n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - } - elseif ($assessment->timegraded and (($timenow - $assessment->timegraded) > $CFG->maxeditingtime)) { - // now show the teacher's comment (but not the grade) to the student if available... - echo "\n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - } - // ...and close the table - echo "
cellheading2\" align=\"center\">". - get_string("pleasegradetheassessment", "exercise", "$submissionowner->firstname $submissionowner->lastname"). - "
".get_string("gradeforstudentsassessment", "exercise", $course->student). - "\n"; - // set up coment scale - for ($i=COMMENTSCALE; $i>=0; $i--) { - $num[$i] = $i; - } - choose_from_menu($num, "gradinggrade", $assessment->gradinggrade, ""); - echo "

". get_string("teacherscomment", "exercise").":

\n"; - echo "\n"; - echo "
cellheading2\"> 

". get_string("teacherscomment", "exercise", $course->teacher).":

\n"; - echo text_to_html($assessment->teachercomment); - echo " 
cellheading2\"> 


\n"; - - // ****************************second form****************************************** - // now print a normal assessment form based on the student's assessment for this submission - // and allow the teacher to grade and add comments - $studentassessment = $assessment; - $allowchanges = true; - - print_heading_with_help(get_string("nowpleasemakeyourownassessment", "exercise", - "$submissionowner->firstname $submissionowner->lastname"), "grading", "exercise"); - - // is there an existing assessment for the submission - if (!$assessment = exercise_get_submission_assessment($submission, $USER)) { - // copy student's assessment without the comments for the student's submission - $assessment = exercise_copy_assessment($studentassessment, $submission); - } - - // only show the grade if grading strategy > 0 and the grade is positive - if ($exercise->gradingstrategy and $assessment->grade >= 0) { - echo "
".get_string("thegradeis", "exercise").": ". - number_format($assessment->grade * $exercise->grade / 100.0, 2)." (". - get_string("maximumgrade")." ".number_format($exercise->grade, 0).")

\n"; - } - - echo "
\n"; - echo "\n"; - echo " \n"; - echo "\n"; - - - unset($grades); - // get any previous grades... - if ($gradesraw = get_records_select("exercise_grades", "assessmentid = $assessment->id", "elementno")) { - foreach ($gradesraw as $grade) { - $grades[] = $grade; // to renumber index 0,1,2... - } - } - - // determine what sort of grading - switch ($exercise->gradingstrategy) { - case 0: // no grading - // now print the form - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - } - break; - - case 1: // accumulative grading - // now print the form - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - } - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - } - break; - - case 2: // error banded grading - // now run through the elements - $error = 0; - for ($i=0; $i < count($elements) - 1; $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - if (empty($grades[$i]->grade)) { - $error += $EXERCISE_EWEIGHTS[$elements[$i]->weight]; - } - } - // print the number of negative elements - // echo "\n"; - // echo "\n"; - // echo " \n"; - echo "
cellheading2\">
".get_string("yourassessment", "exercise"). - "

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); - echo "

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - echo text_to_html($grades[$i]->feedback); - } - echo "
cellheading2\"> 

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); - echo "

Weight: " - .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."\n"; - echo "

". get_string("grade"). ":

\n"; - - // get the appropriate scale - $scalenumber=$elements[$i]->scale; - $SCALE = (object)$EXERCISE_SCALES[$scalenumber]; - switch ($SCALE->type) { - case 'radio' : - // show selections highest first - echo "
$SCALE->start   "; - for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { - $checked = false; - if (isset($grades[$i]->grade)) { - if ($j == $grades[$i]->grade) { - $checked = true; - } - } - else { // there's no previous grade so check the lowest option - if ($j == 0) { - $checked = true; - } - } - if ($checked) { - echo "    \n"; - } - else { - echo "    \n"; - } - } - echo "   $SCALE->end
\n"; - break; - case 'selection' : - unset($numbers); - for ($j = $SCALE->size; $j >= 0; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[$i]->grade)) { - choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[$i]", 0, ""); - } - break; - - echo "

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - echo text_to_html($grades[$i]->feedback); - } - echo "
cellheading2\"> 

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); - echo "

Weight: " - .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."\n"; - echo "

". get_string("grade"). ":

\n"; - - // get the appropriate scale - yes/no scale (0) - $SCALE = (object) $EXERCISE_SCALES[0]; - switch ($SCALE->type) { - case 'radio' : - // show selections highest first - echo "
$SCALE->start   "; - for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { - $checked = false; - if (isset($grades[$i]->grade)) { - if ($j == $grades[$i]->grade) { - $checked = true; - } - } - else { // there's no previous grade so check the lowest option - if ($j == 0) { - $checked = true; - } - } - if ($checked) { - echo "    \n"; - } - else { - echo "    \n"; - } - } - echo "   $SCALE->end
\n"; - break; - case 'selection' : - unset($numbers); - for ($j = $SCALE->size; $j >= 0; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[$i]->grade)) { - choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[$i]", 0, ""); - } - break; - } - - echo "

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - if (isset($grades[$i]->feedback)) { - echo text_to_html($grades[$i]->feedback); - } - } - echo " 
cellheading2\"> 
".get_string("numberofnegativeitems", "exercise")."$negativecount
cellheading2\"> 
\n"; - // now print the grade table - echo "

".get_string("gradetable","exercise")."
\n"; - echo "
\n"; - for ($i=0; $i<=$exercise->nelements; $i++) { - if ($i == intval($error + 0.5)) { - echo "\n"; - } - else { - echo "\n"; - } - } - echo "
". - get_string("numberofnegativeresponses", "exercise"); - echo "". get_string("suggestedgrade", "exercise")."
pixpath/t/right.gif\"> $i{$elements[$i]->maxscore}
$i{$elements[$i]->maxscore}
\n"; - echo "

\n"; - break; - - case 3: // criteria grading - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - // find which criteria has been selected (saved in the zero element), if any - if (isset($grades[0]->grade)) { - $selection = $grades[0]->grade; - } - else { - $selection = 0; - } - // now run through the elements - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - if ($selection == $i) { - echo " \n"; - } - else { - echo " \n"; - } - echo "\n"; - } - echo "
". - get_string("optionaladjustment", "exercise")."\n"; - unset($numbers); - for ($j = 20; $j >= -20; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[$exercise->nelements]->grade)) { - choose_from_menu($numbers, "grade[$exercise->nelements]", $grades[$exercise->nelements]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[$exercise->nelements]", 0, ""); - } - echo "
cellheading2\"> cellheading2\">". get_string("criterion","exercise")."cellheading2\">".get_string("select", "exercise")."cellheading2\">".get_string("suggestedgrade", "exercise")."
$iplus1".text_to_html($elements[$i]->description)."{$elements[$i]->maxscore}
\n"; - echo "

\n"; - break; - - case 4: // rubric grading - // now run through the elements... - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - if (isset($grades[$i])) { - $selection = $grades[$i]->grade; - } else { - $selection = 0; - } - // ...and the rubrics - if ($rubricsraw = get_records_select("exercise_rubrics", "exerciseid = $exercise->id AND - elementno = $i", "rubricno ASC")) { - unset($rubrics); - foreach ($rubricsraw as $rubic) { - $rubrics[] = $rubic; // to renumber index 0,1,2... - } - for ($j=0; $j<5; $j++) { - if (empty($rubrics[$j]->description)) { - break; // out of inner for loop - } - echo "\n"; - if ($selection == $j) { - echo " \n"; - }else { - echo " \n"; - } - echo "\n"; - } - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - } - } - break; - } // end of outer switch - - // now get the general comment (present in all types) - echo "\n"; - switch ($exercise->gradingstrategy) { - case 0: - case 1: - case 4 : // no grading, accumulative and rubic - echo " \n"; - break; - default : - echo " \n"; - } - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - - // ...and close the table and show two buttons...to resubmit or not to resubmit - echo "
". - get_string("optionaladjustment", "exercise")."\n"; - unset($numbers); - for ($j = 20; $j >= -20; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[1]->grade)) { - choose_from_menu($numbers, "grade[1]", $grades[1]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[1]", 0, ""); - } - echo "
".get_string("element", "exercise")." $iplus1:".text_to_html($elements[$i]->description). - "

Weight: " - .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."

cellheading2\" align=\"center\">".get_string("select", "exercise")."cellheading2\">". get_string("criterion","exercise")."
".text_to_html($rubrics[$j]->description)."

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - echo text_to_html($grades[$i]->feedback); - } - echo "
cellheading2\"> 

". get_string("generalcomment", "exercise").":

". get_string("reasonforadjustment", "exercise").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - if ($assessment) { - if (isset($assessment->generalcomment)) { - echo text_to_html($assessment->generalcomment); - } - } - else { - print_string("yourfeedbackgoeshere", "exercise"); - } - } - echo " 
cellheading2\"> 
\n"; - echo "
student)."\" - onclick=\"document.assessmentform.submit();\">\n"; - echo "student)."\" - onclick=\"document.assessmentform.resubmit.value='1';document.assessmentform.submit();\">\n"; - echo "
\n"; - } + // prints the user's assessment and a blank form for the user's submission (for teachers only) + global $CFG, $THEME, $USER, $EXERCISE_SCALES, $EXERCISE_EWEIGHTS; + + if (! $course = get_record("course", "id", $exercise->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + $timenow = time(); + + if(!$submissionowner = get_record("user", "id", $submission->userid)) { + error("Print dual assessment form: User record not found"); + } + + echo "
+
cellcontent\">\n"; + if (!$teachersubmission = get_record("exercise_submissions", "id", $assessment->submissionid)) { + error ("exercise_print_assessment_form: Submission record not found"); + } + echo exercise_print_submission_title($exercise, $teachersubmission); + echo "

\n"; + + print_heading_with_help(get_string("pleasegradetheassessment", "exercise", + "$submissionowner->firstname $submissionowner->lastname"), "gradinggrade", "exercise"); + + echo "
+
cellcontent\">\n"; + echo exercise_print_submission_title($exercise, $submission); + echo "

\n"; + + // only show the grade if grading strategy > 0 and the grade is positive + if ($exercise->gradingstrategy and $assessment->grade >= 0) { + echo "
".get_string("thegradeis", "exercise").": ". + number_format($assessment->grade * $exercise->grade / 100.0, 2)." (". + get_string("maximumgrade")." ".number_format($exercise->grade, 0).")

\n"; + } + + // now print the student's assessment form with the teacher's comments if any + // in this (first) form only allow teachers to change their comment and the grading grade + // the other "active" elements in thie form are suffixed with "_0" to stop conflicts with the teacher's + // assessment form + $allowchanges = false; + + // FORM is needed for Mozilla browsers, else radio bttons are not checked + ?> +
+ + + + + + + userid)) { + error("Exercise_print_dual_assessment_form: could not find user record"); + } + echo "
\n"; + echo "\n"; + echo " \n"; + echo "\n"; + + // get the assignment elements... + if (!$elementsraw = get_records("exercise_elements", "exerciseid", $exercise->id, "elementno ASC")) { + print_string("noteonassignmentelements", "exercise"); + } + else { + foreach ($elementsraw as $element) { + $elements[] = $element; // to renumber index 0,1,2... + } + } + + // get any previous grades... + if ($gradesraw = get_records_select("exercise_grades", "assessmentid = $assessment->id", "elementno")) { + foreach ($gradesraw as $grade) { + $grades[] = $grade; // to renumber index 0,1,2... + } + } + + // determine what sort of grading + switch ($exercise->gradingstrategy) { + case 0: // no grading + // now print the form + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + } + break; + + case 1: // accumulative grading + // now print the form + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + } + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + } + break; + + case 2: // error banded grading + // now run through the elements + $error = 0; + for ($i=0; $i < count($elements) - 1; $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + if (empty($grades[$i]->grade)) { + $error += $EXERCISE_EWEIGHTS[$elements[$i]->weight]; + } + } + // print the number of negative elements + // echo "\n"; + // echo "\n"; + // echo " \n"; + echo "
cellheading2\">
".get_string("assessmentby", + "exercise", "$assessmentowner->firstname $assessmentowner->lastname")."

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); + echo "

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + echo text_to_html($grades[$i]->feedback); + } + echo "
cellheading2\"> 

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); + echo "

Weight: " + .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."\n"; + echo "

". get_string("grade"). ":

\n"; + + // get the appropriate scale + $scalenumber=$elements[$i]->scale; + $SCALE = (object)$EXERCISE_SCALES[$scalenumber]; + switch ($SCALE->type) { + case 'radio' : + // show selections highest first + echo "
$SCALE->start   "; + for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { + $checked = false; + if (isset($grades[$i]->grade)) { + if ($j == $grades[$i]->grade) { + $checked = true; + } + } + else { // there's no previous grade so check the lowest option + if ($j == 0) { + $checked = true; + } + } + if ($checked) { + echo "    \n"; + } + else { + echo "    \n"; + } + } + echo "   $SCALE->end
\n"; + break; + case 'selection' : + unset($numbers); + for ($j = $SCALE->size; $j >= 0; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[$i]->grade)) { + choose_from_menu($numbers, "grade2_0[$i]", $grades[$i]->grade, ""); + } + else { + choose_from_menu($numbers, "grade2_0[$i]", 0, ""); + } + break; + + echo "

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + echo text_to_html($grades[$i]->feedback); + } + echo "
cellheading2\"> 

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); + echo "

Weight: " + .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."\n"; + echo "

". get_string("grade"). ":

\n"; + + // get the appropriate scale - yes/no scale (0) + $SCALE = (object) $EXERCISE_SCALES[0]; + switch ($SCALE->type) { + case 'radio' : + // show selections highest first + echo "
$SCALE->start   "; + for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { + $checked = false; + if (isset($grades[$i]->grade)) { + if ($j == $grades[$i]->grade) { + $checked = true; + } + } + else { // there's no previous grade so check the lowest option + if ($j == 0) { + $checked = true; + } + } + if ($checked) { + echo "    \n"; + } + else { + echo "    \n"; + } + } + echo "   $SCALE->end
\n"; + break; + case 'selection' : + unset($numbers); + for ($j = $SCALE->size; $j >= 0; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[$i]->grade)) { + choose_from_menu($numbers, "grade_0[$i]", $grades[$i]->grade, ""); + } + else { + choose_from_menu($numbers, "grade_0[$i]", 0, ""); + } + break; + } + + echo "

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + if (isset($grades[$i]->feedback)) { + echo text_to_html($grades[$i]->feedback); + } + } + echo " 
cellheading2\"> 
".get_string("numberofnegativeitems", "exercise")."$negativecount
cellheading2\"> 
\n"; + // now print the grade table + echo "

".get_string("gradetable","exercise")."
\n"; + echo "
\n"; + for ($i=0; $i<=$exercise->nelements; $i++) { + if ($i == intval($error + 0.5)) { + echo "\n"; + } + else { + echo "\n"; + } + } + echo "
". + get_string("numberofnegativeresponses", "exercise"); + echo "". get_string("suggestedgrade", "exercise")."
pixpath/t/right.gif\"> $i{$elements[$i]->maxscore}
$i{$elements[$i]->maxscore}
\n"; + echo "

\n"; + break; + + case 3: // criteria grading + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + // find which criteria has been selected (saved in the zero element), if any + if (isset($grades[0]->grade)) { + $selection = $grades[0]->grade; + } + else { + $selection = 0; + } + // now run through the elements + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + if ($selection == $i) { + echo " \n"; + } + else { + echo " \n"; + } + echo "\n"; + } + echo "
". + get_string("optionaladjustment", "exercise")."\n"; + unset($numbers); + for ($j = 20; $j >= -20; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[$exercise->nelements]->grade)) { + choose_from_menu($numbers, "grade_0[$exercise->nelements]", $grades[$exercise->nelements]->grade, ""); + } + else { + choose_from_menu($numbers, "grade_0[$exercise->nelements]", 0, ""); + } + echo "
cellheading2\"> cellheading2\">". get_string("criterion","exercise")."cellheading2\">".get_string("select", "exercise")."cellheading2\">".get_string("suggestedgrade", "exercise")."
$iplus1".text_to_html($elements[$i]->description)."{$elements[$i]->maxscore}
\n"; + echo "

\n"; + break; + + case 4: // rubric grading + // now run through the elements... + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + if (isset($grades[$i])) { + $selection = $grades[$i]->grade; + } else { + $selection = 0; + } + // ...and the rubrics + if ($rubricsraw = get_records_select("exercise_rubrics", "exerciseid = $exercise->id AND + elementno = $i", "rubricno ASC")) { + unset($rubrics); + foreach ($rubricsraw as $rubic) { + $rubrics[] = $rubic; // to renumber index 0,1,2... + } + for ($j=0; $j<5; $j++) { + if (empty($rubrics[$j]->description)) { + break; // out of inner for loop + } + echo "\n"; + if ($selection == $j) { + echo " \n"; + }else { + echo " \n"; + } + echo "\n"; + } + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + } + } + break; + } // end of outer switch + + // now get the general comment (present in all types) + echo "\n"; + switch ($exercise->gradingstrategy) { + case 0: + case 1: + case 4 : // no grading, accumulative and rubic + echo " \n"; + break; + default : + echo " \n"; + } + echo " \n"; + echo "
". + get_string("optionaladjustment", "exercise")."\n"; + unset($numbers); + for ($j = 20; $j >= -20; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[1]->grade)) { + choose_from_menu($numbers, "grade_0[1]", $grades[1]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[1]", 0, ""); + } + echo "
".get_string("element", "exercise")." $iplus1:".text_to_html($elements[$i]->description). + "

Weight: " + .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."

cellheading2\" align=\"center\">".get_string("select", "exercise")."cellheading2\">". get_string("criterion","exercise")."
".text_to_html($rubrics[$j]->description)."

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + echo text_to_html($grades[$i]->feedback); + } + echo "
cellheading2\"> 

". get_string("generalcomment", "exercise").":

". get_string("reasonforadjustment", "exercise").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + if ($assessment) { + if (isset($assessment->generalcomment)) { + echo text_to_html($assessment->generalcomment); + } + } + else { + print_string("yourfeedbackgoeshere", "exercise"); + } + } + echo " 
\n"; + + // the teacher's comment on the assessment + // always allow the teacher to change/add their comment and grade if it's not their assessment! + echo "

\n"; + if (isteacher($course->id) and ($assessment->userid != $USER->id)) { + echo "\n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + } + elseif ($assessment->timegraded and (($timenow - $assessment->timegraded) > $CFG->maxeditingtime)) { + // now show the teacher's comment (but not the grade) to the student if available... + echo "\n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + // ...and close the table + echo "
cellheading2\" align=\"center\">". + get_string("pleasegradetheassessment", "exercise", "$submissionowner->firstname $submissionowner->lastname"). + "
".get_string("gradeforstudentsassessment", "exercise", $course->student). + "\n"; + // set up coment scale + for ($i=COMMENTSCALE; $i>=0; $i--) { + $num[$i] = $i; + } + choose_from_menu($num, "gradinggrade", $assessment->gradinggrade, ""); + echo "

". get_string("teacherscomment", "exercise").":

\n"; + echo "\n"; + echo "
cellheading2\"> 

". get_string("teacherscomment", "exercise", $course->teacher).":

\n"; + echo text_to_html($assessment->teachercomment); + echo " 
cellheading2\"> 


\n"; + + // ****************************second form****************************************** + // now print a normal assessment form based on the student's assessment for this submission + // and allow the teacher to grade and add comments + $studentassessment = $assessment; + $allowchanges = true; + + print_heading_with_help(get_string("nowpleasemakeyourownassessment", "exercise", + "$submissionowner->firstname $submissionowner->lastname"), "grading", "exercise"); + + // is there an existing assessment for the submission + if (!$assessment = exercise_get_submission_assessment($submission, $USER)) { + // copy student's assessment without the comments for the student's submission + $assessment = exercise_copy_assessment($studentassessment, $submission); + } + + // only show the grade if grading strategy > 0 and the grade is positive + if ($exercise->gradingstrategy and $assessment->grade >= 0) { + echo "
".get_string("thegradeis", "exercise").": ". + number_format($assessment->grade * $exercise->grade / 100.0, 2)." (". + get_string("maximumgrade")." ".number_format($exercise->grade, 0).")

\n"; + } + + echo "
\n"; + echo "\n"; + echo " \n"; + echo "\n"; + + + unset($grades); + // get any previous grades... + if ($gradesraw = get_records_select("exercise_grades", "assessmentid = $assessment->id", "elementno")) { + foreach ($gradesraw as $grade) { + $grades[] = $grade; // to renumber index 0,1,2... + } + } + + // determine what sort of grading + switch ($exercise->gradingstrategy) { + case 0: // no grading + // now print the form + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + } + break; + + case 1: // accumulative grading + // now print the form + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + } + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + } + break; + + case 2: // error banded grading + // now run through the elements + $error = 0; + for ($i=0; $i < count($elements) - 1; $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + if (empty($grades[$i]->grade)) { + $error += $EXERCISE_EWEIGHTS[$elements[$i]->weight]; + } + } + // print the number of negative elements + // echo "\n"; + // echo "\n"; + // echo " \n"; + echo "
cellheading2\">
".get_string("yourassessment", "exercise"). + "

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); + echo "

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + echo text_to_html($grades[$i]->feedback); + } + echo "
cellheading2\"> 

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); + echo "

Weight: " + .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."\n"; + echo "

". get_string("grade"). ":

\n"; + + // get the appropriate scale + $scalenumber=$elements[$i]->scale; + $SCALE = (object)$EXERCISE_SCALES[$scalenumber]; + switch ($SCALE->type) { + case 'radio' : + // show selections highest first + echo "
$SCALE->start   "; + for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { + $checked = false; + if (isset($grades[$i]->grade)) { + if ($j == $grades[$i]->grade) { + $checked = true; + } + } + else { // there's no previous grade so check the lowest option + if ($j == 0) { + $checked = true; + } + } + if ($checked) { + echo "    \n"; + } + else { + echo "    \n"; + } + } + echo "   $SCALE->end
\n"; + break; + case 'selection' : + unset($numbers); + for ($j = $SCALE->size; $j >= 0; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[$i]->grade)) { + choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[$i]", 0, ""); + } + break; + + echo "

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + echo text_to_html($grades[$i]->feedback); + } + echo "
cellheading2\"> 

". get_string("element","exercise")." $iplus1:

".text_to_html($elements[$i]->description); + echo "

Weight: " + .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."\n"; + echo "

". get_string("grade"). ":

\n"; + + // get the appropriate scale - yes/no scale (0) + $SCALE = (object) $EXERCISE_SCALES[0]; + switch ($SCALE->type) { + case 'radio' : + // show selections highest first + echo "
$SCALE->start   "; + for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { + $checked = false; + if (isset($grades[$i]->grade)) { + if ($j == $grades[$i]->grade) { + $checked = true; + } + } + else { // there's no previous grade so check the lowest option + if ($j == 0) { + $checked = true; + } + } + if ($checked) { + echo "    \n"; + } + else { + echo "    \n"; + } + } + echo "   $SCALE->end
\n"; + break; + case 'selection' : + unset($numbers); + for ($j = $SCALE->size; $j >= 0; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[$i]->grade)) { + choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[$i]", 0, ""); + } + break; + } + + echo "

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + if (isset($grades[$i]->feedback)) { + echo text_to_html($grades[$i]->feedback); + } + } + echo " 
cellheading2\"> 
".get_string("numberofnegativeitems", "exercise")."$negativecount
cellheading2\"> 
\n"; + // now print the grade table + echo "

".get_string("gradetable","exercise")."
\n"; + echo "
\n"; + for ($i=0; $i<=$exercise->nelements; $i++) { + if ($i == intval($error + 0.5)) { + echo "\n"; + } + else { + echo "\n"; + } + } + echo "
". + get_string("numberofnegativeresponses", "exercise"); + echo "". get_string("suggestedgrade", "exercise")."
pixpath/t/right.gif\"> $i{$elements[$i]->maxscore}
$i{$elements[$i]->maxscore}
\n"; + echo "

\n"; + break; + + case 3: // criteria grading + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + // find which criteria has been selected (saved in the zero element), if any + if (isset($grades[0]->grade)) { + $selection = $grades[0]->grade; + } + else { + $selection = 0; + } + // now run through the elements + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + if ($selection == $i) { + echo " \n"; + } + else { + echo " \n"; + } + echo "\n"; + } + echo "
". + get_string("optionaladjustment", "exercise")."\n"; + unset($numbers); + for ($j = 20; $j >= -20; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[$exercise->nelements]->grade)) { + choose_from_menu($numbers, "grade[$exercise->nelements]", $grades[$exercise->nelements]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[$exercise->nelements]", 0, ""); + } + echo "
cellheading2\"> cellheading2\">". get_string("criterion","exercise")."cellheading2\">".get_string("select", "exercise")."cellheading2\">".get_string("suggestedgrade", "exercise")."
$iplus1".text_to_html($elements[$i]->description)."{$elements[$i]->maxscore}
\n"; + echo "

\n"; + break; + + case 4: // rubric grading + // now run through the elements... + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + if (isset($grades[$i])) { + $selection = $grades[$i]->grade; + } else { + $selection = 0; + } + // ...and the rubrics + if ($rubricsraw = get_records_select("exercise_rubrics", "exerciseid = $exercise->id AND + elementno = $i", "rubricno ASC")) { + unset($rubrics); + foreach ($rubricsraw as $rubic) { + $rubrics[] = $rubic; // to renumber index 0,1,2... + } + for ($j=0; $j<5; $j++) { + if (empty($rubrics[$j]->description)) { + break; // out of inner for loop + } + echo "\n"; + if ($selection == $j) { + echo " \n"; + }else { + echo " \n"; + } + echo "\n"; + } + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + } + } + break; + } // end of outer switch + + // now get the general comment (present in all types) + echo "\n"; + switch ($exercise->gradingstrategy) { + case 0: + case 1: + case 4 : // no grading, accumulative and rubic + echo " \n"; + break; + default : + echo " \n"; + } + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + + // ...and close the table and show two buttons...to resubmit or not to resubmit + echo "
". + get_string("optionaladjustment", "exercise")."\n"; + unset($numbers); + for ($j = 20; $j >= -20; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[1]->grade)) { + choose_from_menu($numbers, "grade[1]", $grades[1]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[1]", 0, ""); + } + echo "
".get_string("element", "exercise")." $iplus1:".text_to_html($elements[$i]->description). + "

Weight: " + .number_format($EXERCISE_EWEIGHTS[$elements[$i]->weight], 2)."

cellheading2\" align=\"center\">".get_string("select", "exercise")."cellheading2\">". get_string("criterion","exercise")."
".text_to_html($rubrics[$j]->description)."

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + echo text_to_html($grades[$i]->feedback); + } + echo "
cellheading2\"> 

". get_string("generalcomment", "exercise").":

". get_string("reasonforadjustment", "exercise").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + if ($assessment) { + if (isset($assessment->generalcomment)) { + echo text_to_html($assessment->generalcomment); + } + } + else { + print_string("yourfeedbackgoeshere", "exercise"); + } + } + echo " 
cellheading2\"> 
\n"; + echo "
student)."\" + onclick=\"document.assessmentform.submit();\">\n"; + echo "student)."\" + onclick=\"document.assessmentform.resubmit.value='1';document.assessmentform.submit();\">\n"; + echo "
\n"; + } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -3628,17 +3653,17 @@ function exercise_print_feedback($course, $submission) { /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_print_league_table($exercise) { - // print an order table of (student) submissions in grade order, only print the student's best submission when - // there are multiple submissions - if (! $course = get_record("course", "id", $exercise->course)) { - error("Print league table: Course is misconfigured"); - } - $nentries = $exercise->showleaguetable; - if ($nentries == 99) { - $nentries = 999999; // a large number - } - - if ($exercise->anonymous and isstudent($course->id)) { + // print an order table of (student) submissions in grade order, only print the student's best submission when + // there are multiple submissions + if (! $course = get_record("course", "id", $exercise->course)) { + error("Print league table: Course is misconfigured"); + } + $nentries = $exercise->showleaguetable; + if ($nentries == 99) { + $nentries = 999999; // a large number + } + + if ($exercise->anonymous and isstudent($course->id)) { $table->head = array (get_string("title", "exercise"), get_string("grade")); $table->align = array ("left", "center"); $table->size = array ("*", "*"); @@ -3650,62 +3675,62 @@ function exercise_print_league_table($exercise) { $table->cellpadding = 2; $table->cellspacing = 0; - if ($submissions = exercise_get_student_submissions($exercise, "grade")) { + if ($submissions = exercise_get_student_submissions($exercise, "grade")) { $n = 1; - foreach ($submissions as $submission) { - if (empty($done[$submission->userid])) { + foreach ($submissions as $submission) { + if (empty($done[$submission->userid])) { if ($submission->late) { continue; } - if (!$user = get_record("user", "id", $submission->userid)) { - error("Print league table: user not found"); - } - if ($exercise->anonymous and isstudent($course->id)) { - $table->data[] = array(exercise_print_submission_title($exercise, $submission), + if (!$user = get_record("user", "id", $submission->userid)) { + error("Print league table: user not found"); + } + if ($exercise->anonymous and isstudent($course->id)) { + $table->data[] = array(exercise_print_submission_title($exercise, $submission), number_format($submission->grade * $exercise->grade / 100.0, 1)); } else { - $table->data[] = array(exercise_print_submission_title($exercise, $submission), + $table->data[] = array(exercise_print_submission_title($exercise, $submission), $user->firstname." ".$user->lastname, number_format($submission->grade * $exercise->grade / 100.0, 1)); } - $n++; + $n++; if ($n > $nentries) { break; } $done[$submission->userid] = 'ok'; - } - } - print_heading(get_string("leaguetable", "exercise")); - print_table($table); - } - } - + } + } + print_heading(get_string("leaguetable", "exercise")); + print_table($table); + } + } + /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_print_submission_assessments($exercise, $submission) { - // Returns a list of grades for this submission - - if (! $course = get_record("course", "id", $exercise->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { - error("Course Module ID was incorrect"); - } - - $str = ''; - if ($assessments = exercise_get_assessments($submission)) { - foreach ($assessments as $assessment) { - if (isteacher($exercise->course, $assessment->userid)) { - $str .= "[".number_format($assessment->grade * $exercise->grade / 100.0, 0)."] "; - } - else { // assessment by student - shouldn't happen! - $str .= "{".number_format($assessment->grade * $exercise->grade / 100.0, 0)."} "; - } - } - } - if (!$str) { - $str = " "; // be kind to Mozilla browsers! - } + // Returns a list of grades for this submission + + if (! $course = get_record("course", "id", $exercise->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + $str = ''; + if ($assessments = exercise_get_assessments($submission)) { + foreach ($assessments as $assessment) { + if (isteacher($exercise->course, $assessment->userid)) { + $str .= "[".number_format($assessment->grade * $exercise->grade / 100.0, 0)."] "; + } + else { // assessment by student - shouldn't happen! + $str .= "{".number_format($assessment->grade * $exercise->grade / 100.0, 0)."} "; + } + } + } + if (!$str) { + $str = " "; // be kind to Mozilla browsers! + } return $str; } @@ -3713,10 +3738,10 @@ function exercise_print_submission_assessments($exercise, $submission) { /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_print_submission_title($exercise, $submission) { global $CFG; - - if (!$submission->timecreated) { // a "no submission" - return $submission->title; - } + + if (!$submission->timecreated) { // a "no submission" + return $submission->title; + } $filearea = exercise_file_area_name($exercise, $submission); if ($basedir = exercise_file_area($exercise, $submission)) { @@ -3738,26 +3763,26 @@ function exercise_print_submission_title($exercise, $submission) { function exercise_print_tabbed_heading($tabs) { // Prints a tabbed heading where one of the tabs highlighted. // $tabs is an object with several properties. -// $tabs->names is an array of tab names -// $tabs->urls is an array of links -// $tabs->align is an array of column alignments (defaults to "center") -// $tabs->size is an array of column sizes -// $tabs->wrap is an array of "nowrap"s or nothing -// $tabs->highlight is an index (zero based) of "active" heading . -// $tabs->width is an percentage of the page (defualts to 80%) -// $tabs->cellpadding padding on each cell (defaults to 5) - - global $CFG, $THEME; - +// $tabs->names is an array of tab names +// $tabs->urls is an array of links +// $tabs->align is an array of column alignments (defaults to "center") +// $tabs->size is an array of column sizes +// $tabs->wrap is an array of "nowrap"s or nothing +// $tabs->highlight is an index (zero based) of "active" heading . +// $tabs->width is an percentage of the page (defualts to 80%) +// $tabs->cellpadding padding on each cell (defaults to 5) + + global $CFG, $THEME; + if (isset($tabs->names)) { foreach ($tabs->names as $key => $name) { if (!empty($tabs->urls[$key])) { - $url =$tabs->urls[$key]; - if ($tabs->highlight == $key) { - $tabcontents[$key] = "$name"; - } else { - $tabcontents[$key] = "$name"; - } + $url =$tabs->urls[$key]; + if ($tabs->highlight == $key) { + $tabcontents[$key] = "$name"; + } else { + $tabcontents[$key] = "$name"; + } } else { $tabcontents[$key] = "$name"; } @@ -3778,43 +3803,43 @@ function exercise_print_tabbed_heading($tabs) { if (!empty($tabs->names)) { echo ""; - echo "". - "wwwroot/pix/spacer.gif\" alt=\"\">\n"; + echo "". + "wwwroot/pix/spacer.gif\" alt=\"\">\n"; foreach ($tabcontents as $key => $tab) { if (isset($align[$key])) { - $alignment = "align=\"$align[$key]\""; - } else { + $alignment = "align=\"$align[$key]\""; + } else { $alignment = "align=\"center\""; } if (isset($size[$key])) { $width = "width=\"$size[$key]\""; } else { - $width = ""; - } + $width = ""; + } if (isset($wrap[$key])) { - $wrapping = "no wrap"; - } else { + $wrapping = "no wrap"; + } else { $wrapping = ""; } - if ($key == $tabs->highlight) { - echo "cellheading2\">$tab\n"; - } else { - echo "cellheading\">$tab\n"; - } - echo "". - "wwwroot/pix/spacer.gif\" alt=\"\">\n"; + if ($key == $tabs->highlight) { + echo "cellheading2\">$tab\n"; + } else { + echo "cellheading\">$tab\n"; + } + echo "". + "wwwroot/pix/spacer.gif\" alt=\"\">\n"; } echo "\n"; } else { - echo "No names specified\n"; - } - // bottom stripe - $ncells = count($tabs->names)*2 +1; - $height = 2; - echo "cellheading2\">". - "wwwroot/pix/spacer.gif\" alt=\"\">\n"; + echo "No names specified\n"; + } + // bottom stripe + $ncells = count($tabs->names)*2 +1; + $height = 2; + echo "cellheading2\">". + "wwwroot/pix/spacer.gif\" alt=\"\">\n"; echo "\n"; - // print_simple_box_end(); + // print_simple_box_end(); return true; } @@ -3851,11 +3876,11 @@ function exercise_print_teacher_table($course) { $table->size[] = "*"; foreach ($exercises as $exercise) { $table->head[] = $exercise->name; - $table->align[] = "center"; - $table->size[] = "*"; + $table->align[] = "center"; + $table->size[] = "*"; } - $table->cellpadding = 2; - $table->cellspacing = 0; + $table->cellpadding = 2; + $table->cellspacing = 0; if (!$teachers = get_course_teachers($course->id, "u.firstname, u.lastname")) { error("No teachers on this course!"); @@ -3876,29 +3901,29 @@ function exercise_print_teacher_table($course) { $j++; } $grandtotal += $total; - $table->data[] = array_merge(array("$teacher->firstname $teacher->lastname"), array($total), $n); - } - $table->data[] = array_merge(array(get_string("total")), array($grandtotal), $grand); - print_heading(get_string("teacherassessmenttable", "exercise", $course->teacher)); - print_table($table); + $table->data[] = array_merge(array("$teacher->firstname $teacher->lastname"), array($total), $n); + } + $table->data[] = array_merge(array(get_string("total")), array($grandtotal), $grand); + print_heading(get_string("teacherassessmenttable", "exercise", $course->teacher)); + print_table($table); } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_print_upload_form($exercise) { - if (! $course = get_record("course", "id", $exercise->course)) { + if (! $course = get_record("course", "id", $exercise->course)) { error("Course is misconfigured"); } if (! $cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id)) { error("Course Module ID was incorrect"); - } + } echo "
"; echo "
"; echo " maxbytes\">"; echo " id\">"; - echo "".get_string("title", "exercise").":

\n"; + echo "".get_string("title", "exercise").":

\n"; echo " "; echo " "; echo "
"; @@ -3908,66 +3933,66 @@ function exercise_print_upload_form($exercise) { /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_print_user_assessments($exercise, $user) { - // Returns the number of assessments and a hyperlinked list of grading grades for the assessments made by this user - - if ($assessments = exercise_get_user_assessments($exercise, $user)) { - $n = count($assessments); - $str = "$n ("; - foreach ($assessments as $assessment) { - if ($assessment->timegraded) { - $gradingscaled = intval($assessment->gradinggrade * $exercise->grade / COMMENTSCALE); - $str .= "id&aid=$assessment->id\">"; - $str .= "$gradingscaled "; - } - else { - $str .= "id&aid=$assessment->id\">"; - $str .= "- "; - } - } - $str .= ")"; - } - else { - $str ="0"; - } + // Returns the number of assessments and a hyperlinked list of grading grades for the assessments made by this user + + if ($assessments = exercise_get_user_assessments($exercise, $user)) { + $n = count($assessments); + $str = "$n ("; + foreach ($assessments as $assessment) { + if ($assessment->timegraded) { + $gradingscaled = intval($assessment->gradinggrade * $exercise->grade / COMMENTSCALE); + $str .= "id&aid=$assessment->id\">"; + $str .= "$gradingscaled "; + } + else { + $str .= "id&aid=$assessment->id\">"; + $str .= "- "; + } + } + $str .= ")"; + } + else { + $str ="0"; + } return $str; - } + } /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_test_for_resubmission($exercise, $user) { - // see if any of the user's submissions have the resubmit flag set - $result = false; - if ($submissions = exercise_get_user_submissions($exercise, $user)) { - foreach ($submissions as $submission) { - if ($submission->resubmit) { - $result =true; - break; - } - } - } - return $result; - } - + // see if any of the user's submissions have the resubmit flag set + $result = false; + if ($submissions = exercise_get_user_submissions($exercise, $user)) { + foreach ($submissions as $submission) { + if ($submission->resubmit) { + $result =true; + break; + } + } + } + return $result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// function exercise_test_user_assessments($exercise, $user) { - // see if user has assessed one of teacher's exercises/submissions... - global $CFG; - - $result = false; - $timenow =time(); - if ($submissions = exercise_get_teacher_submissions($exercise)) { - foreach ($submissions as $submission) { - if ($assessment = exercise_get_submission_assessment($submission, $user)) { - // ...the date stamp on the assessment should be in the past - if ($assessment->timecreated < $timenow) { - $result = true; - break; - } - } - } - } - return $result; - } + // see if user has assessed one of teacher's exercises/submissions... + global $CFG; + + $result = false; + $timenow =time(); + if ($submissions = exercise_get_teacher_submissions($exercise)) { + foreach ($submissions as $submission) { + if ($assessment = exercise_get_submission_assessment($submission, $user)) { + // ...the date stamp on the assessment should be in the past + if ($assessment->timecreated < $timenow) { + $result = true; + break; + } + } + } + } + return $result; + } ?> diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 32cf224b4b..af4d766b33 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -8,49 +8,49 @@ $WORKSHOP_TYPE = array (0 => get_string("notgraded", "workshop"), 1 => get_string("accumulative", "workshop"), 2 => get_string("errorbanded", "workshop"), 3 => get_string("criterion", "workshop"), - 4 => get_string("rubric", "workshop") ); + 4 => get_string("rubric", "workshop") ); $WORKSHOP_SHOWGRADES = array (0 => get_string("dontshowgrades", "workshop"), 1 => get_string("showgrades", "workshop") ); $WORKSHOP_SCALES = array( - 0 => array( 'name' => get_string("scaleyes", "workshop"), 'type' => 'radio', + 0 => array( 'name' => get_string("scaleyes", "workshop"), 'type' => 'radio', 'size' => 2, 'start' => get_string("yes"), 'end' => get_string("no")), - 1 => array( 'name' => get_string("scalepresent", "workshop"), 'type' => 'radio', + 1 => array( 'name' => get_string("scalepresent", "workshop"), 'type' => 'radio', 'size' => 2, 'start' => get_string("present", "workshop"), 'end' => get_string("absent", "workshop")), - 2 => array( 'name' => get_string("scalecorrect", "workshop"), 'type' => 'radio', + 2 => array( 'name' => get_string("scalecorrect", "workshop"), 'type' => 'radio', 'size' => 2, 'start' => get_string("correct", "workshop"), 'end' => get_string("incorrect", "workshop")), - 3 => array( 'name' => get_string("scalegood3", "workshop"), 'type' => 'radio', + 3 => array( 'name' => get_string("scalegood3", "workshop"), 'type' => 'radio', 'size' => 3, 'start' => get_string("good", "workshop"), 'end' => get_string("poor", "workshop")), - 4 => array( 'name' => get_string("scaleexcellent4", "workshop"), 'type' => 'radio', + 4 => array( 'name' => get_string("scaleexcellent4", "workshop"), 'type' => 'radio', 'size' => 4, 'start' => get_string("excellent", "workshop"), 'end' => get_string("verypoor", "workshop")), - 5 => array( 'name' => get_string("scaleexcellent5", "workshop"), 'type' => 'radio', + 5 => array( 'name' => get_string("scaleexcellent5", "workshop"), 'type' => 'radio', 'size' => 5, 'start' => get_string("excellent", "workshop"), 'end' => get_string("verypoor", "workshop")), - 6 => array( 'name' => get_string("scaleexcellent7", "workshop"), 'type' => 'radio', + 6 => array( 'name' => get_string("scaleexcellent7", "workshop"), 'type' => 'radio', 'size' => 7, 'start' => get_string("excellent", "workshop"), 'end' => get_string("verypoor", "workshop")), - 7 => array( 'name' => get_string("scale10", "workshop"), 'type' => 'selection', + 7 => array( 'name' => get_string("scale10", "workshop"), 'type' => 'selection', 'size' => 10), - 8 => array( 'name' => get_string("scale20", "workshop"), 'type' => 'selection', + 8 => array( 'name' => get_string("scale20", "workshop"), 'type' => 'selection', 'size' => 20), - 9 => array( 'name' => get_string("scale100", "workshop"), 'type' => 'selection', + 9 => array( 'name' => get_string("scale100", "workshop"), 'type' => 'selection', 'size' => 100)); $WORKSHOP_EWEIGHTS = array( 0 => -4.0, 1 => -2.0, 2 => -1.5, 3 => -1.0, 4 => -0.75, 5 => -0.5, 6 => -0.25, - 7 => 0.0, 8 => 0.25, 9 => 0.5, 10 => 0.75, 11=> 1.0, 12 => 1.5, 13=> 2.0, + 7 => 0.0, 8 => 0.25, 9 => 0.5, 10 => 0.75, 11=> 1.0, 12 => 1.5, 13=> 2.0, 14 => 4.0); $WORKSHOP_FWEIGHTS = array( 0 => 0, 1 => 0.1, 2 => 0.25, 3 => 0.5, 4 => 0.75, 5 => 1.0, 6 => 1.5, - 7 => 2.0, 8 => 3.0, 9 => 5.0, 10 => 7.5, 11=> 10.0, 12=>50.0); + 7 => 2.0, 8 => 3.0, 9 => 5.0, 10 => 7.5, 11=> 10.0, 12=>50.0); if (!defined("COMMENTSCALE")) { - define("COMMENTSCALE", 20); - } + define("COMMENTSCALE", 20); + } /*** Standard Moodle functions ****************** @@ -75,8 +75,8 @@ function workshop_add_instance($workshop) { $workshop->timemodified = time(); $workshop->deadline = make_timestamp($workshop->deadlineyear, - $workshop->deadlinemonth, $workshop->deadlineday, $workshop->deadlinehour, - $workshop->deadlineminute); + $workshop->deadlinemonth, $workshop->deadlineday, $workshop->deadlinehour, + $workshop->deadlineminute); if ($returnid = insert_record("workshop", $workshop)) { @@ -104,31 +104,31 @@ function workshop_cron () { // Function to be run periodically according to the moodle cron global $CFG, $USER; - - // Find all workshop notifications that have yet to be mailed out, and mails them + + // Find all workshop notifications that have yet to be mailed out, and mails them $cutofftime = time() - $CFG->maxeditingtime; - // look for new assessments - if ($assessments = workshop_get_unmailed_assessments($cutofftime)) { + // look for new assessments + if ($assessments = workshop_get_unmailed_assessments($cutofftime)) { $timenow = time(); foreach ($assessments as $assessment) { - echo "Processing workshop assessment $assessment->id\n"; + echo "Processing workshop assessment $assessment->id\n"; // only process the entry once - if (! set_field("workshop_assessments", "mailed", "1", "id", "$assessment->id")) { - echo "Could not update the mailed field for id $assessment->id\n"; - } - + if (! set_field("workshop_assessments", "mailed", "1", "id", "$assessment->id")) { + echo "Could not update the mailed field for id $assessment->id\n"; + } + if (! $submission = get_record("workshop_submissions", "id", "$assessment->submissionid")) { - echo "Could not find submission $assessment->submissionid\n"; - continue; - } - if (! $workshop = get_record("workshop", "id", $submission->workshopid)) { - echo "Could not find workshop id $submission->workshopid\n"; - continue; - } + echo "Could not find submission $assessment->submissionid\n"; + continue; + } + if (! $workshop = get_record("workshop", "id", $submission->workshopid)) { + echo "Could not find workshop id $submission->workshopid\n"; + continue; + } if (! $course = get_record("course", "id", $workshop->course)) { error("Could not find course id $workshop->course"); continue; @@ -137,96 +137,96 @@ function workshop_cron () { error("Course Module ID was incorrect"); continue; } - if (! $submissionowner = get_record("user", "id", "$submission->userid")) { - echo "Could not find user $submission->userid\n"; - continue; - } - if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) { - echo "Could not find user $assessment->userid\n"; - continue; - } - if (! isstudent($course->id, $submissionowner->id) and !isteacher($course->id, + if (! $submissionowner = get_record("user", "id", "$submission->userid")) { + echo "Could not find user $submission->userid\n"; + continue; + } + if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) { + echo "Could not find user $assessment->userid\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, + continue; // Not an active participant + } + if (! isstudent($course->id, $assessmentowner->id) and !isteacher($course->id, $assessmentowner->id)) { - continue; // Not an active participant - } + continue; // Not an active participant + } // don't sent self assessment - if ($submissionowner->id == $assessmentowner->id) { + if ($submissionowner->id == $assessmentowner->id) { continue; } - $strworkshops = get_string("modulenameplural", "workshop"); - $strworkshop = get_string("modulename", "workshop"); - - // it's an assessment, tell the submission owner - $USER->lang = $submissionowner->lang; - $sendto = $submissionowner; - // "Your assignment \"$submission->title\" has been assessed by" - if (isstudent($course->id, $assessmentowner->id)) { - $msg = get_string("mail1", "workshop", $submission->title)." a $course->student.\n"; - } - else { - $msg = get_string("mail1", "workshop", $submission->title). + $strworkshops = get_string("modulenameplural", "workshop"); + $strworkshop = get_string("modulename", "workshop"); + + // it's an assessment, tell the submission owner + $USER->lang = $submissionowner->lang; + $sendto = $submissionowner; + // "Your assignment \"$submission->title\" has been assessed by" + if (isstudent($course->id, $assessmentowner->id)) { + $msg = get_string("mail1", "workshop", $submission->title)." a $course->student.\n"; + } + else { + $msg = get_string("mail1", "workshop", $submission->title). " $assessmentowner->firstname $assessmentowner->lastname.\n"; - } - // "The comments and grade can be seen in the workshop assignment '$workshop->name' - $msg .= get_string("mail2", "workshop", $workshop->name)."\n\n"; - - $postsubject = "$course->shortname: $strworkshops: $workshop->name"; - $posttext = "$course->shortname -> $strworkshops -> $workshop->name\n"; - $posttext .= "---------------------------------------------------------------------\n"; - $posttext .= $msg; - // "You can see it in your workshop assignment" - $posttext .= get_string("mail3", "workshop").":\n"; - $posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n"; - $posttext .= "---------------------------------------------------------------------\n"; - if ($sendto->mailformat == 1) { // HTML - $posthtml = "

". - "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". - "wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops ->". - "wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name

"; - $posthtml .= "
"; - $posthtml .= "

$msg

"; - $posthtml .= "

".get_string("mail3", "workshop"). - " wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name.


"; - } else { - $posthtml = ""; - } - - if (!$teacher = get_teacher($course->id)) { - echo "Error: can not find teacher for course $course->id!\n"; - } - - if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { - echo "Error: workshop cron: Could not send out mail for id $submission->id to + } + // "The comments and grade can be seen in the workshop assignment '$workshop->name' + $msg .= get_string("mail2", "workshop", $workshop->name)."\n\n"; + + $postsubject = "$course->shortname: $strworkshops: $workshop->name"; + $posttext = "$course->shortname -> $strworkshops -> $workshop->name\n"; + $posttext .= "---------------------------------------------------------------------\n"; + $posttext .= $msg; + // "You can see it in your workshop assignment" + $posttext .= get_string("mail3", "workshop").":\n"; + $posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n"; + $posttext .= "---------------------------------------------------------------------\n"; + if ($sendto->mailformat == 1) { // HTML + $posthtml = "

". + "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". + "wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops ->". + "wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name

"; + $posthtml .= "
"; + $posthtml .= "

$msg

"; + $posthtml .= "

".get_string("mail3", "workshop"). + " wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name.


"; + } else { + $posthtml = ""; + } + + if (!$teacher = get_teacher($course->id)) { + echo "Error: can not find teacher for course $course->id!\n"; + } + + if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { + echo "Error: workshop cron: Could not send out mail for id $submission->id to user $sendto->id ($sendto->email)\n"; - } - } - } - - // look for new assessments of resubmissions - if ($assessments = workshop_get_unmailed_resubmissions($cutofftime)) { + } + } + } + + // look for new assessments of resubmissions + if ($assessments = workshop_get_unmailed_resubmissions($cutofftime)) { $timenow = time(); foreach ($assessments as $assessment) { - echo "Processing workshop assessment $assessment->id\n"; + echo "Processing workshop assessment $assessment->id\n"; // only process the entry once - if (! set_field("workshop_assessments", "mailed", "1", "id", "$assessment->id")) { - echo "Could not update the mailed field for id $assessment->id\n"; - } - + if (! set_field("workshop_assessments", "mailed", "1", "id", "$assessment->id")) { + echo "Could not update the mailed field for id $assessment->id\n"; + } + if (! $submission = get_record("workshop_submissions", "id", "$assessment->submissionid")) { - echo "Could not find submission $assessment->submissionid\n"; - continue; - } - if (! $workshop = get_record("workshop", "id", $submission->workshopid)) { - echo "Could not find workshop id $submission->workshopid\n"; - continue; - } + echo "Could not find submission $assessment->submissionid\n"; + continue; + } + if (! $workshop = get_record("workshop", "id", $submission->workshopid)) { + echo "Could not find workshop id $submission->workshopid\n"; + continue; + } if (! $course = get_record("course", "id", $workshop->course)) { error("Could not find course id $workshop->course"); continue; @@ -235,92 +235,92 @@ function workshop_cron () { error("Course Module ID was incorrect"); continue; } - if (! $submissionowner = get_record("user", "id", "$submission->userid")) { - echo "Could not find user $submission->userid\n"; - continue; - } - if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) { - echo "Could not find user $assessment->userid\n"; - continue; - } - if (! isstudent($course->id, $submissionowner->id) and !isteacher($course->id, + if (! $submissionowner = get_record("user", "id", "$submission->userid")) { + echo "Could not find user $submission->userid\n"; + continue; + } + if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) { + echo "Could not find user $assessment->userid\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, + continue; // Not an active participant + } + if (! isstudent($course->id, $assessmentowner->id) and !isteacher($course->id, $assessmentowner->id)) { - continue; // Not an active participant - } - - $strworkshops = get_string("modulenameplural", "workshop"); - $strworkshop = get_string("modulename", "workshop"); - - // it's a resubission assessment, tell the assessment owner to (re)assess - $USER->lang = $assessmentowner->lang; - $sendto = $assessmentowner; - // "The assignment \"$submission->title\" is a revised piece of work. " - $msg = get_string("mail8", "workshop", $submission->title)."\n"; - // "Please assess it in the workshop assignment '$workshop->name' - $msg .= get_string("mail9", "workshop", $workshop->name)."\n\n"; - - $postsubject = "$course->shortname: $strworkshops: $workshop->name"; - $posttext = "$course->shortname -> $strworkshops -> $workshop->name\n"; - $posttext .= "---------------------------------------------------------------------\n"; - $posttext .= $msg; - // "You can assess it in your workshop assignment" - $posttext .= get_string("mail10", "workshop").":\n"; - $posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n"; - $posttext .= "---------------------------------------------------------------------\n"; - if ($sendto->mailformat == 1) { // HTML - $posthtml = "

". - "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". - "wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops ->". - "wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name

"; - $posthtml .= "
"; - $posthtml .= "

$msg

"; - $posthtml .= "

".get_string("mail3", "workshop"). - " wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name.


"; - } + continue; // Not an active participant + } + + $strworkshops = get_string("modulenameplural", "workshop"); + $strworkshop = get_string("modulename", "workshop"); + + // it's a resubission assessment, tell the assessment owner to (re)assess + $USER->lang = $assessmentowner->lang; + $sendto = $assessmentowner; + // "The assignment \"$submission->title\" is a revised piece of work. " + $msg = get_string("mail8", "workshop", $submission->title)."\n"; + // "Please assess it in the workshop assignment '$workshop->name' + $msg .= get_string("mail9", "workshop", $workshop->name)."\n\n"; + + $postsubject = "$course->shortname: $strworkshops: $workshop->name"; + $posttext = "$course->shortname -> $strworkshops -> $workshop->name\n"; + $posttext .= "---------------------------------------------------------------------\n"; + $posttext .= $msg; + // "You can assess it in your workshop assignment" + $posttext .= get_string("mail10", "workshop").":\n"; + $posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n"; + $posttext .= "---------------------------------------------------------------------\n"; + if ($sendto->mailformat == 1) { // HTML + $posthtml = "

". + "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". + "wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops ->". + "wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name

"; + $posthtml .= "
"; + $posthtml .= "

$msg

"; + $posthtml .= "

".get_string("mail3", "workshop"). + " wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name.


"; + } else { - $posthtml = ""; - } - - if (!$teacher = get_teacher($course->id)) { - echo "Error: can not find teacher for course $course->id!\n"; - } - - if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { - echo "Error: workshop cron: Could not send out mail for id $submission->id to + $posthtml = ""; + } + + if (!$teacher = get_teacher($course->id)) { + echo "Error: can not find teacher for course $course->id!\n"; + } + + if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { + echo "Error: workshop cron: Could not send out mail for id $submission->id to user $sendto->id ($sendto->email)\n"; - } - } - } - + } + } + } + // look for new comments - if ($comments = workshop_get_unmailed_comments($cutofftime)) { + if ($comments = workshop_get_unmailed_comments($cutofftime)) { $timenow = time(); foreach ($comments as $comment) { - echo "Processing workshop comment $comment->id\n"; + echo "Processing workshop comment $comment->id\n"; // only process the entry once - if (! set_field("workshop_comments", "mailed", "1", "id", "$comment->id")) { - echo "Could not update the mailed field for comment id $comment->id\n"; - } - + if (! set_field("workshop_comments", "mailed", "1", "id", "$comment->id")) { + echo "Could not update the mailed field for comment id $comment->id\n"; + } + if (! $assessment = get_record("workshop_assessments", "id", "$comment->assessmentid")) { - echo "Could not find assessment $comment->assessmentid\n"; - continue; - } - if (! $submission = get_record("workshop_submissions", "id", "$assessment->submissionid")) { - echo "Could not find submission $assessment->submissionid\n"; - continue; - } - if (! $workshop = get_record("workshop", "id", $submission->workshopid)) { - echo "Could not find workshop id $submission->workshopid\n"; - continue; - } + echo "Could not find assessment $comment->assessmentid\n"; + continue; + } + if (! $submission = get_record("workshop_submissions", "id", "$assessment->submissionid")) { + echo "Could not find submission $assessment->submissionid\n"; + continue; + } + if (! $workshop = get_record("workshop", "id", $submission->workshopid)) { + echo "Could not find workshop id $submission->workshopid\n"; + continue; + } if (! $course = get_record("course", "id", $workshop->course)) { error("Could not find course id $workshop->course"); continue; @@ -329,127 +329,127 @@ function workshop_cron () { error("Course Module ID was incorrect"); continue; } - if (! $submissionowner = get_record("user", "id", "$submission->userid")) { - echo "Could not find user $submission->userid\n"; - continue; - } - if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) { - echo "Could not find user $assessment->userid\n"; - continue; - } - if (! isstudent($course->id, $submissionowner->id) and !isteacher($course->id, + if (! $submissionowner = get_record("user", "id", "$submission->userid")) { + echo "Could not find user $submission->userid\n"; + continue; + } + if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) { + echo "Could not find user $assessment->userid\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, + continue; // Not an active participant + } + if (! isstudent($course->id, $assessmentowner->id) and !isteacher($course->id, $assessmentowner->id)) { - continue; // Not an active participant - } - - $strworkshops = get_string("modulenameplural", "workshop"); - $strworkshop = get_string("modulename", "workshop"); - - // see if the submission owner needs to be told - if ($comment->userid != $submission->userid) { - $USER->lang = $submissionowner->lang; - $sendto = $submissionowner; - // "A comment has been added to the assignment \"$submission->title\" by - if (isstudent($course->id, $assessmentowner->id)) { - $msg = get_string("mail4", "workshop", $submission->title)." a $course->student.\n"; - } - else { - $msg = get_string("mail4", "workshop", $submission->title)." $assessmentowner->firstname $assessmentowner->lastname.\n"; - } - // "The new comment can be seen in the workshop assignment '$workshop->name' - $msg .= get_string("mail5", "workshop", $workshop->name)."\n\n"; - - $postsubject = "$course->shortname: $strworkshops: $workshop->name"; - $posttext = "$course->shortname -> $strworkshops -> $workshop->name\n"; - $posttext .= "---------------------------------------------------------------------\n"; - $posttext .= $msg; - // "You can see it in your workshop assignment" - $posttext .= get_string("mail3", "workshop").":\n"; - $posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n"; - $posttext .= "---------------------------------------------------------------------\n"; - if ($sendto->mailformat == 1) { // HTML - $posthtml = "

". - "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". - "wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops ->". - "wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name

"; - $posthtml .= "
"; - $posthtml .= "

$msg

"; - $posthtml .= "

".get_string("mail3", "workshop"). - " wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name + continue; // Not an active participant + } + + $strworkshops = get_string("modulenameplural", "workshop"); + $strworkshop = get_string("modulename", "workshop"); + + // see if the submission owner needs to be told + if ($comment->userid != $submission->userid) { + $USER->lang = $submissionowner->lang; + $sendto = $submissionowner; + // "A comment has been added to the assignment \"$submission->title\" by + if (isstudent($course->id, $assessmentowner->id)) { + $msg = get_string("mail4", "workshop", $submission->title)." a $course->student.\n"; + } + else { + $msg = get_string("mail4", "workshop", $submission->title)." $assessmentowner->firstname $assessmentowner->lastname.\n"; + } + // "The new comment can be seen in the workshop assignment '$workshop->name' + $msg .= get_string("mail5", "workshop", $workshop->name)."\n\n"; + + $postsubject = "$course->shortname: $strworkshops: $workshop->name"; + $posttext = "$course->shortname -> $strworkshops -> $workshop->name\n"; + $posttext .= "---------------------------------------------------------------------\n"; + $posttext .= $msg; + // "You can see it in your workshop assignment" + $posttext .= get_string("mail3", "workshop").":\n"; + $posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n"; + $posttext .= "---------------------------------------------------------------------\n"; + if ($sendto->mailformat == 1) { // HTML + $posthtml = "

". + "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". + "wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops ->". + "wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name

"; + $posthtml .= "
"; + $posthtml .= "

$msg

"; + $posthtml .= "

".get_string("mail3", "workshop"). + " wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name .


"; - } - else { - $posthtml = ""; - } - - if (!$teacher = get_teacher($course->id)) { - echo "Error: can not find teacher for course $course->id!\n"; - } - - if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { - echo "Error: workshop cron: Could not send out mail for id $submission->id to user + } + else { + $posthtml = ""; + } + + if (!$teacher = get_teacher($course->id)) { + echo "Error: can not find teacher for course $course->id!\n"; + } + + if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { + echo "Error: workshop cron: Could not send out mail for id $submission->id to user $sendto->id ($sendto->email)\n"; - } - } - // see if the assessor needs to to told - if ($comment->userid != $assessment->userid) { - $USER->lang = $assessmentowner->lang; - $sendto = $assessmentowner; - // "A comment has been added to the assignment \"$submission->title\" by - if (isstudent($course->id, $submissionowner->id)) { - $msg = get_string("mail4", "workshop", $submission->title)." a $course->student.\n"; - } - else { - $msg = get_string("mail4", "workshop", $submission->title). + } + } + // see if the assessor needs to to told + if ($comment->userid != $assessment->userid) { + $USER->lang = $assessmentowner->lang; + $sendto = $assessmentowner; + // "A comment has been added to the assignment \"$submission->title\" by + if (isstudent($course->id, $submissionowner->id)) { + $msg = get_string("mail4", "workshop", $submission->title)." a $course->student.\n"; + } + else { + $msg = get_string("mail4", "workshop", $submission->title). " $submissionowner->firstname $submissionowner->lastname.\n"; - } - // "The new comment can be seen in the workshop assignment '$workshop->name' - $msg .= get_string("mail5", "workshop", $workshop->name)."\n\n"; - - $postsubject = "$course->shortname: $strworkshops: $workshop->name"; - $posttext = "$course->shortname -> $strworkshops -> $workshop->name\n"; - $posttext .= "---------------------------------------------------------------------\n"; - $posttext .= $msg; - // "You can see it in your workshop assignment" - $posttext .= get_string("mail3", "workshop").":\n"; - $posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n"; - $posttext .= "---------------------------------------------------------------------\n"; - if ($sendto->mailformat == 1) { // HTML - $posthtml = "

". - "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". - "wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops ->". - "wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name

"; - $posthtml .= "
"; - $posthtml .= "

$msg

"; - $posthtml .= "

".get_string("mail3", "workshop"). - " wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name.


"; - } - else { - $posthtml = ""; - } - - if (!$teacher = get_teacher($course->id)) { - echo "Error: can not find teacher for course $course->id!\n"; - } - - if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { - echo "Error: workshop cron: Could not send out mail for id $submission->id to user + } + // "The new comment can be seen in the workshop assignment '$workshop->name' + $msg .= get_string("mail5", "workshop", $workshop->name)."\n\n"; + + $postsubject = "$course->shortname: $strworkshops: $workshop->name"; + $posttext = "$course->shortname -> $strworkshops -> $workshop->name\n"; + $posttext .= "---------------------------------------------------------------------\n"; + $posttext .= $msg; + // "You can see it in your workshop assignment" + $posttext .= get_string("mail3", "workshop").":\n"; + $posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n"; + $posttext .= "---------------------------------------------------------------------\n"; + if ($sendto->mailformat == 1) { // HTML + $posthtml = "

". + "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". + "wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops ->". + "wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name

"; + $posthtml .= "
"; + $posthtml .= "

$msg

"; + $posthtml .= "

".get_string("mail3", "workshop"). + " wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name.


"; + } + else { + $posthtml = ""; + } + + if (!$teacher = get_teacher($course->id)) { + echo "Error: can not find teacher for course $course->id!\n"; + } + + if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { + echo "Error: workshop cron: Could not send out mail for id $submission->id to user $sendto->id ($sendto->email)\n"; - } - if (! set_field("workshop_comments", "mailed", "1", "id", "$comment->id")) { - echo "Could not update the mailed field for comment id $comment->id\n"; - } - } - } - } + } + if (! set_field("workshop_comments", "mailed", "1", "id", "$comment->id")) { + echo "Could not update the mailed field for comment id $comment->id\n"; + } + } + } + } - // look for new gradings - if ($assessments = workshop_get_unmailed_graded_assessments($cutofftime)) { + // look for new gradings + if ($assessments = workshop_get_unmailed_graded_assessments($cutofftime)) { $timenow = time(); foreach ($assessments as $assessment) { @@ -461,15 +461,15 @@ function workshop_cron () { echo "Could not update the mailed field for id $assessment->id\n"; } - if (! $submission = get_record("workshop_submissions", "id", "$assessment->submissionid")) { + if (! $submission = get_record("workshop_submissions", "id", "$assessment->submissionid")) { echo "Could not find submission $assessment->submissionid\n"; continue; } - if (! $workshop = get_record("workshop", "id", $submission->workshopid)) { - echo "Could not find workshop id $submission->workshopid\n"; - continue; - } + if (! $workshop = get_record("workshop", "id", $submission->workshopid)) { + echo "Could not find workshop id $submission->workshopid\n"; + continue; + } if (! $course = get_record("course", "id", $workshop->course)) { error("Could not find course id $workshop->course"); continue; @@ -478,11 +478,11 @@ function workshop_cron () { error("Course Module ID was incorrect"); continue; } - if (! $submissionowner = get_record("user", "id", "$submission->userid")) { + if (! $submissionowner = get_record("user", "id", "$submission->userid")) { echo "Could not find user $submission->userid\n"; continue; } - if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) { + if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) { echo "Could not find user $assessment->userid\n"; continue; } @@ -498,39 +498,39 @@ function workshop_cron () { $strworkshops = get_string("modulenameplural", "workshop"); $strworkshop = get_string("modulename", "workshop"); - // it's a grading tell the assessment owner - $USER->lang = $assessmentowner->lang; - $sendto = $assessmentowner; - // Your assessment of the assignment \"$submission->title\" has by reviewed - $msg = get_string("mail6", "workshop", $submission->title).".\n"; - // The comments given by the $course->teacher can be seen in the Workshop Assignment - $msg .= get_string("mail7", "workshop", $course->teacher)." '$workshop->name'.\n\n"; + // it's a grading tell the assessment owner + $USER->lang = $assessmentowner->lang; + $sendto = $assessmentowner; + // Your assessment of the assignment \"$submission->title\" has by reviewed + $msg = get_string("mail6", "workshop", $submission->title).".\n"; + // The comments given by the $course->teacher can be seen in the Workshop Assignment + $msg .= get_string("mail7", "workshop", $course->teacher)." '$workshop->name'.\n\n"; - $postsubject = "$course->shortname: $strworkshops: $workshop->name"; + $postsubject = "$course->shortname: $strworkshops: $workshop->name"; $posttext = "$course->shortname -> $strworkshops -> $workshop->name\n"; $posttext .= "---------------------------------------------------------------------\n"; $posttext .= $msg; - // "You can see it in your workshop assignment" - $posttext .= get_string("mail3", "workshop").":\n"; - $posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n"; + // "You can see it in your workshop assignment" + $posttext .= get_string("mail3", "workshop").":\n"; + $posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n"; $posttext .= "---------------------------------------------------------------------\n"; if ($sendto->mailformat == 1) { // HTML - $posthtml = "

". - "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". - "wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops ->". - "wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name

"; - $posthtml .= "
"; - $posthtml .= "

$msg

"; - $posthtml .= "

".get_string("mail3", "workshop"). - " wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name.


"; + $posthtml = "

". + "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". + "wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops ->". + "wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name

"; + $posthtml .= "
"; + $posthtml .= "

$msg

"; + $posthtml .= "

".get_string("mail3", "workshop"). + " wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name.


"; } else { $posthtml = ""; } - if (!$teacher = get_teacher($course->id)) { - echo "Error: can not find teacher for course $course->id!\n"; - } - + if (!$teacher = get_teacher($course->id)) { + echo "Error: can not find teacher for course $course->id!\n"; + } + if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { echo "Error: workshop cron: Could not send out mail for id $submission->id to user $sendto->id ($sendto->email)\n"; @@ -551,8 +551,8 @@ function workshop_delete_instance($id) { if (! $workshop = get_record("workshop", "id", "$id")) { return false; } - - // delete all the associated records in the workshop tables, start positive... + + // delete all the associated records in the workshop tables, start positive... $result = true; if (! delete_records("workshop_comments", "workshopid", "$workshop->id")) { @@ -593,17 +593,17 @@ function workshop_grades($workshopid) { /// only retruns grades in phase 6 global $CFG; - if ($workshop = get_record("workshop", "id", $workshopid)) { + if ($workshop = get_record("workshop", "id", $workshopid)) { if ($workshop->phase == 6) { if ($bestsubmissions = get_records_sql("SELECT userid, max(finalgrade) finalgrade FROM - {$CFG->prefix}workshop_submissions WHERE workshopid = $workshopid GROUP - BY userid")) { - foreach ($bestsubmissions as $bestgrade) { - $return->grades[$bestgrade->userid] = $bestgrade->finalgrade; + {$CFG->prefix}workshop_submissions WHERE workshopid = $workshopid GROUP + BY userid")) { + foreach ($bestsubmissions as $bestgrade) { + $return->grades[$bestgrade->userid] = $bestgrade->finalgrade; } } - } - $return->maxgrade = $workshop->grade; + } + $return->maxgrade = $workshop->grade; } return $return; } @@ -611,24 +611,24 @@ global $CFG; function workshop_is_recent_activity($course, $isteacher, $timestart) {//jlw1 added for adding mark to courses with activity in My Moodle global $CFG; - // have a look for agreed assessments for this user (agree) + // have a look for agreed assessments for this user (agree) $agreecontent = false; - if (!$isteacher) { // teachers only need to see submissions - if ($logs = workshop_get_agree_logs($course, $timestart)) { - // got some, see if any belong to a visible module - foreach ($logs as $log) { - // Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->workshopid; - //Obtain the visible property from the instance - if (instance_is_visible("workshop",$tempmod)) { - $agreecontent = true; - break; - } - } - } - } - return false; + if (!$isteacher) { // teachers only need to see submissions + if ($logs = workshop_get_agree_logs($course, $timestart)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->workshopid; + //Obtain the visible property from the instance + if (instance_is_visible("workshop",$tempmod)) { + $agreecontent = true; + break; + } + } + } + } + return false; } @@ -636,193 +636,193 @@ function workshop_is_recent_activity($course, $isteacher, $timestart) {//jlw1 ad function workshop_print_recent_activity($course, $isteacher, $timestart) { global $CFG; - // have a look for agreed assessments for this user (agree) + // have a look for agreed assessments for this user (agree) $agreecontent = false; - if (!$isteacher) { // teachers only need to see submissions - if ($logs = workshop_get_agree_logs($course, $timestart)) { - // got some, see if any belong to a visible module - foreach ($logs as $log) { - // Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->workshopid; - //Obtain the visible property from the instance - if (instance_is_visible("workshop",$tempmod)) { - $agreecontent = true; - break; - } - } - // if we got some "live" ones then output them - if ($agreecontent) { - $strftimerecent = get_string("strftimerecent"); - print_headline(get_string("workshopagreedassessments", "workshop").":"); - foreach ($logs as $log) { - //Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->workshopid; - //Obtain the visible property from the instance - if (instance_is_visible("workshop",$tempmod)) { - $date = userdate($log->time, $strftimerecent); - if (isteacher($course->id, $log->userid)) { - echo "

$date - $log->firstname $log->lastname
"; - } - else { // don't break anonymous rule - echo "

$date - A $course->student
"; - } - echo "\"wwwroot/mod/workshop/$log->url\">"; - echo "$log->name"; - echo "\"

"; - } - } - } - } - } - - // have a look for new assessments for this user (assess) + if (!$isteacher) { // teachers only need to see submissions + if ($logs = workshop_get_agree_logs($course, $timestart)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->workshopid; + //Obtain the visible property from the instance + if (instance_is_visible("workshop",$tempmod)) { + $agreecontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($agreecontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("workshopagreedassessments", "workshop").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->workshopid; + //Obtain the visible property from the instance + if (instance_is_visible("workshop",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + if (isteacher($course->id, $log->userid)) { + echo "

$date - $log->firstname $log->lastname
"; + } + else { // don't break anonymous rule + echo "

$date - A $course->student
"; + } + echo "\"wwwroot/mod/workshop/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } + } + + // have a look for new assessments for this user (assess) $assesscontent = false; - if (!$isteacher) { // teachers only need to see submissions - if ($logs = workshop_get_assess_logs($course, $timestart)) { - // got some, see if any belong to a visible module - foreach ($logs as $log) { - // Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->workshopid; - //Obtain the visible property from the instance - if (instance_is_visible("workshop",$tempmod)) { - $assesscontent = true; - break; - } - } - // if we got some "live" ones then output them - if ($assesscontent) { - $strftimerecent = get_string("strftimerecent"); - print_headline(get_string("workshopassessments", "workshop").":"); - foreach ($logs as $log) { - //Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->workshopid; - //Obtain the visible property from the instance - if (instance_is_visible("workshop",$tempmod)) { - $date = userdate($log->time, $strftimerecent); - if (isteacher($course->id, $log->userid)) { - echo "

$date - $log->firstname $log->lastname
"; - } - else { // don't break anonymous rule - echo "

$date - A $course->student
"; - } - echo "\"wwwroot/mod/workshop/$log->url\">"; - echo "$log->name"; - echo "\"

"; - } - } - } - } - } - - // have a look for new comments for this user (comment) + if (!$isteacher) { // teachers only need to see submissions + if ($logs = workshop_get_assess_logs($course, $timestart)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->workshopid; + //Obtain the visible property from the instance + if (instance_is_visible("workshop",$tempmod)) { + $assesscontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($assesscontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("workshopassessments", "workshop").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->workshopid; + //Obtain the visible property from the instance + if (instance_is_visible("workshop",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + if (isteacher($course->id, $log->userid)) { + echo "

$date - $log->firstname $log->lastname
"; + } + else { // don't break anonymous rule + echo "

$date - A $course->student
"; + } + echo "\"wwwroot/mod/workshop/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } + } + + // have a look for new comments for this user (comment) $commentcontent = false; - if (!$isteacher) { // teachers only need to see submissions - if ($logs = workshop_get_comment_logs($course, $timestart)) { - // got some, see if any belong to a visible module - foreach ($logs as $log) { - // Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->workshopid; - //Obtain the visible property from the instance - if (instance_is_visible("workshop",$tempmod)) { - $commentcontent = true; - break; - } - } - // if we got some "live" ones then output them - if ($commentcontent) { - $strftimerecent = get_string("strftimerecent"); - print_headline(get_string("workshopcomments", "workshop").":"); - foreach ($logs as $log) { - //Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->workshopid; - //Obtain the visible property from the instance - if (instance_is_visible("workshop",$tempmod)) { - $date = userdate($log->time, $strftimerecent); - echo "

$date - A $course->student
"; - echo "\"wwwroot/mod/workshop/$log->url\">"; - echo "$log->name"; - echo "\"

"; - } - } - } - } - } - - // have a look for new assessment gradings for this user (grade) + if (!$isteacher) { // teachers only need to see submissions + if ($logs = workshop_get_comment_logs($course, $timestart)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->workshopid; + //Obtain the visible property from the instance + if (instance_is_visible("workshop",$tempmod)) { + $commentcontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($commentcontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("workshopcomments", "workshop").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->workshopid; + //Obtain the visible property from the instance + if (instance_is_visible("workshop",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + echo "

$date - A $course->student
"; + echo "\"wwwroot/mod/workshop/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } + } + + // have a look for new assessment gradings for this user (grade) $gradecontent = false; - if ($logs = workshop_get_grade_logs($course, $timestart)) { - // got some, see if any belong to a visible module - foreach ($logs as $log) { - // Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->workshopid; - //Obtain the visible property from the instance - if (instance_is_visible("workshop",$tempmod)) { - $gradecontent = true; - break; - } - } - // if we got some "live" ones then output them - if ($gradecontent) { - $strftimerecent = get_string("strftimerecent"); - print_headline(get_string("workshopfeedback", "workshop").":"); - foreach ($logs as $log) { - //Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->workshopid; - //Obtain the visible property from the instance - if (instance_is_visible("workshop",$tempmod)) { - $date = userdate($log->time, $strftimerecent); - echo "

$date - $course->teacher
"; - echo "\"wwwroot/mod/workshop/$log->url\">"; - echo "$log->name"; - echo "\"

"; - } - } - } - } - - // have a look for new submissions (only show to teachers) (submit) + if ($logs = workshop_get_grade_logs($course, $timestart)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->workshopid; + //Obtain the visible property from the instance + if (instance_is_visible("workshop",$tempmod)) { + $gradecontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($gradecontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("workshopfeedback", "workshop").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->workshopid; + //Obtain the visible property from the instance + if (instance_is_visible("workshop",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + echo "

$date - $course->teacher
"; + echo "\"wwwroot/mod/workshop/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } + + // have a look for new submissions (only show to teachers) (submit) $submitcontent = false; - if ($isteacher) { - if ($logs = workshop_get_submit_logs($course, $timestart)) { - // got some, see if any belong to a visible module - foreach ($logs as $log) { - // Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->workshopid; - //Obtain the visible property from the instance - if (instance_is_visible("workshop",$tempmod)) { - $submitcontent = true; - break; - } - } - // if we got some "live" ones then output them - if ($submitcontent) { - $strftimerecent = get_string("strftimerecent"); - print_headline(get_string("workshopsubmissions", "workshop").":"); - foreach ($logs as $log) { - //Create a temp valid module structure (only need courseid, moduleid) - $tempmod->course = $course->id; - $tempmod->id = $log->workshopid; - //Obtain the visible property from the instance - if (instance_is_visible("workshop",$tempmod)) { - $date = userdate($log->time, $strftimerecent); - echo "

$date - $log->firstname $log->lastname
"; - echo "\"wwwroot/mod/workshop/$log->url\">"; - echo "$log->name"; - echo "\"

"; - } - } - } - } - } + if ($isteacher) { + if ($logs = workshop_get_submit_logs($course, $timestart)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->workshopid; + //Obtain the visible property from the instance + if (instance_is_visible("workshop",$tempmod)) { + $submitcontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($submitcontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("workshopsubmissions", "workshop").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->workshopid; + //Obtain the visible property from the instance + if (instance_is_visible("workshop",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + echo "

$date - $log->firstname $log->lastname
"; + echo "\"wwwroot/mod/workshop/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } + } return $agreecontent or $assesscontent or $commentcontent or $gradecontent or $submitcontent; } @@ -882,8 +882,8 @@ function workshop_update_instance($workshop) { $workshop->timemodified = time(); $workshop->deadline = make_timestamp($workshop->deadlineyear, - $workshop->deadlinemonth, $workshop->deadlineday, $workshop->deadlinehour, - $workshop->deadlineminute); + $workshop->deadlinemonth, $workshop->deadlineday, $workshop->deadlinehour, + $workshop->deadlineminute); $workshop->id = $workshop->instance; @@ -937,12 +937,12 @@ function workshop_user_complete($course, $user, $mod, $workshop) { /////////////////////////////////////////////////////////////////////////////// function workshop_user_outline($course, $user, $mod, $workshop) { if ($submissions = workshop_get_user_submissions($workshop, $user)) { - $result->info = count($submissions)." ".get_string("submissions", "workshop"); - // workshop_get_user_submissions returns the newest one first - foreach ($submissions as $submission) { - $result->time = $submission->timecreated; - break; - } + $result->info = count($submissions)." ".get_string("submissions", "workshop"); + // workshop_get_user_submissions returns the newest one first + foreach ($submissions as $submission) { + $result->time = $submission->timecreated; + break; + } return $result; } return NULL; @@ -1098,13 +1098,13 @@ function workshop_choose_from_menu ($options, $name, $selected="", $nothing="cho if ($value == $selected) { $output .= " SELECTED"; } - // stop zero label being replaced by array index value + // stop zero label being replaced by array index value // if ($label) { // $output .= ">$label\n"; // } else { // $output .= ">$value\n"; - // } - $output .= ">$label\n"; + // } + $output .= ">$label\n"; } } @@ -1120,43 +1120,43 @@ function workshop_choose_from_menu ($options, $name, $selected="", $nothing="cho /////////////////////////////////////////////////////////////////////////////////////////////// function workshop_copy_assessment($assessment, $submission, $withfeedback = false) { - // adds a copy of the given assessment for the submission specified to the workshop_assessments table. - // The grades and optionally the comments are added to the workshop_grades table. Returns the new - // assessment object. The owner of the assessment is not changed. - - $yearfromnow = time() + 365 * 86400; - $newassessment->workshopid = $assessment->workshopid; - $newassessment->submissionid = $submission->id; - $newassessment->userid = $assessment->userid; - $newassessment->timecreated = $yearfromnow; - $newassessment->grade = $assessment->grade; - if ($withfeedback) { - $newassessment->generalcomment = addslashes($assessment->generalcomment); - $newassessment->teachercomment = addslashes($assessment->teachercomment); - } - if (!$newassessment->id = insert_record("workshop_assessments", $newassessment)) { - error("Copy Assessment: Could not insert workshop assessment!"); - } - - if ($grades = get_records("workshop_grades", "assessmentid", $assessment->id)) { - foreach ($grades as $grade) { - if (!$withfeedback) { - $grade->feedback = ''; - } + // adds a copy of the given assessment for the submission specified to the workshop_assessments table. + // The grades and optionally the comments are added to the workshop_grades table. Returns the new + // assessment object. The owner of the assessment is not changed. + + $yearfromnow = time() + 365 * 86400; + $newassessment->workshopid = $assessment->workshopid; + $newassessment->submissionid = $submission->id; + $newassessment->userid = $assessment->userid; + $newassessment->timecreated = $yearfromnow; + $newassessment->grade = $assessment->grade; + if ($withfeedback) { + $newassessment->generalcomment = addslashes($assessment->generalcomment); + $newassessment->teachercomment = addslashes($assessment->teachercomment); + } + if (!$newassessment->id = insert_record("workshop_assessments", $newassessment)) { + error("Copy Assessment: Could not insert workshop assessment!"); + } + + if ($grades = get_records("workshop_grades", "assessmentid", $assessment->id)) { + foreach ($grades as $grade) { + if (!$withfeedback) { + $grade->feedback = ''; + } else { $grade->feedback = addslashes($grade->feedback); } - $grade->assessmentid = $newassessment->id; - if (!$grade->id = insert_record("workshop_grades", $grade)) { - error("Copy Assessment: Could not insert workshop grade!"); - } - } - } - if ($withfeedback) { + $grade->assessmentid = $newassessment->id; + if (!$grade->id = insert_record("workshop_grades", $grade)) { + error("Copy Assessment: Could not insert workshop grade!"); + } + } + } + if ($withfeedback) { // remove the slashes from comments as the new assessment record might be used, // currently this function is only called in upload which does not! - $newassessment->generalcomment = stripslashes($assessment->generalcomment); - $newassessment->teachercomment = stripslashes($assessment->teachercomment); + $newassessment->generalcomment = stripslashes($assessment->generalcomment); + $newassessment->teachercomment = stripslashes($assessment->teachercomment); } return $newassessment; } @@ -1165,23 +1165,23 @@ function workshop_copy_assessment($assessment, $submission, $withfeedback = fals ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_all_submissions_for_assessment($workshop, $user) { - // looks at all submissions and deducts the number which has been assessed by this user - $n = 0; - if ($submissions = get_records_select("workshop_submissions", "workshopid = $workshop->id AND + // looks at all submissions and deducts the number which has been assessed by this user + $n = 0; + if ($submissions = get_records_select("workshop_submissions", "workshopid = $workshop->id AND timecreated > 0")) { - $n =count($submissions); - foreach ($submissions as $submission) { - $n -= count_records("workshop_assessments", "submissionid", $submission->id, "userid", $user->id); - } - } - return $n; - } + $n =count($submissions); + foreach ($submissions as $submission) { + $n -= count_records("workshop_assessments", "submissionid", $submission->id, "userid", $user->id); + } + } + return $n; + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_assessments($submission) { - // Return the (real) assessments for this submission, - $timenow = time(); + // Return the (real) assessments for this submission, + $timenow = time(); return count_records_select("workshop_assessments", "submissionid = $submission->id AND timecreated < $timenow"); } @@ -1189,254 +1189,254 @@ function workshop_count_assessments($submission) { ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_comments($assessment) { - // Return the number of comments for this assessment provided they are newer than the assessment, + // Return the number of comments for this assessment provided they are newer than the assessment, return count_records_select("workshop_comments", "(assessmentid = $assessment->id) AND - timecreated > $assessment->timecreated"); + timecreated > $assessment->timecreated"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_peer_assessments($workshop, $user) { - // returns the number of assessments made by students on user's submissions - - $n = 0; - if ($submissions = workshop_get_user_submissions($workshop, $user)) { - foreach ($submissions as $submission) { - if ($assessments = workshop_get_assessments($submission)) { - foreach ($assessments as $assessment) { - // ignore teacher assessments - if (!isteacher($workshop->course, $assessment->userid)) { - $n++; - } - } - } - } - } - return $n; - } + // returns the number of assessments made by students on user's submissions + + $n = 0; + if ($submissions = workshop_get_user_submissions($workshop, $user)) { + foreach ($submissions as $submission) { + if ($assessments = workshop_get_assessments($submission)) { + foreach ($assessments as $assessment) { + // ignore teacher assessments + if (!isteacher($workshop->course, $assessment->userid)) { + $n++; + } + } + } + } + } + return $n; + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_self_assessments($workshop, $user) { - // returns the number of assessments made by user on their own submissions - - $n = 0; - if ($submissions = workshop_get_user_submissions($workshop, $user)) { - foreach ($submissions as $submission) { - if ($assessment = get_record_select("workshop_assessments", "userid = $user->id AND - submissionid = $submission->id")) { - $n++; - } - } - } - return $n; - } + // returns the number of assessments made by user on their own submissions + + $n = 0; + if ($submissions = workshop_get_user_submissions($workshop, $user)) { + foreach ($submissions as $submission) { + if ($assessment = get_record_select("workshop_assessments", "userid = $user->id AND + submissionid = $submission->id")) { + $n++; + } + } + } + return $n; + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_student_submissions($workshop) { - global $CFG; - - return count_records_sql("SELECT count(*) FROM {$CFG->prefix}workshop_submissions s, + global $CFG; + + return count_records_sql("SELECT count(*) FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}user_students u - WHERE u.course = $workshop->course + WHERE u.course = $workshop->course AND s.userid = u.userid AND s.workshopid = $workshop->id - AND timecreated > 0"); - } + AND timecreated > 0"); + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_student_submissions_for_assessment($workshop, $user) { - global $CFG; - - $timenow = time(); - $n = 0; - if ($submissions = workshop_get_student_submissions($workshop)) { - $n =count($submissions); - foreach ($submissions as $submission) { - $n -= count_records_select("workshop_assessments", "submissionid = $submission->id AND - userid = $user->id AND timecreated < $timenow - $CFG->maxeditingtime"); - } - } - return $n; - } + global $CFG; + + $timenow = time(); + $n = 0; + if ($submissions = workshop_get_student_submissions($workshop)) { + $n =count($submissions); + foreach ($submissions as $submission) { + $n -= count_records_select("workshop_assessments", "submissionid = $submission->id AND + userid = $user->id AND timecreated < $timenow - $CFG->maxeditingtime"); + } + } + return $n; + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_teacher_assessments($workshop, $user) { - // returns the number of assessments made by teachers on user's submissions - - $n = 0; - if ($submissions = workshop_get_user_submissions($workshop, $user)) { - foreach ($submissions as $submission) { - if ($assessments = workshop_get_assessments($submission)) { - foreach ($assessments as $assessment) { - // count only teacher assessments - if (isteacher($workshop->course, $assessment->userid)) { - $n++; - } - } - } - } - } - return $n; - } + // returns the number of assessments made by teachers on user's submissions + + $n = 0; + if ($submissions = workshop_get_user_submissions($workshop, $user)) { + foreach ($submissions as $submission) { + if ($assessments = workshop_get_assessments($submission)) { + foreach ($assessments as $assessment) { + // count only teacher assessments + if (isteacher($workshop->course, $assessment->userid)) { + $n++; + } + } + } + } + } + return $n; + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_teacher_submissions($workshop) { - global $CFG; - - return count_records_sql("SELECT count(*) FROM {$CFG->prefix}workshop_submissions s, - {$CFG->prefix}user_teachers u - WHERE u.course = $workshop->course + global $CFG; + + return count_records_sql("SELECT count(*) FROM {$CFG->prefix}workshop_submissions s, + {$CFG->prefix}user_teachers u + WHERE u.course = $workshop->course AND s.userid = u.userid AND s.workshopid = $workshop->id"); - } + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_teacher_submissions_for_assessment($workshop, $user) { - $n = 0; - if ($submissions = workshop_get_teacher_submissions($workshop)) { - $n =count($submissions); - foreach ($submissions as $submission) { - $n -= count_records("workshop_assessments", "submissionid", $submission->id, "userid", $user->id); - } - } - return $n; - } + $n = 0; + if ($submissions = workshop_get_teacher_submissions($workshop)) { + $n =count($submissions); + foreach ($submissions as $submission) { + $n -= count_records("workshop_assessments", "submissionid", $submission->id, "userid", $user->id); + } + } + return $n; + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_ungraded_assessments_student($workshop) { - // function returns the number of ungraded assessments by students of STUDENT submissions - $n = 0; - if ($submissions = workshop_get_student_submissions($workshop)) { - foreach ($submissions as $submission) { - if ($assessments = workshop_get_assessments($submission)) { - foreach ($assessments as $assessment) { - if ($assessment->timegraded == 0) { - // ignore teacher assessments - if (!isteacher($workshop->course, $assessment->userid)) { - $n++; - } - } - } - } - } - } - return $n; - } + // function returns the number of ungraded assessments by students of STUDENT submissions + $n = 0; + if ($submissions = workshop_get_student_submissions($workshop)) { + foreach ($submissions as $submission) { + if ($assessments = workshop_get_assessments($submission)) { + foreach ($assessments as $assessment) { + if ($assessment->timegraded == 0) { + // ignore teacher assessments + if (!isteacher($workshop->course, $assessment->userid)) { + $n++; + } + } + } + } + } + } + return $n; + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_ungraded_assessments_teacher($workshop) { - // function returns the number of ungraded assessments by students of TEACHER submissions - global $CFG; - - $timenow = time(); - $n = 0; - if ($submissions = workshop_get_teacher_submissions($workshop)) { - foreach ($submissions as $submission) { - if ($assessments = workshop_get_assessments($submission)) { - foreach ($assessments as $assessment) { - if ($assessment->timegraded == 0) { - // ignore teacher assessments - if (!isteacher($workshop->course, $assessment->userid)) { - // must have created a little time ago - if (($timenow - $assessment->timecreated) > $CFG->maxeditingtime) { - $n++; - } - } - } - } - } - } - } - return $n; - } + // function returns the number of ungraded assessments by students of TEACHER submissions + global $CFG; + + $timenow = time(); + $n = 0; + if ($submissions = workshop_get_teacher_submissions($workshop)) { + foreach ($submissions as $submission) { + if ($assessments = workshop_get_assessments($submission)) { + foreach ($assessments as $assessment) { + if ($assessment->timegraded == 0) { + // ignore teacher assessments + if (!isteacher($workshop->course, $assessment->userid)) { + // must have created a little time ago + if (($timenow - $assessment->timecreated) > $CFG->maxeditingtime) { + $n++; + } + } + } + } + } + } + } + return $n; + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_user_assessments($workshop, $user, $stype = "all") { - // returns the number of assessments allocated/made by a user, all of them, or just those + // returns the number of assessments allocated/made by a user, all of them, or just those // for the student or teacher submissions. The student's self assessments are included in the count. - // The maxeditingtime is NOT taken into account here also, allocated assessments which have not yet - // been done are counted as well - - $n = 0; - if ($assessments = workshop_get_user_assessments($workshop, $user)) { - foreach ($assessments as $assessment) { - switch ($stype) { - case "all" : - $n++; - break; - case "student" : - $submission = get_record("workshop_submissions", "id", $assessment->submissionid); - if (isstudent($workshop->course, $submission->userid)) { - $n++; - } - break; - case "teacher" : - $submission = get_record("workshop_submissions", "id", $assessment->submissionid); - if (isteacher($workshop->course, $submission->userid)) { - $n++; - } - break; - } - } - } - return $n; - } - - -////////////////////////////////////////////////////////////////////////////////////// -function workshop_count_user_assessments_done($workshop, $user) { - // returns the number of assessments actually done by a user - // the student's self assessments are included in the count - // the maxeditingtime is NOT taken into account here - - $n = 0; - $timenow = time(); - if ($assessments = workshop_get_user_assessments($workshop, $user)) { - foreach ($assessments as $assessment) { - if ($assessment->timecreated < $timenow) { - $n++; - } - } - } - return $n; - } - + // The maxeditingtime is NOT taken into account here also, allocated assessments which have not yet + // been done are counted as well + + $n = 0; + if ($assessments = workshop_get_user_assessments($workshop, $user)) { + foreach ($assessments as $assessment) { + switch ($stype) { + case "all" : + $n++; + break; + case "student" : + $submission = get_record("workshop_submissions", "id", $assessment->submissionid); + if (isstudent($workshop->course, $submission->userid)) { + $n++; + } + break; + case "teacher" : + $submission = get_record("workshop_submissions", "id", $assessment->submissionid); + if (isteacher($workshop->course, $submission->userid)) { + $n++; + } + break; + } + } + } + return $n; + } + + +////////////////////////////////////////////////////////////////////////////////////// +function workshop_count_user_assessments_done($workshop, $user) { + // returns the number of assessments actually done by a user + // the student's self assessments are included in the count + // the maxeditingtime is NOT taken into account here + + $n = 0; + $timenow = time(); + if ($assessments = workshop_get_user_assessments($workshop, $user)) { + foreach ($assessments as $assessment) { + if ($assessment->timecreated < $timenow) { + $n++; + } + } + } + return $n; + } + ////////////////////////////////////////////////////////////////////////////////////// function workshop_count_user_submissions($workshop, $user) { - // returns the number of (real) submissions make by this user - return count_records_select("workshop_submissions", "workshopid = $workshop->id AND - userid = $user->id AND timecreated > 0"); - } + // returns the number of (real) submissions make by this user + return count_records_select("workshop_submissions", "workshopid = $workshop->id AND + userid = $user->id AND timecreated > 0"); + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_delete_submitted_files($workshop, $submission) { // Deletes the files in the workshop area for this submission - if ($basedir = workshop_file_area($workshop, $submission)) { - if ($files = get_directory_list($basedir)) { - foreach ($files as $file) { - if (unlink("$basedir/$file")) { - notify("Existing file '$file' has been deleted!"); - } - else { - notify("Attempt to delete file $basedir/$file has failed!"); - } - } - } - } - } + if ($basedir = workshop_file_area($workshop, $submission)) { + if ($files = get_directory_list($basedir)) { + foreach ($files as $file) { + if (unlink("$basedir/$file")) { + notify("Existing file '$file' has been deleted!"); + } + else { + notify("Attempt to delete file $basedir/$file has failed!"); + } + } + } + } + } ////////////////////////////////////////////////////////////////////////////////////// @@ -1445,22 +1445,22 @@ function workshop_delete_user_files($workshop, $user, $exception) { // EXCEPT for any file named $exception if (!$submissions = workshop_get_submissions($workshop, $user)) { - notify("No submissions!"); - return; - } - foreach ($submissions as $submission) { - if ($basedir = workshop_file_area($workshop, $submission)) { - if ($files = get_directory_list($basedir)) { - foreach ($files as $file) { - if ($file != $exception) { - unlink("$basedir/$file"); - notify("Existing file '$file' has been deleted!"); - } - } - } - } - } - } + notify("No submissions!"); + return; + } + foreach ($submissions as $submission) { + if ($basedir = workshop_file_area($workshop, $submission)) { + if ($files = get_directory_list($basedir)) { + foreach ($files as $file) { + if ($file != $exception) { + unlink("$basedir/$file"); + notify("Existing file '$file' has been deleted!"); + } + } + } + } + } + } ////////////////////////////////////////////////////////////////////////////////////// @@ -1480,133 +1480,145 @@ function workshop_file_area_name($workshop, $submission) { /////////////////////////////////////////////////////////////////////////////////////////////// function workshop_get_agree_logs($course, $timestart) { - // get the "agree" entries for this user (the assessment owner and add the first and last names + // get the "agree" entries for this user (the assessment owner and add the first and last names // the last two probably wont be used... - global $CFG, $USER; - - $timethen = time() - $CFG->maxeditingtime; + global $CFG, $USER; + if (empty($USER->id)) { + return false; + } + + $timethen = time() - $CFG->maxeditingtime; return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, a.workshopid, a.userid, e.name FROM {$CFG->prefix}log l, - {$CFG->prefix}workshop e, - {$CFG->prefix}workshop_submissions s, - {$CFG->prefix}workshop_assessments a, - {$CFG->prefix}user u + {$CFG->prefix}workshop e, + {$CFG->prefix}workshop_submissions s, + {$CFG->prefix}workshop_assessments a, + {$CFG->prefix}user u WHERE l.time > $timestart AND l.time < $timethen - AND l.course = $course->id AND l.module = 'workshop' AND l.action = 'agree' - AND a.id = l.info AND s.id = a.submissionid AND a.userid = $USER->id - AND u.id = s.userid AND e.id = a.workshopid"); + AND l.course = $course->id AND l.module = 'workshop' AND l.action = 'agree' + AND a.id = l.info AND s.id = a.submissionid AND a.userid = $USER->id + AND u.id = s.userid AND e.id = a.workshopid"); } /////////////////////////////////////////////////////////////////////////////////////////////// function workshop_get_assess_logs($course, $timestart) { - // get the "assess" entries for this user and add the first and last names... - global $CFG, $USER; - - $timethen = time() - $CFG->maxeditingtime; + // get the "assess" entries for this user and add the first and last names... + global $CFG, $USER; + if (empty($USER->id)) { + return false; + } + + $timethen = time() - $CFG->maxeditingtime; return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, a.workshopid, a.userid, e.name FROM {$CFG->prefix}log l, - {$CFG->prefix}workshop e, - {$CFG->prefix}workshop_submissions s, - {$CFG->prefix}workshop_assessments a, - {$CFG->prefix}user u + {$CFG->prefix}workshop e, + {$CFG->prefix}workshop_submissions s, + {$CFG->prefix}workshop_assessments a, + {$CFG->prefix}user u WHERE l.time > $timestart AND l.time < $timethen - AND l.course = $course->id AND l.module = 'workshop' AND l.action = 'assess' - AND a.id = l.info AND s.id = a.submissionid AND s.userid = $USER->id - AND u.id = a.userid AND e.id = a.workshopid"); + AND l.course = $course->id AND l.module = 'workshop' AND l.action = 'assess' + AND a.id = l.info AND s.id = a.submissionid AND s.userid = $USER->id + AND u.id = a.userid AND e.id = a.workshopid"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_assessments($submission, $all = '') { - // Return assessments for this submission ordered oldest first, newest last - // new assessments made within the editing time are NOT return unless the - // second argument is set to ALL - global $CFG; - - if ($all != 'ALL') { - $timenow = time(); - return get_records_select("workshop_assessments", "(submissionid = $submission->id) AND - (timecreated < $timenow - $CFG->maxeditingtime)", "timecreated DESC"); - } else { - return get_records_select("workshop_assessments", "submissionid = $submission->id", + // Return assessments for this submission ordered oldest first, newest last + // new assessments made within the editing time are NOT return unless the + // second argument is set to ALL + global $CFG; + + if ($all != 'ALL') { + $timenow = time(); + return get_records_select("workshop_assessments", "(submissionid = $submission->id) AND + (timecreated < $timenow - $CFG->maxeditingtime)", "timecreated DESC"); + } else { + return get_records_select("workshop_assessments", "submissionid = $submission->id", "timecreated DESC"); - } + } } /////////////////////////////////////////////////////////////////////////////////////////////// function workshop_get_comment_logs($course, $timestart) { - // get the "comment" entries for this user and add the first and last names (which may not be used)... - global $CFG, $USER; - - $timethen = time() - $CFG->maxeditingtime; + // get the "comment" entries for this user and add the first and last names (which may not be used)... + global $CFG, $USER; + if (empty($USER->id)) { + return false; + } + + $timethen = time() - $CFG->maxeditingtime; return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, a.workshopid, e.name FROM {$CFG->prefix}log l, - {$CFG->prefix}workshop e, - {$CFG->prefix}workshop_submissions s, - {$CFG->prefix}workshop_assessments a, - {$CFG->prefix}workshop_comments c, - {$CFG->prefix}user u + {$CFG->prefix}workshop e, + {$CFG->prefix}workshop_submissions s, + {$CFG->prefix}workshop_assessments a, + {$CFG->prefix}workshop_comments c, + {$CFG->prefix}user u WHERE l.time > $timestart AND l.time < $timethen - AND l.course = $course->id AND l.module = 'workshop' AND l.action = 'comment' - AND c.id = l.info AND c.userid != $USER->id AND a.id = c.assessmentid - AND s.id = a.submissionid AND (s.userid = $USER->id OR a.userid = $USER->id) - AND u.id = a.userid AND e.id = a.workshopid"); + AND l.course = $course->id AND l.module = 'workshop' AND l.action = 'comment' + AND c.id = l.info AND c.userid != $USER->id AND a.id = c.assessmentid + AND s.id = a.submissionid AND (s.userid = $USER->id OR a.userid = $USER->id) + AND u.id = a.userid AND e.id = a.workshopid"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_comments($assessment) { - // Return all comments for this assessment provided they are newer than the assessment, - // and ordered oldest first, newest last + // Return all comments for this assessment provided they are newer than the assessment, + // and ordered oldest first, newest last return get_records_select("workshop_comments", "(assessmentid = $assessment->id) AND - timecreated > $assessment->timecreated", - "timecreated DESC"); + timecreated > $assessment->timecreated", + "timecreated DESC"); } /////////////////////////////////////////////////////////////////////////////////////////////// function workshop_get_grade_logs($course, $timestart) { - // get the "grade" entries for this user and add the first and last names (of submission owner, + // get the "grade" entries for this user and add the first and last names (of submission owner, // better to get name of teacher... - // ...but not available in assessment record...) - global $CFG, $USER; - - $timethen = time() - $CFG->maxeditingtime; + // ...but not available in assessment record...) + global $CFG, $USER; + if (empty($USER->id)) { + return false; + } + + $timethen = time() - $CFG->maxeditingtime; return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, a.workshopid, e.name FROM {$CFG->prefix}log l, - {$CFG->prefix}workshop e, - {$CFG->prefix}workshop_submissions s, - {$CFG->prefix}workshop_assessments a, - {$CFG->prefix}user u + {$CFG->prefix}workshop e, + {$CFG->prefix}workshop_submissions s, + {$CFG->prefix}workshop_assessments a, + {$CFG->prefix}user u WHERE l.time > $timestart AND l.time < $timethen - AND l.course = $course->id AND l.module = 'workshop' AND l.action = 'grade' - AND a.id = l.info AND s.id = a.submissionid AND a.userid = $USER->id - AND u.id = s.userid AND e.id = a.workshopid"); + AND l.course = $course->id AND l.module = 'workshop' AND l.action = 'grade' + AND a.id = l.info AND s.id = a.submissionid AND a.userid = $USER->id + AND u.id = s.userid AND e.id = a.workshopid"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_student_assessments($workshop, $user) { // Return all assessments on the student submissions by a user, order by youngest first, oldest last - global $CFG; - + global $CFG; + return get_records_sql("SELECT a.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}user_students u, - {$CFG->prefix}workshop_assessments a + {$CFG->prefix}workshop_assessments a WHERE u.course = $workshop->course AND s.userid = u.userid AND s.workshopid = $workshop->id - AND a.submissionid = s.id - AND a.userid = $user->id - ORDER BY a.timecreated DESC"); + AND a.submissionid = s.id + AND a.userid = $user->id + ORDER BY a.timecreated DESC"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_student_submission($workshop, $user) { // Return a submission for a particular user - global $CFG; + global $CFG; $submission = get_record("workshop_submissions", "workshopid", $workshop->id, "userid", $user->id); if (!empty($submission->timecreated)) { @@ -1619,154 +1631,154 @@ function workshop_get_student_submission($workshop, $user) { ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_student_submission_assessments($workshop) { // Return all assessments on the student submissions, order by youngest first, oldest last - global $CFG; - + global $CFG; + return get_records_sql("SELECT a.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}user_students u, {$CFG->prefix}workshop_assessments a WHERE u.course = $workshop->course AND s.userid = u.userid AND s.workshopid = $workshop->id - AND a.submissionid = s.id - ORDER BY a.timecreated DESC"); + AND a.submissionid = s.id + ORDER BY a.timecreated DESC"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_student_submissions($workshop, $order = "title") { // Return all ENROLLED student submissions - global $CFG; - - if ($order == "title") { - $order = "s.title"; - } - if ($order == "name") { - $order = "a.firstname, a.lastname"; - } - if ($order == "grade") { - $order = "$workshop->teacherweight * s.teachergrade + $workshop->peerweight * s.peergrade DESC"; - } - return get_records_sql("SELECT s.* FROM {$CFG->prefix}workshop_submissions s, + global $CFG; + + if ($order == "title") { + $order = "s.title"; + } + if ($order == "name") { + $order = "a.firstname, a.lastname"; + } + if ($order == "grade") { + $order = "$workshop->teacherweight * s.teachergrade + $workshop->peerweight * s.peergrade DESC"; + } + return get_records_sql("SELECT s.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}user_students u, {$CFG->prefix}user a WHERE u.course = $workshop->course AND s.userid = u.userid - AND a.id = u.userid + AND a.id = u.userid AND s.workshopid = $workshop->id - AND s.timecreated > 0 - ORDER BY $order"); + AND s.timecreated > 0 + ORDER BY $order"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_submission_assessment($submission, $user) { - // Return the user's assessment for this submission (cold or warm, not hot) + // Return the user's assessment for this submission (cold or warm, not hot) $timenow = time(); - return get_record_select("workshop_assessments", "submissionid = $submission->id AND + return get_record_select("workshop_assessments", "submissionid = $submission->id AND userid = $user->id AND timecreated < $timenow"); } /////////////////////////////////////////////////////////////////////////////////////////////// function workshop_get_submit_logs($course, $timestart) { - // get the "submit" entries and add the first and last names... - global $CFG, $USER; - - $timethen = time() - $CFG->maxeditingtime; + // get the "submit" entries and add the first and last names... + global $CFG, $USER; + + $timethen = time() - $CFG->maxeditingtime; return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, l.info workshopid, e.name FROM {$CFG->prefix}log l, - {$CFG->prefix}workshop e, - {$CFG->prefix}user u + {$CFG->prefix}workshop e, + {$CFG->prefix}user u WHERE l.time > $timestart AND l.time < $timethen - AND l.course = $course->id AND l.module = 'workshop' - AND l.action = 'submit' - AND e.id = l.info - AND u.id = l.userid"); + AND l.course = $course->id AND l.module = 'workshop' + AND l.action = 'submit' + AND e.id = l.info + AND u.id = l.userid"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_teacher_submission_assessments($workshop) { // Return all assessments on the teacher submissions, order by youngest first, oldest last - global $CFG; - + global $CFG; + return get_records_sql("SELECT a.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}user_teachers u, {$CFG->prefix}workshop_assessments a WHERE u.course = $workshop->course AND s.userid = u.userid AND s.workshopid = $workshop->id - AND a.submissionid = s.id - ORDER BY a.timecreated DESC"); + AND a.submissionid = s.id + ORDER BY a.timecreated DESC"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_teacher_submissions($workshop) { // Return all teacher submissions, ordered by title - global $CFG; - - return get_records_sql("SELECT s.* FROM {$CFG->prefix}workshop_submissions s, + global $CFG; + + return get_records_sql("SELECT s.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}user_teachers u WHERE u.course = $workshop->course AND s.userid = u.userid AND s.workshopid = $workshop->id - ORDER BY s.title"); + ORDER BY s.title"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_ungraded_assessments($workshop) { - global $CFG; - // Return all assessments which have not been graded or just graded - $cutofftime =time() - $CFG->maxeditingtime; + global $CFG; + // Return all assessments which have not been graded or just graded + $cutofftime =time() - $CFG->maxeditingtime; return get_records_select("workshop_assessments", "workshopid = $workshop->id AND (timegraded = 0 OR - timegraded > $cutofftime)", "timecreated"); - } + timegraded > $cutofftime)", "timecreated"); + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_ungraded_assessments_student($workshop) { - global $CFG; - // Return all assessments which have not been graded or just graded of student's submissions - - $cutofftime = time() - $CFG->maxeditingtime; + global $CFG; + // Return all assessments which have not been graded or just graded of student's submissions + + $cutofftime = time() - $CFG->maxeditingtime; return get_records_sql("SELECT a.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}user_students u, {$CFG->prefix}workshop_assessments a WHERE u.course = $workshop->course AND s.userid = u.userid AND s.workshopid = $workshop->id - AND a.submissionid = s.id - AND (a.timegraded = 0 OR a.timegraded > $cutofftime) - AND a.timecreated < $cutofftime - ORDER BY a.timecreated ASC"); - } + AND a.submissionid = s.id + AND (a.timegraded = 0 OR a.timegraded > $cutofftime) + AND a.timecreated < $cutofftime + ORDER BY a.timecreated ASC"); + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_ungraded_assessments_teacher($workshop) { - global $CFG; - // Return all assessments which have not been graded or just graded of teacher's submissions - - $cutofftime =time() - $CFG->maxeditingtime; + global $CFG; + // Return all assessments which have not been graded or just graded of teacher's submissions + + $cutofftime =time() - $CFG->maxeditingtime; return get_records_sql("SELECT a.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}user_teachers u, {$CFG->prefix}workshop_assessments a WHERE u.course = $workshop->course AND s.userid = u.userid AND s.workshopid = $workshop->id - AND a.submissionid = s.id - AND (a.timegraded = 0 OR a.timegraded > $cutofftime) - AND a.timecreated < $cutofftime - ORDER BY a.timecreated ASC"); - } + AND a.submissionid = s.id + AND (a.timegraded = 0 OR a.timegraded > $cutofftime) + AND a.timecreated < $cutofftime + ORDER BY a.timecreated ASC"); + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_unmailed_assessments($cutofftime) { - /// Return list of (ungraded) assessments that have not been mailed out + /// Return list of (ungraded) assessments that have not been mailed out global $CFG; return get_records_sql("SELECT a.*, g.course, g.name FROM {$CFG->prefix}workshop_assessments a, {$CFG->prefix}workshop g WHERE a.mailed = 0 - AND a.timegraded = 0 + AND a.timegraded = 0 AND a.timecreated < $cutofftime AND g.id = a.workshopid"); } @@ -1774,37 +1786,37 @@ function workshop_get_unmailed_assessments($cutofftime) { ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_unmailed_comments($cutofftime) { - /// Return list of comments that have not been mailed out + /// Return list of comments that have not been mailed out global $CFG; return get_records_sql("SELECT c.*, g.course, g.name FROM {$CFG->prefix}workshop_comments c, {$CFG->prefix}workshop g WHERE c.mailed = 0 - AND c.timecreated < $cutofftime + AND c.timecreated < $cutofftime AND g.id = c.workshopid"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_unmailed_graded_assessments($cutofftime) { - /// Return list of graded assessments that have not been mailed out + /// Return list of graded assessments that have not been mailed out global $CFG; return get_records_sql("SELECT a.*, g.course, g.name FROM {$CFG->prefix}workshop_assessments a, {$CFG->prefix}workshop g WHERE a.mailed = 0 - AND a.timegraded < $cutofftime - AND a.timegraded > 0 + AND a.timegraded < $cutofftime + AND a.timegraded > 0 AND g.id = a.workshopid"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_unmailed_resubmissions($cutofftime) { - /// Return list of assessments of resubmissions that have not been mailed out + /// Return list of assessments of resubmissions that have not been mailed out global $CFG; return get_records_sql("SELECT a.*, w.course, w.name FROM {$CFG->prefix}workshop_assessments a, {$CFG->prefix}workshop w WHERE a.mailed = 0 - AND a.resubmission = 1 + AND a.resubmission = 1 AND w.id = a.workshopid"); } @@ -1812,8 +1824,8 @@ function workshop_get_unmailed_resubmissions($cutofftime) { ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_user_assessments($workshop, $user) { // Return all the user's assessments, newest first, oldest last (hot, warm and cold ones) - return get_records_select("workshop_assessments", "workshopid = $workshop->id AND userid = $user->id", - "timecreated DESC"); + return get_records_select("workshop_assessments", "workshopid = $workshop->id AND userid = $user->id", + "timecreated DESC"); } @@ -1822,26 +1834,26 @@ function workshop_get_user_assessments_done($workshop, $user) { // Return all the user's assessments, newest first, oldest last (warm and cold ones only) // ignores maxeditingtime $timenow = time(); - return get_records_select("workshop_assessments", "workshopid = $workshop->id AND userid = $user->id + return get_records_select("workshop_assessments", "workshopid = $workshop->id AND userid = $user->id AND timecreated < $timenow", - "timecreated DESC"); + "timecreated DESC"); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_user_submissions($workshop, $user) { - // return real submissions of user newest first, oldest last. Ignores the dummy submissions - // which get created to hold the final grades for users for make no submissions) + // return real submissions of user newest first, oldest last. Ignores the dummy submissions + // which get created to hold the final grades for users for make no submissions) return get_records_select("workshop_submissions", "workshopid = $workshop->id AND - userid = $user->id AND timecreated > 0", "timecreated DESC" ); + userid = $user->id AND timecreated > 0", "timecreated DESC" ); } ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_users_done($workshop) { - global $CFG; + global $CFG; return get_records_sql("SELECT u.* - FROM {$CFG->prefix}user u, {$CFG->prefix}user_students s, + FROM {$CFG->prefix}user u, {$CFG->prefix}user_students s, {$CFG->prefix}workshop_submissions a WHERE s.course = '$workshop->course' AND s.user = u.id AND u.id = a.user AND a.workshop = '$workshop->id' @@ -1851,353 +1863,353 @@ function workshop_get_users_done($workshop) { ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_all_submissions($workshop, $user) { - // list the teacher sublmissions first - global $CFG; - + // list the teacher sublmissions first + global $CFG; + if (! $course = get_record("course", "id", $workshop->course)) { error("Course is misconfigured"); } - $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), + $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop")); - $table->align = array ("left", "left", "left"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - if ($submissions = workshop_get_teacher_submissions($workshop)) { - foreach ($submissions as $submission) { - if ($submission->userid == $user->id) { - $comment = get_string("ownwork", "workshop")."; "; - } - else { - $comment = ""; - } - // has user already assessed this submission - if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id - AND userid = $user->id")) { - $curtime = time(); - if (($curtime - $assessment->timecreated) > $CFG->maxeditingtime) { - $action = "id&aid=$assessment->id\">" - .get_string("view", "workshop").""; - // has teacher graded user's assessment? - if ($assessment->timegraded) { - if (($curtime - $assessment->timegraded) > $CFG->maxeditingtime) { - $comment .= get_string("gradedbyteacher", "workshop", $course->teacher); - } - } - } - else { // there's still time left to edit... - $action = "id&sid=$submission->id\">". - get_string("edit", "workshop").""; - } - } - else { // user has not graded this submission - $action = "id&sid=$submission->id\">". - get_string("assess", "workshop").""; - } - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, + $table->align = array ("left", "left", "left"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + if ($submissions = workshop_get_teacher_submissions($workshop)) { + foreach ($submissions as $submission) { + if ($submission->userid == $user->id) { + $comment = get_string("ownwork", "workshop")."; "; + } + else { + $comment = ""; + } + // has user already assessed this submission + if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id + AND userid = $user->id")) { + $curtime = time(); + if (($curtime - $assessment->timecreated) > $CFG->maxeditingtime) { + $action = "id&aid=$assessment->id\">" + .get_string("view", "workshop").""; + // has teacher graded user's assessment? + if ($assessment->timegraded) { + if (($curtime - $assessment->timegraded) > $CFG->maxeditingtime) { + $comment .= get_string("gradedbyteacher", "workshop", $course->teacher); + } + } + } + else { // there's still time left to edit... + $action = "id&sid=$submission->id\">". + get_string("edit", "workshop").""; + } + } + else { // user has not graded this submission + $action = "id&sid=$submission->id\">". + get_string("assess", "workshop").""; + } + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); - } - print_table($table); - } + } + print_table($table); + } - echo "

".get_string("studentsubmissions", "workshop", $course->student). + echo "

".get_string("studentsubmissions", "workshop", $course->student). "


\n"; - unset($table); - $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), + unset($table); + $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - if ($submissions = workshop_get_student_submissions($workshop)) { - foreach ($submissions as $submission) { - if ($submission->userid == $user->id) { - $comment = get_string("ownwork", "workshop")."; "; - } - else { - $comment = ""; - } - // has user already assessed this submission - if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id - AND userid = $user->id")) { - $curtime = time(); - if (($curtime - $assessment->timecreated) > $CFG->maxeditingtime) { - $action = "id&aid=$assessment->id\">". - get_string("view", "workshop").""; - // has teacher graded on user's assessment? - if ($assessment->timegraded) { - if (($curtime - $assessment->timegraded) > $CFG->maxeditingtime) { - $comment .= get_string("gradedbyteacher", "workshop", $course->teacher)."; "; - } - } - $otherassessments = workshop_get_assessments($submission); - if (count($otherassessments) > 1) { - $comment .= "id&sid=$submission->id\">". - get_string("viewotherassessments", "workshop").""; - } - } - else { // there's still time left to edit... - $action = "id&sid=$submission->id\">". - get_string("edit", "workshop").""; - } - } - else { // user has not assessed this submission - $action = "id&sid=$submission->id\">". - get_string("assess", "workshop").""; - } - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + if ($submissions = workshop_get_student_submissions($workshop)) { + foreach ($submissions as $submission) { + if ($submission->userid == $user->id) { + $comment = get_string("ownwork", "workshop")."; "; + } + else { + $comment = ""; + } + // has user already assessed this submission + if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id + AND userid = $user->id")) { + $curtime = time(); + if (($curtime - $assessment->timecreated) > $CFG->maxeditingtime) { + $action = "id&aid=$assessment->id\">". + get_string("view", "workshop").""; + // has teacher graded on user's assessment? + if ($assessment->timegraded) { + if (($curtime - $assessment->timegraded) > $CFG->maxeditingtime) { + $comment .= get_string("gradedbyteacher", "workshop", $course->teacher)."; "; + } + } + $otherassessments = workshop_get_assessments($submission); + if (count($otherassessments) > 1) { + $comment .= "id&sid=$submission->id\">". + get_string("viewotherassessments", "workshop").""; + } + } + else { // there's still time left to edit... + $action = "id&sid=$submission->id\">". + get_string("edit", "workshop").""; + } + } + else { // user has not assessed this submission + $action = "id&sid=$submission->id\">". + get_string("assess", "workshop").""; + } + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); - } - print_table($table); - } - } + } + print_table($table); + } + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_all_ungraded_assessments($workshop) { - // lists all the assessments for comment by teacher - global $CFG; - - $table->head = array (get_string("title", "workshop"), get_string("timeassessed", "workshop"), get_string("action", "workshop")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - $timenow = time(); - - if ($assessments = workshop_get_ungraded_assessments($workshop)) { - foreach ($assessments as $assessment) { - if (!isteacher($workshop->course, $assessment->userid)) { - if (($timenow - $assessment->timegraded) < $CFG->maxeditingtime) { - $action = "id&aid=$assessment->id\">". - get_string("edit", "workshop").""; - } - else { - $action = "id&aid=$assessment->id\">". - get_string("gradeassessment", "workshop").""; - } - $submission = get_record("workshop_submissions", "id", $assessment->submissionid); - $table->data[] = array(workshop_print_submission_title($workshop, $submission), - userdate($assessment->timecreated), $action); - } - } - if (isset($table->data)) { - print_table($table); - } - } - } - + // lists all the assessments for comment by teacher + global $CFG; + + $table->head = array (get_string("title", "workshop"), get_string("timeassessed", "workshop"), get_string("action", "workshop")); + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + $timenow = time(); + + if ($assessments = workshop_get_ungraded_assessments($workshop)) { + foreach ($assessments as $assessment) { + if (!isteacher($workshop->course, $assessment->userid)) { + if (($timenow - $assessment->timegraded) < $CFG->maxeditingtime) { + $action = "id&aid=$assessment->id\">". + get_string("edit", "workshop").""; + } + else { + $action = "id&aid=$assessment->id\">". + get_string("gradeassessment", "workshop").""; + } + $submission = get_record("workshop_submissions", "id", $assessment->submissionid); + $table->data[] = array(workshop_print_submission_title($workshop, $submission), + userdate($assessment->timecreated), $action); + } + } + if (isset($table->data)) { + print_table($table); + } + } + } + ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_assessed_submissions($workshop, $user) { - // list the submissions that have been assessed by this user and are COLD - global $CFG; - + // list the submissions that have been assessed by this user and are COLD + global $CFG; + if (! $course = get_record("course", "id", $workshop->course)) { error("Course is misconfigured"); } - $table->head = array (get_string("title","workshop"), get_string("action","workshop"), + $table->head = array (get_string("title","workshop"), get_string("action","workshop"), get_string("comment","workshop")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - if ($assessments = workshop_get_student_assessments($workshop, $user)) { - $timenow = time(); - foreach ($assessments as $assessment) { - $comment = ""; - $submission = get_record("workshop_submissions", "id", $assessment->submissionid); - // the assessment may be in three states: + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + if ($assessments = workshop_get_student_assessments($workshop, $user)) { + $timenow = time(); + foreach ($assessments as $assessment) { + $comment = ""; + $submission = get_record("workshop_submissions", "id", $assessment->submissionid); + // the assessment may be in three states: // 1. "hot", just created but not completed (timecreated is in the future) - // 2. "warm" just created and still capable of being edited, and + // 2. "warm" just created and still capable of being edited, and // 3. "cold" after the editing time - if ($assessment->timecreated < ($timenow - $CFG->maxeditingtime)) { // it's cold - $action = "id&aid=$assessment->id&". - "allowcomments=$workshop->agreeassessments\">". - get_string("view", "workshop").""; - if ($workshop->agreeassessments and !$assessment->timeagreed) { - $action .= " | id&sid=$submission->id\">". - get_string("reassess", "workshop").""; - } - if ($assessment->timecreated < $timenow) { // only show the date if it's in the past (future dates cause confusion - $comment = get_string("assessedon", "workshop", userdate($assessment->timecreated)); - } - else { - $comment = ''; - } - if ($submission->userid == $user->id) { // self assessment? - $comment .= "; ".get_string("ownwork", "workshop"); // just in case they don't know! - } - // has teacher commented on user's assessment? - if ($assessment->timegraded and ($timenow - $assessment->timegraded > $CFG->maxeditingtime)) { - $comment .= "; ".get_string("gradedbyteacher", "workshop", $course->teacher); - } - // if peer agrrements show whether agreement has been reached - if ($workshop->agreeassessments) { - if ($assessment->timeagreed) { - $comment .= "; ".get_string("assessmentwasagreedon", "workshop", + if ($assessment->timecreated < ($timenow - $CFG->maxeditingtime)) { // it's cold + $action = "id&aid=$assessment->id&". + "allowcomments=$workshop->agreeassessments\">". + get_string("view", "workshop").""; + if ($workshop->agreeassessments and !$assessment->timeagreed) { + $action .= " | id&sid=$submission->id\">". + get_string("reassess", "workshop").""; + } + if ($assessment->timecreated < $timenow) { // only show the date if it's in the past (future dates cause confusion + $comment = get_string("assessedon", "workshop", userdate($assessment->timecreated)); + } + else { + $comment = ''; + } + if ($submission->userid == $user->id) { // self assessment? + $comment .= "; ".get_string("ownwork", "workshop"); // just in case they don't know! + } + // has teacher commented on user's assessment? + if ($assessment->timegraded and ($timenow - $assessment->timegraded > $CFG->maxeditingtime)) { + $comment .= "; ".get_string("gradedbyteacher", "workshop", $course->teacher); + } + // if peer agrrements show whether agreement has been reached + if ($workshop->agreeassessments) { + if ($assessment->timeagreed) { + $comment .= "; ".get_string("assessmentwasagreedon", "workshop", userdate($assessment->timeagreed)); - } - else { - $comment .= "; ".get_string("assessmentnotyetagreed", "workshop"); - } - } - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, + } + else { + $comment .= "; ".get_string("assessmentnotyetagreed", "workshop"); + } + } + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); - } - } - } - if (isset($table->data)) { - print_table($table); - } - else { - echo "
".get_string("noassessmentsdone", "workshop")."
\n"; - } - } + } + } + } + if (isset($table->data)) { + print_table($table); + } + else { + echo "
".get_string("noassessmentsdone", "workshop")."
\n"; + } + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_peer_assessments($workshop, $user) { - global $CFG; - - if (! $course = get_record("course", "id", $workshop->course)) { + global $CFG; + + if (! $course = get_record("course", "id", $workshop->course)) { error("Course is misconfigured"); } - $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), + $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - // get user's submissions - if ($submissions = workshop_get_user_submissions($workshop, $user)) { - foreach ($submissions as $submission) { - // get the assessments - if ($assessments = workshop_get_assessments($submission)) { - foreach ($assessments as $assessment) { - // assessments by students only and exclude any self assessments - if (isstudent($workshop->course, $assessment->userid) and + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + // get user's submissions + if ($submissions = workshop_get_user_submissions($workshop, $user)) { + foreach ($submissions as $submission) { + // get the assessments + if ($assessments = workshop_get_assessments($submission)) { + foreach ($assessments as $assessment) { + // assessments by students only and exclude any self assessments + if (isstudent($workshop->course, $assessment->userid) and ($assessment->userid != $user->id)) { - $timenow = time(); - if (($timenow - $assessment->timecreated) > $CFG->maxeditingtime) { - $action = "id&aid=$assessment->id&". - "allowcomments=$workshop->agreeassessments\">". - get_string("view", "workshop").""; - $comment = get_string("assessedon", "workshop", + $timenow = time(); + if (($timenow - $assessment->timecreated) > $CFG->maxeditingtime) { + $action = "id&aid=$assessment->id&". + "allowcomments=$workshop->agreeassessments\">". + get_string("view", "workshop").""; + $comment = get_string("assessedon", "workshop", userdate($assessment->timecreated)); - // has teacher commented on user's assessment? - if ($assessment->timegraded and + // has teacher commented on user's assessment? + if ($assessment->timegraded and ($timenow - $assessment->timegraded > $CFG->maxeditingtime)) { - $comment .= "; ".get_string("gradedbyteacher", "workshop", $course->teacher); - } - // if peer agrrements show whether agreement has been reached - if ($workshop->agreeassessments) { - if ($assessment->timeagreed) { - $comment .= "; ".get_string("assessmentwasagreedon", "workshop", + $comment .= "; ".get_string("gradedbyteacher", "workshop", $course->teacher); + } + // if peer agrrements show whether agreement has been reached + if ($workshop->agreeassessments) { + if ($assessment->timeagreed) { + $comment .= "; ".get_string("assessmentwasagreedon", "workshop", userdate($assessment->timeagreed)); - } - else { - $comment .= "; ".get_string("assessmentnotyetagreed", "workshop"); - } - } - $table->data[] = array(workshop_print_submission_title($workshop, $submission), + } + else { + $comment .= "; ".get_string("assessmentnotyetagreed", "workshop"); + } + } + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); - } - } - } - } - } - } - if (isset($table->data)) { - print_table($table); - } - else { - echo "
".get_string("noassessmentsdone", "workshop")."
\n"; - } - } + } + } + } + } + } + } + if (isset($table->data)) { + print_table($table); + } + else { + echo "
".get_string("noassessmentsdone", "workshop")."
\n"; + } + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_self_assessments($workshop, $user) { - // list user's submissions for the user to assess - global $CFG; - - if (! $course = get_record("course", "id", $workshop->course)) { + // list user's submissions for the user to assess + global $CFG; + + if (! $course = get_record("course", "id", $workshop->course)) { error("Course is misconfigured"); } - $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), + $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - // get the user's submissions - if ($submissions = workshop_get_user_submissions($workshop, $user)) { - foreach ($submissions as $submission) { - $comment = ""; - if (!$assessment = get_record_select("workshop_assessments", "submissionid = $submission->id AND - userid = $user->id")) { - if ($submission->userid == $user->id) { // this will always be true - $comment = get_string("ownwork", "workshop"); // just in case they don't know! - } - $action = "id&sid=$submission->id\">". - get_string("assess", "workshop").""; - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); - } - } - } - if (isset($table->data)) { - echo "

".get_string("pleaseassessyoursubmissions", "workshop", $course->student). - "

\n"; - print_table($table); - } - } + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + // get the user's submissions + if ($submissions = workshop_get_user_submissions($workshop, $user)) { + foreach ($submissions as $submission) { + $comment = ""; + if (!$assessment = get_record_select("workshop_assessments", "submissionid = $submission->id AND + userid = $user->id")) { + if ($submission->userid == $user->id) { // this will always be true + $comment = get_string("ownwork", "workshop"); // just in case they don't know! + } + $action = "id&sid=$submission->id\">". + get_string("assess", "workshop").""; + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); + } + } + } + if (isset($table->data)) { + echo "

".get_string("pleaseassessyoursubmissions", "workshop", $course->student). + "

\n"; + print_table($table); + } + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_student_submissions($workshop, $user) { - // list available submissions for this user to assess, submissions with the least number - // of assessments are show first - global $CFG; - + // list available submissions for this user to assess, submissions with the least number + // of assessments are show first + global $CFG; + $timenow = time(); - if (! $course = get_record("course", "id", $workshop->course)) { + if (! $course = get_record("course", "id", $workshop->course)) { error("Course is misconfigured"); } if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id)) { - error("Course Module ID was incorrect"); - } - - $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - // get the number of assessments this user has done on student submission, deduct self assessments - $nassessed = workshop_count_user_assessments($workshop, $user, "student") - - workshop_count_self_assessments($workshop, $user); - // user hasn't been allocated enough, try and get some more - if ($nassessed < $workshop->nsassessments) { - // count the number of assessments for each student submission - if ($submissions = workshop_get_student_submissions($workshop)) { - // srand ((float)microtime()*1000000); // now done automatically in PHP 4.2.0-> - foreach ($submissions as $submission) { + error("Course Module ID was incorrect"); + } + + $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop")); + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + // get the number of assessments this user has done on student submission, deduct self assessments + $nassessed = workshop_count_user_assessments($workshop, $user, "student") - + workshop_count_self_assessments($workshop, $user); + // user hasn't been allocated enough, try and get some more + if ($nassessed < $workshop->nsassessments) { + // count the number of assessments for each student submission + if ($submissions = workshop_get_student_submissions($workshop)) { + // srand ((float)microtime()*1000000); // now done automatically in PHP 4.2.0-> + foreach ($submissions as $submission) { // process only cold submissions if (($submission->timecreated + $CFG->maxeditingtime) > $timenow) { continue; } - $n = count_records("workshop_assessments", "submissionid", $submission->id); - // ...OK to have zero, we add a small random number to randomise things - $nassessments[$submission->id] = $n + rand(0, 98) / 100; - } - + $n = count_records("workshop_assessments", "submissionid", $submission->id); + // ...OK to have zero, we add a small random number to randomise things + $nassessments[$submission->id] = $n + rand(0, 98) / 100; + } + if (isset($nassessments)) { // make sure we end up with something to play with :-) // put the submissions with the lowest number of assessments first asort($nassessments); @@ -2232,53 +2244,53 @@ function workshop_list_student_submissions($workshop, $user) { } } } - } - } + } + } } - // now list the student submissions this user has been allocated, list only the hot and warm ones, + // now list the student submissions this user has been allocated, list only the hot and warm ones, // the cold ones are listed in the "your assessments list" (_list_assessed submissions) - if ($assessments = workshop_get_user_assessments($workshop, $user)) { - $timenow = time(); - foreach ($assessments as $assessment) { - if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) { - error ("workshop_list_student_submissions: unable to get submission"); - } - // submission from a student? - if (isstudent($workshop->course, $submission->userid)) { - $comment = ''; - // user assessment has three states: record created but not assessed (date created in the future) [hot]; - // just assessed but still editable [warm]; and "static" (may or may not have been graded by teacher, that - // is shown in the comment) [cold] - if ($assessment->timecreated > $timenow) { // user needs to assess this submission - $action = "id&sid=$submission->id\">". - get_string("assess", "workshop").""; - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); - } - elseif ($assessment->timecreated > ($timenow - $CFG->maxeditingtime)) { // there's still time left to edit... - $action = "id&sid=$submission->id\">". - get_string("edit", "workshop").""; - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); - } - } - } - } - - if (isset($table->data)) { - echo "

".get_string("pleaseassessthesestudentsubmissions", "workshop", $course->student). - "

\n"; - print_table($table); - } - else { - echo "

".get_string("nosubmissionsavailableforassessment", "workshop")."

\n"; - } - } + if ($assessments = workshop_get_user_assessments($workshop, $user)) { + $timenow = time(); + foreach ($assessments as $assessment) { + if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) { + error ("workshop_list_student_submissions: unable to get submission"); + } + // submission from a student? + if (isstudent($workshop->course, $submission->userid)) { + $comment = ''; + // user assessment has three states: record created but not assessed (date created in the future) [hot]; + // just assessed but still editable [warm]; and "static" (may or may not have been graded by teacher, that + // is shown in the comment) [cold] + if ($assessment->timecreated > $timenow) { // user needs to assess this submission + $action = "id&sid=$submission->id\">". + get_string("assess", "workshop").""; + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); + } + elseif ($assessment->timecreated > ($timenow - $CFG->maxeditingtime)) { // there's still time left to edit... + $action = "id&sid=$submission->id\">". + get_string("edit", "workshop").""; + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); + } + } + } + } + + if (isset($table->data)) { + echo "

".get_string("pleaseassessthesestudentsubmissions", "workshop", $course->student). + "

\n"; + print_table($table); + } + else { + echo "

".get_string("nosubmissionsavailableforassessment", "workshop")."

\n"; + } + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_submissions_for_admin($workshop, $order) { - // list the teacher sublmissions first - global $CFG, $USER; - + // list the teacher sublmissions first + global $CFG, $USER; + if (! $course = get_record("course", "id", $workshop->course)) { error("Course is misconfigured"); } @@ -2286,25 +2298,25 @@ function workshop_list_submissions_for_admin($workshop, $order) { error("Course Module ID was incorrect"); } - workshop_print_assignment_info($workshop); + workshop_print_assignment_info($workshop); - // if peer assessments allow teacher to change overallocation option + // if peer assessments allow teacher to change overallocation option if ($workshop->nsassessments) { print_simple_box_start("center"); - print_heading_with_help(get_string("setoverallocation", "workshop"), "overallocation", "workshop"); - echo "
\n"; - echo "id\">\n"; - echo "\n"; - echo "
\n"; + print_heading_with_help(get_string("setoverallocation", "workshop"), "overallocation", "workshop"); + echo "\n"; + echo "id\">\n"; + echo "\n"; + echo "
\n"; echo "\n"; echo "

".get_string("overallocation", "workshop").":

\n"; for ($i=2; $i>=0; $i--) { - $numbers[$i] = $i; - } + $numbers[$i] = $i; + } choose_from_menu($numbers, "overallocation", "$workshop->overallocation", ""); echo "

\n"; - echo "\n"; - echo "
\n"; + echo "\n"; + echo "
\n"; print_simple_box_end(); } @@ -2338,1068 +2350,1068 @@ function workshop_list_submissions_for_admin($workshop, $order) { echo "
\n"; print_simple_box_end(); - // list any teacher submissions - $table->head = array (get_string("title", "workshop"), get_string("submittedby", "workshop"), get_string("action", "workshop")); - $table->align = array ("left", "left", "left"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - if ($submissions = workshop_get_teacher_submissions($workshop)) { - foreach ($submissions as $submission) { - $action = "id&sid=$submission->id\">". - get_string("amendtitle", "workshop").""; - // has user already assessed this submission - if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id - AND userid = $USER->id")) { - $curtime = time(); - if ($assessment->timecreated > $curtime) { // it's a "hanging" assessment - $action .= " | id&sid=$submission->id\">". - get_string("assess", "workshop").""; - } - elseif (($curtime - $assessment->timecreated) > $CFG->maxeditingtime) { - $action .= " | id&sid=$submission->id\">" - .get_string("reassess", "workshop").""; - } - else { // there's still time left to edit... - $action .= " | id&sid=$submission->id\">". - get_string("edit", "workshop").""; - } - } - else { // user has not graded this submission - $action .= " | id&sid=$submission->id\">". - get_string("assess", "workshop").""; - } - if ($assessments = workshop_get_assessments($submission)) { - $action .= " | id&sid=$submission->id\">". - get_string("listassessments", "workshop").""; - } - $action .= " | id&sid=$submission->id\">". - get_string("delete", "workshop").""; - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $course->teacher, $action); - } - print_heading(get_string("studentsubmissions", "workshop", $course->teacher), "center"); - print_table($table); - } - - // list student assessments - // Get all the students... - if ($users = get_course_students($course->id, "u.firstname, u.lastname")) { - $timenow = time(); - print_heading(get_string("studentassessments", "workshop", $course->student)); - unset($table); - $table->head = array(get_string("name"), get_string("title", "workshop"), get_string("action", "workshop")); - $table->align = array ("left", "left", "left"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - foreach ($users as $user) { + // list any teacher submissions + $table->head = array (get_string("title", "workshop"), get_string("submittedby", "workshop"), get_string("action", "workshop")); + $table->align = array ("left", "left", "left"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + if ($submissions = workshop_get_teacher_submissions($workshop)) { + foreach ($submissions as $submission) { + $action = "id&sid=$submission->id\">". + get_string("amendtitle", "workshop").""; + // has user already assessed this submission + if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id + AND userid = $USER->id")) { + $curtime = time(); + if ($assessment->timecreated > $curtime) { // it's a "hanging" assessment + $action .= " | id&sid=$submission->id\">". + get_string("assess", "workshop").""; + } + elseif (($curtime - $assessment->timecreated) > $CFG->maxeditingtime) { + $action .= " | id&sid=$submission->id\">" + .get_string("reassess", "workshop").""; + } + else { // there's still time left to edit... + $action .= " | id&sid=$submission->id\">". + get_string("edit", "workshop").""; + } + } + else { // user has not graded this submission + $action .= " | id&sid=$submission->id\">". + get_string("assess", "workshop").""; + } + if ($assessments = workshop_get_assessments($submission)) { + $action .= " | id&sid=$submission->id\">". + get_string("listassessments", "workshop").""; + } + $action .= " | id&sid=$submission->id\">". + get_string("delete", "workshop").""; + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $course->teacher, $action); + } + print_heading(get_string("studentsubmissions", "workshop", $course->teacher), "center"); + print_table($table); + } + + // list student assessments + // Get all the students... + if ($users = get_course_students($course->id, "u.firstname, u.lastname")) { + $timenow = time(); + print_heading(get_string("studentassessments", "workshop", $course->student)); + unset($table); + $table->head = array(get_string("name"), get_string("title", "workshop"), get_string("action", "workshop")); + $table->align = array ("left", "left", "left"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + foreach ($users as $user) { // list the assessments which have been done (exclude the hot ones) - if ($assessments = workshop_get_user_assessments_done($workshop, $user)) { - $title =''; - foreach ($assessments as $assessment) { - if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) { - error("Workshop_list_submissions_for_admin: Submission record not found!"); - } - $title .= $submission->title; - // test for allocated assesments which have not been done - if ($assessment->timecreated < $timenow) { - $title .= " {".number_format($assessment->grade, 0); - } - else { // assessment record created but user has not yet assessed this submission - $title .= " {-"; - } - if ($assessment->timegraded) { - $title .= "/".number_format($assessment->gradinggrade * 100 / COMMENTSCALE, 0)."%"; - } - $title .= "} "; - if ($realassessments = workshop_count_user_assessments_done($workshop, $user)) { - $action = "id&userid=$user->id\">". - get_string("liststudentsassessments", "workshop")." ($realassessments)"; - } - else { - $action =""; - } - } - $table->data[] = array("$user->firstname $user->lastname", $title, $action); - } - } - if (isset($table->data)) { - print_table($table); - } - } - - // now the sudent submissions - unset($table); - switch ($order) { - case "title" : - $table->head = array("id&order=name\">". - get_string("submittedby", "workshop")."", get_string("title", "workshop"), get_string("action", "workshop")); - break; - case "name" : - $table->head = array (get_string("submittedby", "workshop"), - "id&order=title\">". - get_string("title", "workshop")."", get_string("action", "workshop")); - break; - } - $table->align = array ("left", "left", "left"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - if ($submissions = workshop_get_student_submissions($workshop, $order)) { - foreach ($submissions as $submission) { - if (!$user = get_record("user", "id", $submission->userid)) { - error("workshop_list_submissions_for_admin: failure to get user record"); - } - $action = "id&sid=$submission->id\">". - get_string("amendtitle", "workshop").""; - // has teacher already assessed this submission - if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id - AND userid = $USER->id")) { - $curtime = time(); - if (($curtime - $assessment->timecreated) > $CFG->maxeditingtime) { - $action .= " | id&sid=$submission->id\">". - get_string("reassess", "workshop").""; - } - else { // there's still time left to edit... - $action .= " | id&sid=$submission->id\">". - get_string("edit", "workshop").""; - } - } - else { // user has not assessed this submission - $action .= " | id&sid=$submission->id\">". - get_string("assess", "workshop").""; - } - if ($nassessments = workshop_count_assessments($submission)) { - $action .= " | id&sid=$submission->id\">". - get_string("listassessments", "workshop")." ($nassessments)"; - } - $action .= " | id&sid=$submission->id\">". - get_string("delete", "workshop").""; - $table->data[] = array("$user->firstname $user->lastname", $submission->title. - " ".workshop_print_submission_assessments($workshop, $submission, "teacher"). - " ".workshop_print_submission_assessments($workshop, $submission, "student"), $action); - } - print_heading(get_string("studentsubmissions", "workshop", $course->student), "center"); - print_table($table); - } + if ($assessments = workshop_get_user_assessments_done($workshop, $user)) { + $title =''; + foreach ($assessments as $assessment) { + if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) { + error("Workshop_list_submissions_for_admin: Submission record not found!"); + } + $title .= $submission->title; + // test for allocated assesments which have not been done + if ($assessment->timecreated < $timenow) { + $title .= " {".number_format($assessment->grade, 0); + } + else { // assessment record created but user has not yet assessed this submission + $title .= " {-"; + } + if ($assessment->timegraded) { + $title .= "/".number_format($assessment->gradinggrade * 100 / COMMENTSCALE, 0)."%"; + } + $title .= "} "; + if ($realassessments = workshop_count_user_assessments_done($workshop, $user)) { + $action = "id&userid=$user->id\">". + get_string("liststudentsassessments", "workshop")." ($realassessments)"; + } + else { + $action =""; + } + } + $table->data[] = array("$user->firstname $user->lastname", $title, $action); + } + } + if (isset($table->data)) { + print_table($table); + } + } + + // now the sudent submissions + unset($table); + switch ($order) { + case "title" : + $table->head = array("id&order=name\">". + get_string("submittedby", "workshop")."", get_string("title", "workshop"), get_string("action", "workshop")); + break; + case "name" : + $table->head = array (get_string("submittedby", "workshop"), + "id&order=title\">". + get_string("title", "workshop")."", get_string("action", "workshop")); + break; + } + $table->align = array ("left", "left", "left"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + if ($submissions = workshop_get_student_submissions($workshop, $order)) { + foreach ($submissions as $submission) { + if (!$user = get_record("user", "id", $submission->userid)) { + error("workshop_list_submissions_for_admin: failure to get user record"); + } + $action = "id&sid=$submission->id\">". + get_string("amendtitle", "workshop").""; + // has teacher already assessed this submission + if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id + AND userid = $USER->id")) { + $curtime = time(); + if (($curtime - $assessment->timecreated) > $CFG->maxeditingtime) { + $action .= " | id&sid=$submission->id\">". + get_string("reassess", "workshop").""; + } + else { // there's still time left to edit... + $action .= " | id&sid=$submission->id\">". + get_string("edit", "workshop").""; + } + } + else { // user has not assessed this submission + $action .= " | id&sid=$submission->id\">". + get_string("assess", "workshop").""; + } + if ($nassessments = workshop_count_assessments($submission)) { + $action .= " | id&sid=$submission->id\">". + get_string("listassessments", "workshop")." ($nassessments)"; + } + $action .= " | id&sid=$submission->id\">". + get_string("delete", "workshop").""; + $table->data[] = array("$user->firstname $user->lastname", $submission->title. + " ".workshop_print_submission_assessments($workshop, $submission, "teacher"). + " ".workshop_print_submission_assessments($workshop, $submission, "student"), $action); + } + print_heading(get_string("studentsubmissions", "workshop", $course->student), "center"); + print_table($table); + } } ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_teacher_assessments($workshop, $user) { - global $CFG; - - if (! $course = get_record("course", "id", $workshop->course)) { + global $CFG; + + if (! $course = get_record("course", "id", $workshop->course)) { error("Course is misconfigured"); } - $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - // get user's submissions - if ($submissions = workshop_get_user_submissions($workshop, $user)) { - foreach ($submissions as $submission) { - // get the assessments - if ($assessments = workshop_get_assessments($submission)) { - foreach ($assessments as $assessment) { - if (isteacher($workshop->course, $assessment->userid)) { // assessments by teachers only - $action = "id&aid=$assessment->id\">". - get_string("view", "workshop").""; - // has teacher commented on teacher's assessment? shouldn't happen but leave test in - if ($assessment->timegraded and ($timenow - $assessment->timegraded > $CFG->maxeditingtime)) { - $comment = get_string("gradedbyteacher", "workshop", $course->teacher); - } - else { - $comment = userdate($assessment->timecreated); - } - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); - } - } - } - } - } - if (isset($table->data)) { - print_table($table); - } - else { - echo "
".get_string("noassessmentsdone", "workshop")."
\n"; - } - } + $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop")); + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + // get user's submissions + if ($submissions = workshop_get_user_submissions($workshop, $user)) { + foreach ($submissions as $submission) { + // get the assessments + if ($assessments = workshop_get_assessments($submission)) { + foreach ($assessments as $assessment) { + if (isteacher($workshop->course, $assessment->userid)) { // assessments by teachers only + $action = "id&aid=$assessment->id\">". + get_string("view", "workshop").""; + // has teacher commented on teacher's assessment? shouldn't happen but leave test in + if ($assessment->timegraded and ($timenow - $assessment->timegraded > $CFG->maxeditingtime)) { + $comment = get_string("gradedbyteacher", "workshop", $course->teacher); + } + else { + $comment = userdate($assessment->timecreated); + } + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); + } + } + } + } + } + if (isset($table->data)) { + print_table($table); + } + else { + echo "
".get_string("noassessmentsdone", "workshop")."
\n"; + } + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_teacher_submissions($workshop, $user) { - global $CFG; - - if (! $course = get_record("course", "id", $workshop->course)) { + global $CFG; + + if (! $course = get_record("course", "id", $workshop->course)) { error("Course is misconfigured"); } - $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - // get the number of assessments this user has done - $nassessed = count_records_select("workshop_assessments", "workshopid = $workshop->id - AND userid = $user->id"); - if ($nassessed < $workshop->ntassessments) { - // if user has not assessed enough, set up "future" assessment records for this user for the teacher submissions... - // ... first count the number of assessments for each teacher submission... - if ($submissions = workshop_get_teacher_submissions($workshop)) { - srand ((float)microtime()*1000000); // initialise random number generator - foreach ($submissions as $submission) { - $n = count_records("workshop_assessments", "submissionid", $submission->id); - // ...OK to have zero, we add a small random number to randomise things... - $nassessments[$submission->id] = $n + rand(0, 99) / 100; - } - // ...put the submissions with the lowest number of assessments first... - asort($nassessments); - reset($nassessments); - foreach ($nassessments as $submissionid => $n) { // break out of loop when we allocated enough assessments... - $submission = get_record("workshop_submissions", "id", $submissionid); - // ... provided the user has NOT already assessed that submission... - if (!get_record("workshop_assessments", "submissionid", $submission->id, "userid", + $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop")); + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + // get the number of assessments this user has done + $nassessed = count_records_select("workshop_assessments", "workshopid = $workshop->id + AND userid = $user->id"); + if ($nassessed < $workshop->ntassessments) { + // if user has not assessed enough, set up "future" assessment records for this user for the teacher submissions... + // ... first count the number of assessments for each teacher submission... + if ($submissions = workshop_get_teacher_submissions($workshop)) { + srand ((float)microtime()*1000000); // initialise random number generator + foreach ($submissions as $submission) { + $n = count_records("workshop_assessments", "submissionid", $submission->id); + // ...OK to have zero, we add a small random number to randomise things... + $nassessments[$submission->id] = $n + rand(0, 99) / 100; + } + // ...put the submissions with the lowest number of assessments first... + asort($nassessments); + reset($nassessments); + foreach ($nassessments as $submissionid => $n) { // break out of loop when we allocated enough assessments... + $submission = get_record("workshop_submissions", "id", $submissionid); + // ... provided the user has NOT already assessed that submission... + if (!get_record("workshop_assessments", "submissionid", $submission->id, "userid", $user->id)) { - $yearfromnow = time() + 365 * 86400; - // ...create one and set timecreated way in the future, this is reset when record is updated - $assessment->workshopid = $workshop->id; - $assessment->submissionid = $submission->id; - $assessment->userid = $user->id; - $assessment->grade = -1; // set impossible grade - $assessment->timecreated = $yearfromnow; - if (!$assessment->id = insert_record("workshop_assessments", $assessment)) { - error("Could not insert workshop assessment!"); - } - $nassessed++; - if ($nassessed >= $workshop->ntassessments) { - break; - } - } - } - } - } - // now list user's assessments (but only list those which come from teacher submissions) - if ($assessments = workshop_get_user_assessments($workshop, $user)) { - $timenow = time(); - foreach ($assessments as $assessment) { - if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) { - error ("workshop_list_teacher_submissions: unable to get submission"); - } - // submission from a teacher? - if (isteacher($workshop->course, $submission->userid)) { - $comment = ''; - // user assessment has three states: record created but not assessed (date created in the future); - // just assessed but still editable; and "static" (may or may not have been graded by teacher, that - // is shown in the comment) - if ($assessment->timecreated> $timenow) { // user needs to assess this submission - $action = "id&sid=$submission->id\">". - get_string("assess", "workshop").""; - } - elseif (($timenow - $assessment->timecreated) < $CFG->maxeditingtime) { // there's still time left to edit... - $action = "id&sid=$submission->id\">". - get_string("edit", "workshop").""; - } - else { - $action = "id&aid=$assessment->id\">" - .get_string("view", "workshop").""; - } - // see if teacher has graded assessment - if ($assessment->timegraded and (($timenow - $assessment->timegraded) > $CFG->maxeditingtime)) { - $comment .= get_string("thereisfeedbackfromtheteacher", "workshop", $course->teacher); - } - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); - } - } - } - print_table($table); - } + $yearfromnow = time() + 365 * 86400; + // ...create one and set timecreated way in the future, this is reset when record is updated + $assessment->workshopid = $workshop->id; + $assessment->submissionid = $submission->id; + $assessment->userid = $user->id; + $assessment->grade = -1; // set impossible grade + $assessment->timecreated = $yearfromnow; + if (!$assessment->id = insert_record("workshop_assessments", $assessment)) { + error("Could not insert workshop assessment!"); + } + $nassessed++; + if ($nassessed >= $workshop->ntassessments) { + break; + } + } + } + } + } + // now list user's assessments (but only list those which come from teacher submissions) + if ($assessments = workshop_get_user_assessments($workshop, $user)) { + $timenow = time(); + foreach ($assessments as $assessment) { + if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) { + error ("workshop_list_teacher_submissions: unable to get submission"); + } + // submission from a teacher? + if (isteacher($workshop->course, $submission->userid)) { + $comment = ''; + // user assessment has three states: record created but not assessed (date created in the future); + // just assessed but still editable; and "static" (may or may not have been graded by teacher, that + // is shown in the comment) + if ($assessment->timecreated> $timenow) { // user needs to assess this submission + $action = "id&sid=$submission->id\">". + get_string("assess", "workshop").""; + } + elseif (($timenow - $assessment->timecreated) < $CFG->maxeditingtime) { // there's still time left to edit... + $action = "id&sid=$submission->id\">". + get_string("edit", "workshop").""; + } + else { + $action = "id&aid=$assessment->id\">" + .get_string("view", "workshop").""; + } + // see if teacher has graded assessment + if ($assessment->timegraded and (($timenow - $assessment->timegraded) > $CFG->maxeditingtime)) { + $comment .= get_string("thereisfeedbackfromtheteacher", "workshop", $course->teacher); + } + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); + } + } + } + print_table($table); + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_unassessed_student_submissions($workshop, $user) { - // list the student submissions not assessed by this user - global $CFG; - - $table->head = array (get_string("title", "workshop"), get_string("submittedby", "workshop"), - get_string("action", "workshop"), get_string("comment", "workshop")); - $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - if ($submissions = workshop_get_student_submissions($workshop)) { - foreach ($submissions as $submission) { - $comment = ""; - // see if user already graded this assessment - if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id - AND userid = $user->id")) { - $timenow = time(); - if (($timenow - $assessment->timecreated < $CFG->maxeditingtime)) { - // last chance salon - $submissionowner = get_record("user", "id", $submission->userid); - $action = "id&sid=$submission->id\">". - get_string("edit", "workshop").""; - $table->data[] = array(workshop_print_submission_title($workshop, $submission), - $submissionowner->firstname." ".$submissionowner->lastname, $action, $comment); - } - } - else { // no assessment - $submissionowner = get_record("user", "id", $submission->userid); - $action = "id&sid=$submission->id\">". - get_string("assess", "workshop").""; - $table->data[] = array(workshop_print_submission_title($workshop, $submission), - $submissionowner->firstname." ".$submissionowner->lastname, $action, $comment); - } - } - if (isset($table->data)) { - print_table($table); - } - } - } + // list the student submissions not assessed by this user + global $CFG; + + $table->head = array (get_string("title", "workshop"), get_string("submittedby", "workshop"), + get_string("action", "workshop"), get_string("comment", "workshop")); + $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + if ($submissions = workshop_get_student_submissions($workshop)) { + foreach ($submissions as $submission) { + $comment = ""; + // see if user already graded this assessment + if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id + AND userid = $user->id")) { + $timenow = time(); + if (($timenow - $assessment->timecreated < $CFG->maxeditingtime)) { + // last chance salon + $submissionowner = get_record("user", "id", $submission->userid); + $action = "id&sid=$submission->id\">". + get_string("edit", "workshop").""; + $table->data[] = array(workshop_print_submission_title($workshop, $submission), + $submissionowner->firstname." ".$submissionowner->lastname, $action, $comment); + } + } + else { // no assessment + $submissionowner = get_record("user", "id", $submission->userid); + $action = "id&sid=$submission->id\">". + get_string("assess", "workshop").""; + $table->data[] = array(workshop_print_submission_title($workshop, $submission), + $submissionowner->firstname." ".$submissionowner->lastname, $action, $comment); + } + } + if (isset($table->data)) { + print_table($table); + } + } + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_unassessed_teacher_submissions($workshop, $user) { - // list the teacher submissions not assessed by this user - global $CFG; - - $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop")); - $table->align = array ("LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - if ($submissions = workshop_get_teacher_submissions($workshop)) { - foreach ($submissions as $submission) { - $comment = ""; - // see if user already graded this assessment - if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id - AND userid = $user->id")) { - $timenow = time(); - if (($timenow - $assessment->timecreated < $CFG->maxeditingtime)) { - // last chance salon - $action = "id&sid=$submission->id\">". - get_string("edit", "workshop").""; - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); - } - } - else { // no assessment - $action = "id&sid=$submission->id\">". - get_string("assess", "workshop").""; - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); - } - } - if (isset($table->data)) { - print_table($table); - } - } - } + // list the teacher submissions not assessed by this user + global $CFG; + + $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop")); + $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + if ($submissions = workshop_get_teacher_submissions($workshop)) { + foreach ($submissions as $submission) { + $comment = ""; + // see if user already graded this assessment + if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id + AND userid = $user->id")) { + $timenow = time(); + if (($timenow - $assessment->timecreated < $CFG->maxeditingtime)) { + // last chance salon + $action = "id&sid=$submission->id\">". + get_string("edit", "workshop").""; + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); + } + } + else { // no assessment + $action = "id&sid=$submission->id\">". + get_string("assess", "workshop").""; + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment); + } + } + if (isset($table->data)) { + print_table($table); + } + } + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_ungraded_assessments($workshop, $stype) { - global $CFG; - - // lists all the assessments of student submissions for grading by teacher - $table->head = array (get_string("title", "workshop"), get_string("submittedby", "workshop"), - get_string("assessor", "workshop"), get_string("timeassessed", "workshop"), get_string("action", "workshop")); - $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - $timenow = time(); - - switch ($stype) { - case "student" : - $assessments = workshop_get_ungraded_assessments_student($workshop); - break; - case "teacher" : - $assessments = workshop_get_ungraded_assessments_teacher($workshop); - break; - } - if ($assessments) { - foreach ($assessments as $assessment) { - if (!isteacher($workshop->course, $assessment->userid)) { // don't let teacher grade their own assessments - if (($timenow - $assessment->timegraded) < $CFG->maxeditingtime) { - $action = "id&stype=$stype&aid=$assessment->id\">". - get_string("edit", "workshop").""; - } - else { - $action = "id&stype=$stype&aid=$assessment->id\">". - get_string("grade", "workshop").""; - } - $submission = get_record("workshop_submissions", "id", $assessment->submissionid); - $submissionowner = get_record("user", "id", $submission->userid); - $assessor = get_record("user", "id", $assessment->userid); - $table->data[] = array(workshop_print_submission_title($workshop, $submission), - $submissionowner->firstname." ".$submissionowner->lastname, - $assessor->firstname." ".$assessor->lastname, userdate($assessment->timecreated), $action); - } - } - if (isset($table->data)) { - print_table($table); - } - } - } - + global $CFG; + + // lists all the assessments of student submissions for grading by teacher + $table->head = array (get_string("title", "workshop"), get_string("submittedby", "workshop"), + get_string("assessor", "workshop"), get_string("timeassessed", "workshop"), get_string("action", "workshop")); + $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + $timenow = time(); + + switch ($stype) { + case "student" : + $assessments = workshop_get_ungraded_assessments_student($workshop); + break; + case "teacher" : + $assessments = workshop_get_ungraded_assessments_teacher($workshop); + break; + } + if ($assessments) { + foreach ($assessments as $assessment) { + if (!isteacher($workshop->course, $assessment->userid)) { // don't let teacher grade their own assessments + if (($timenow - $assessment->timegraded) < $CFG->maxeditingtime) { + $action = "id&stype=$stype&aid=$assessment->id\">". + get_string("edit", "workshop").""; + } + else { + $action = "id&stype=$stype&aid=$assessment->id\">". + get_string("grade", "workshop").""; + } + $submission = get_record("workshop_submissions", "id", $assessment->submissionid); + $submissionowner = get_record("user", "id", $submission->userid); + $assessor = get_record("user", "id", $assessment->userid); + $table->data[] = array(workshop_print_submission_title($workshop, $submission), + $submissionowner->firstname." ".$submissionowner->lastname, + $assessor->firstname." ".$assessor->lastname, userdate($assessment->timecreated), $action); + } + } + if (isset($table->data)) { + print_table($table); + } + } + } + ////////////////////////////////////////////////////////////////////////////////////// function workshop_list_user_submissions($workshop, $user) { - global $CFG; - - $timenow = time(); - $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), - get_string("submitted", "assignment"), get_string("assessments", "workshop")); - $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT"); - $table->size = array ("*", "*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; - - if ($submissions = workshop_get_user_submissions($workshop, $user)) { - foreach ($submissions as $submission) { - // allow user to delete a submission if it's warm - if ($submission->timecreated > ($timenow - $CFG->maxeditingtime)) { - $action = "id&sid=$submission->id\">". - get_string("delete", "workshop").""; - } - else { - $action = ''; - } - $n = count_records_select("workshop_assessments", "submissionid = $submission->id AND - timecreated < ($timenow - $CFG->maxeditingtime)"); - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, - userdate($submission->timecreated), $n); - } - print_table($table); - } + global $CFG; + + $timenow = time(); + $table->head = array (get_string("title", "workshop"), get_string("action", "workshop"), + get_string("submitted", "assignment"), get_string("assessments", "workshop")); + $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT"); + $table->size = array ("*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + if ($submissions = workshop_get_user_submissions($workshop, $user)) { + foreach ($submissions as $submission) { + // allow user to delete a submission if it's warm + if ($submission->timecreated > ($timenow - $CFG->maxeditingtime)) { + $action = "id&sid=$submission->id\">". + get_string("delete", "workshop").""; + } + else { + $action = ''; + } + $n = count_records_select("workshop_assessments", "submissionid = $submission->id AND + timecreated < ($timenow - $CFG->maxeditingtime)"); + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, + userdate($submission->timecreated), $n); + } + print_table($table); + } } ////////////////////////////////////////////////////////////////////////////////////// function workshop_print_assessment($workshop, $assessment = false, $allowchanges = false, - $showcommentlinks = false, $returnto = '') { - // $allowchanges added 14/7/03 - // $returnto added 28/8/03 - global $CFG, $THEME, $USER, $WORKSHOP_SCALES, $WORKSHOP_EWEIGHTS; - + $showcommentlinks = false, $returnto = '') { + // $allowchanges added 14/7/03 + // $returnto added 28/8/03 + global $CFG, $THEME, $USER, $WORKSHOP_SCALES, $WORKSHOP_EWEIGHTS; + if (! $course = get_record("course", "id", $workshop->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id)) { - error("Course Module ID was incorrect"); - } - - $timenow = time(); - - // reset the internal flags - if ($assessment) { - $showgrades = false; - } - else { // if no assessment, i.e. specimen grade form always show grading scales - $showgrades = true; - } - - if ($assessment) { - // set the internal flag is necessary - if ($allowchanges or !$workshop->agreeassessments or !$workshop->hidegrades or + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + $timenow = time(); + + // reset the internal flags + if ($assessment) { + $showgrades = false; + } + else { // if no assessment, i.e. specimen grade form always show grading scales + $showgrades = true; + } + + if ($assessment) { + // set the internal flag is necessary + if ($allowchanges or !$workshop->agreeassessments or !$workshop->hidegrades or $assessment->timeagreed) { - $showgrades = true; - } - - echo "
-
cellcontent\">\n"; - if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) { - error ("Workshop_print_assessment: Submission record not found"); - } - echo workshop_print_submission_title($workshop, $submission); - echo "

\n"; - + $showgrades = true; + } + + echo "
+
cellcontent\">\n"; + if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) { + error ("Workshop_print_assessment: Submission record not found"); + } + echo workshop_print_submission_title($workshop, $submission); + echo "

\n"; + // see if this is a pre-filled assessment for a re-submission... if ($assessment->resubmission) { // ...and print an explaination print_heading(get_string("assessmentofresubmission", "workshop")); } - // print agreement time if the workshop requires peer agreement - if ($workshop->agreeassessments and $assessment->timeagreed) { - echo "

".get_string("assessmentwasagreedon", "workshop", userdate($assessment->timeagreed)); - } - - // first print any comments on this assessment - if ($comments = workshop_get_comments($assessment)) { - echo "\n"; - $firstcomment = TRUE; - foreach ($comments as $comment) { - echo "\n"; + break; + + case 4: // rubric grading + // now run through the elements... + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + if (isset($grades[$i])) { + $selection = $grades[$i]->grade; + } else { + $selection = 0; + } + // ...and the rubrics + if ($rubricsraw = get_records_select("workshop_rubrics", "workshopid = $workshop->id AND + elementno = $i", "rubricno ASC")) { + unset($rubrics); + foreach ($rubricsraw as $rubic) { + $rubrics[] = $rubic; // to renumber index 0,1,2... + } + for ($j=0; $j<5; $j++) { + if (empty($rubrics[$j]->description)) { + break; // out of inner for loop + } + echo "\n"; + if ($selection == $j) { + echo " \n"; + }else { + echo " \n"; + } + echo "\n"; + } + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + } + } + break; + } // end of outer switch + + // now get the general comment (present in all types) + echo "\n"; + switch ($workshop->gradingstrategy) { + case 0: + case 1: + case 4 : // no grading, accumulative and rubic + echo " \n"; + break; + default : + echo " \n"; + } + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + + $timenow = time(); + // now show the teacher's comment if available... + if ($assessment->timegraded and (($timenow - $assessment->timegraded) > $CFG->maxeditingtime)) { + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + // only show the grading grade if it's the teacher + if (isteacher($course->id)) { + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + } + echo "\n"; + echo "\n"; + echo "\n"; + } + + // ...and close the table, show submit button if needed... + echo "
cellheading2\">

". + // print agreement time if the workshop requires peer agreement + if ($workshop->agreeassessments and $assessment->timeagreed) { + echo "

".get_string("assessmentwasagreedon", "workshop", userdate($assessment->timeagreed)); + } + + // first print any comments on this assessment + if ($comments = workshop_get_comments($assessment)) { + echo "\n"; + $firstcomment = TRUE; + foreach ($comments as $comment) { + echo "\n"; - } - echo "
cellheading2\">

". get_string("commentby","workshop")." "; - if (isteacher($workshop->course, $comment->userid)) { - echo $course->teacher; - } - elseif ($assessment->userid == $comment->userid) { - print_string("assessor", "workshop"); - } - else { - print_string("authorofsubmission", "workshop"); - } - echo " ".get_string("on", "workshop", userdate($comment->timecreated))."

\n"; - echo text_to_html($comment->comments)." \n"; - // add the links if needed - if ($firstcomment and $showcommentlinks and !$assessment->timeagreed) { - // show links depending on who doing the viewing - $firstcomment = FALSE; - if (isteacher($workshop->course, $USER->id) and ($comment->userid != $USER->id)) { - echo "

id&aid=$assessment->id\">". - get_string("reply", "workshop")."\n"; - } - elseif (($comment->userid ==$USER->id) and (($timenow - $comment->timecreated) < $CFG->maxeditingtime)) { - echo "

id&cid=$comment->id\">". - get_string("edit", "workshop")."\n"; - if ($USER->id == $submission->userid) { - echo " | id&aid=$assessment->id\">". - get_string("agreetothisassessment", "workshop")."\n"; - } - } - elseif (($comment->userid != $USER->id) and (($USER->id == $assessment->userid) or - ($USER->id == $submission->userid))) { - echo "

id&aid=$assessment->id\">". - get_string("reply", "workshop")."\n"; - if ($USER->id == $submission->userid) { - echo " | id&aid=$assessment->id\">". - get_string("agreetothisassessment", "workshop")."\n"; - } - } - } - echo "

\n"; - } - - // only show the grade if grading strategy > 0 and the grade is positive - if ($showgrades and $workshop->gradingstrategy and $assessment->grade >= 0) { - echo "

".get_string("thegradeis", "workshop").": ".number_format($assessment->grade, 2)." (". - get_string("maximumgrade")." ".number_format($workshop->grade, 0).")

\n"; - } - } - - // now print the grading form with the teacher's comments if any - // FORM is needed for Mozilla browsers, else radio bttons are not checked - ?> -
- - - - -
- - \n"; - echo " \n"; - echo "\n"; - - // get the assignment elements... - if (!$elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC")) { - print_string("noteonassignmentelements", "workshop"); - } - else { - foreach ($elementsraw as $element) { - $elements[] = $element; // to renumber index 0,1,2... - } - } - - if ($assessment) { - // get any previous grades... - if ($gradesraw = get_records_select("workshop_grades", "assessmentid = $assessment->id", "elementno")) { - foreach ($gradesraw as $grade) { - $grades[] = $grade; // to renumber index 0,1,2... - } - } - } - else { - // setup dummy grades array - for($i = 0; $i < count($elementsraw); $i++) { // gives a suitable sized loop - $grades[$i]->feedback = get_string("yourfeedbackgoeshere", "workshop"); - $grades[$i]->grade = 0; - } - } - - // determine what sort of grading - switch ($workshop->gradingstrategy) { - case 0: // no grading - // now print the form - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - } - break; - - case 1: // accumulative grading - // now print the form - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - echo " \n"; - if ($showgrades) { - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - } - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - } - break; - - case 2: // error banded grading - // now run through the elements - $negativecount = 0; - for ($i=0; $i < count($elements) - 1; $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - if (empty($grades[$i]->grade)) { - $negativecount++; - } - } - // print the number of negative elements - // echo "\n"; - // echo "\n"; - // echo " \n"; - echo "
cellheading2\">
".get_string("assessment", "workshop"). - "

". get_string("element","workshop")." $iplus1:

".text_to_html($elements[$i]->description); - echo "

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - echo text_to_html($grades[$i]->feedback); - } - echo "
cellheading2\"> 

". get_string("element","workshop")." $iplus1:

".text_to_html($elements[$i]->description); - echo "

".get_string("weight", "workshop").": ". - number_format($WORKSHOP_EWEIGHTS[$elements[$i]->weight], 2)."\n"; - echo "

". get_string("grade"). ":

\n"; - - // get the appropriate scale - $scalenumber=$elements[$i]->scale; - $SCALE = (object)$WORKSHOP_SCALES[$scalenumber]; - switch ($SCALE->type) { - case 'radio' : - // show selections highest first - echo "
$SCALE->start   "; - for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { - $checked = false; - if (isset($grades[$i]->grade)) { - if ($j == $grades[$i]->grade) { - $checked = true; - } - } - else { // there's no previous grade so check the lowest option - if ($j == 0) { - $checked = true; - } - } - if ($checked) { - echo "    \n"; - } - else { - echo "    \n"; - } - } - echo "   $SCALE->end
\n"; - break; - case 'selection' : - unset($numbers); - for ($j = $SCALE->size; $j >= 0; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[$i]->grade)) { - choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[$i]", 0, ""); - } - break; - } - - echo "

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - echo text_to_html($grades[$i]->feedback); - } - echo "
cellheading2\"> 

". get_string("element","workshop")." $iplus1:

".text_to_html($elements[$i]->description); - echo "

".get_string("weight", "workshop").": ". - number_format($WORKSHOP_EWEIGHTS[$elements[$i]->weight], 2)."\n"; - echo "

". get_string("grade"). ":

\n"; - - // get the appropriate scale - yes/no scale (0) - $SCALE = (object) $WORKSHOP_SCALES[0]; - switch ($SCALE->type) { - case 'radio' : - // show selections highest first - echo "
$SCALE->start   "; - for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { - $checked = false; - if (isset($grades[$i]->grade)) { - if ($j == $grades[$i]->grade) { - $checked = true; - } - } - else { // there's no previous grade so check the lowest option - if ($j == 0) { - $checked = true; - } - } - if ($checked) { - echo "    \n"; - } - else { - echo "    \n"; - } - } - echo "   $SCALE->end
\n"; - break; - case 'selection' : - unset($numbers); - for ($j = $SCALE->size; $j >= 0; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[$i]->grade)) { - choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[$i]", 0, ""); - } - break; - } - - echo "

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - if (isset($grades[$i]->feedback)) { - echo text_to_html($grades[$i]->feedback); - } - } - echo " 
cellheading2\"> 
".get_string("numberofnegativeitems", "workshop")."$negativecount
cellheading2\"> 
\n"; - // now print the grade table - echo "

".get_string("gradetable","workshop")."
\n"; - echo "
\n"; - for ($j = 100; $j >= 0; $j--) { - $numbers[$j] = $j; - } - for ($i=0; $i<=$workshop->nelements; $i++) { - if ($i == $negativecount) { - echo "\n"; - } - else { - echo "\n"; - } - } - echo "
". - get_string("numberofnegativeresponses", "workshop"); - echo "". get_string("suggestedgrade", "workshop")."
pixpath/t/right.gif\"> $i{$elements[$i]->maxscore}
$i{$elements[$i]->maxscore}
\n"; - echo "

\n"; + } + echo "
".get_string("optionaladjustment", + if (isteacher($workshop->course, $comment->userid)) { + echo $course->teacher; + } + elseif ($assessment->userid == $comment->userid) { + print_string("assessor", "workshop"); + } + else { + print_string("authorofsubmission", "workshop"); + } + echo " ".get_string("on", "workshop", userdate($comment->timecreated))."

\n"; + echo text_to_html($comment->comments)." \n"; + // add the links if needed + if ($firstcomment and $showcommentlinks and !$assessment->timeagreed) { + // show links depending on who doing the viewing + $firstcomment = FALSE; + if (isteacher($workshop->course, $USER->id) and ($comment->userid != $USER->id)) { + echo "

id&aid=$assessment->id\">". + get_string("reply", "workshop")."\n"; + } + elseif (($comment->userid ==$USER->id) and (($timenow - $comment->timecreated) < $CFG->maxeditingtime)) { + echo "

id&cid=$comment->id\">". + get_string("edit", "workshop")."\n"; + if ($USER->id == $submission->userid) { + echo " | id&aid=$assessment->id\">". + get_string("agreetothisassessment", "workshop")."\n"; + } + } + elseif (($comment->userid != $USER->id) and (($USER->id == $assessment->userid) or + ($USER->id == $submission->userid))) { + echo "

id&aid=$assessment->id\">". + get_string("reply", "workshop")."\n"; + if ($USER->id == $submission->userid) { + echo " | id&aid=$assessment->id\">". + get_string("agreetothisassessment", "workshop")."\n"; + } + } + } + echo "

\n"; + } + + // only show the grade if grading strategy > 0 and the grade is positive + if ($showgrades and $workshop->gradingstrategy and $assessment->grade >= 0) { + echo "
".get_string("thegradeis", "workshop").": ".number_format($assessment->grade, 2)." (". + get_string("maximumgrade")." ".number_format($workshop->grade, 0).")

\n"; + } + } + + // now print the grading form with the teacher's comments if any + // FORM is needed for Mozilla browsers, else radio bttons are not checked + ?> + + + + + +
+ + \n"; + echo " \n"; + echo "\n"; + + // get the assignment elements... + if (!$elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC")) { + print_string("noteonassignmentelements", "workshop"); + } + else { + foreach ($elementsraw as $element) { + $elements[] = $element; // to renumber index 0,1,2... + } + } + + if ($assessment) { + // get any previous grades... + if ($gradesraw = get_records_select("workshop_grades", "assessmentid = $assessment->id", "elementno")) { + foreach ($gradesraw as $grade) { + $grades[] = $grade; // to renumber index 0,1,2... + } + } + } + else { + // setup dummy grades array + for($i = 0; $i < count($elementsraw); $i++) { // gives a suitable sized loop + $grades[$i]->feedback = get_string("yourfeedbackgoeshere", "workshop"); + $grades[$i]->grade = 0; + } + } + + // determine what sort of grading + switch ($workshop->gradingstrategy) { + case 0: // no grading + // now print the form + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + } + break; + + case 1: // accumulative grading + // now print the form + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + echo " \n"; + if ($showgrades) { + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + } + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + } + break; + + case 2: // error banded grading + // now run through the elements + $negativecount = 0; + for ($i=0; $i < count($elements) - 1; $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + if (empty($grades[$i]->grade)) { + $negativecount++; + } + } + // print the number of negative elements + // echo "\n"; + // echo "\n"; + // echo " \n"; + echo "
cellheading2\">
".get_string("assessment", "workshop"). + "

". get_string("element","workshop")." $iplus1:

".text_to_html($elements[$i]->description); + echo "

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + echo text_to_html($grades[$i]->feedback); + } + echo "
cellheading2\"> 

". get_string("element","workshop")." $iplus1:

".text_to_html($elements[$i]->description); + echo "

".get_string("weight", "workshop").": ". + number_format($WORKSHOP_EWEIGHTS[$elements[$i]->weight], 2)."\n"; + echo "

". get_string("grade"). ":

\n"; + + // get the appropriate scale + $scalenumber=$elements[$i]->scale; + $SCALE = (object)$WORKSHOP_SCALES[$scalenumber]; + switch ($SCALE->type) { + case 'radio' : + // show selections highest first + echo "
$SCALE->start   "; + for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { + $checked = false; + if (isset($grades[$i]->grade)) { + if ($j == $grades[$i]->grade) { + $checked = true; + } + } + else { // there's no previous grade so check the lowest option + if ($j == 0) { + $checked = true; + } + } + if ($checked) { + echo "    \n"; + } + else { + echo "    \n"; + } + } + echo "   $SCALE->end
\n"; + break; + case 'selection' : + unset($numbers); + for ($j = $SCALE->size; $j >= 0; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[$i]->grade)) { + choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[$i]", 0, ""); + } + break; + } + + echo "

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + echo text_to_html($grades[$i]->feedback); + } + echo "
cellheading2\"> 

". get_string("element","workshop")." $iplus1:

".text_to_html($elements[$i]->description); + echo "

".get_string("weight", "workshop").": ". + number_format($WORKSHOP_EWEIGHTS[$elements[$i]->weight], 2)."\n"; + echo "

". get_string("grade"). ":

\n"; + + // get the appropriate scale - yes/no scale (0) + $SCALE = (object) $WORKSHOP_SCALES[0]; + switch ($SCALE->type) { + case 'radio' : + // show selections highest first + echo "
$SCALE->start   "; + for ($j = $SCALE->size - 1; $j >= 0 ; $j--) { + $checked = false; + if (isset($grades[$i]->grade)) { + if ($j == $grades[$i]->grade) { + $checked = true; + } + } + else { // there's no previous grade so check the lowest option + if ($j == 0) { + $checked = true; + } + } + if ($checked) { + echo "    \n"; + } + else { + echo "    \n"; + } + } + echo "   $SCALE->end
\n"; + break; + case 'selection' : + unset($numbers); + for ($j = $SCALE->size; $j >= 0; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[$i]->grade)) { + choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[$i]", 0, ""); + } + break; + } + + echo "

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + if (isset($grades[$i]->feedback)) { + echo text_to_html($grades[$i]->feedback); + } + } + echo " 
cellheading2\"> 
".get_string("numberofnegativeitems", "workshop")."$negativecount
cellheading2\"> 
\n"; + // now print the grade table + echo "

".get_string("gradetable","workshop")."
\n"; + echo "
\n"; + for ($j = 100; $j >= 0; $j--) { + $numbers[$j] = $j; + } + for ($i=0; $i<=$workshop->nelements; $i++) { + if ($i == $negativecount) { + echo "\n"; + } + else { + echo "\n"; + } + } + echo "
". + get_string("numberofnegativeresponses", "workshop"); + echo "". get_string("suggestedgrade", "workshop")."
pixpath/t/right.gif\"> $i{$elements[$i]->maxscore}
$i{$elements[$i]->maxscore}
\n"; + echo "

\n"; - break; - - case 3: // criteria grading - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - // find which criteria has been selected (saved in the zero element), if any - if (isset($grades[0]->grade)) { - $selection = $grades[0]->grade; - } - else { - $selection = 0; - } - // now run through the elements - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo " \n"; - if ($selection == $i) { - echo " \n"; - } - else { - echo " \n"; - } - echo "\n"; - } - echo "
".get_string("optionaladjustment", "workshop")."\n"; - unset($numbers); - for ($j = 20; $j >= -20; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[$workshop->nelements]->grade)) { - choose_from_menu($numbers, "grade[$workshop->nelements]", $grades[$workshop->nelements]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[$workshop->nelements]", 0, ""); - } - echo "
cellheading2\"> cellheading2\">". get_string("criterion","workshop")."cellheading2\">".get_string("select", "workshop")."cellheading2\">".get_string("suggestedgrade", "workshop")."
$iplus1".text_to_html($elements[$i]->description)."{$elements[$i]->maxscore}
\n"; - echo "

\n"; + break; + + case 3: // criteria grading + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + // find which criteria has been selected (saved in the zero element), if any + if (isset($grades[0]->grade)) { + $selection = $grades[0]->grade; + } + else { + $selection = 0; + } + // now run through the elements + for ($i=0; $i < count($elements); $i++) { + $iplus1 = $i+1; + echo "\n"; + echo " \n"; + if ($selection == $i) { + echo " \n"; + } + else { + echo " \n"; + } + echo "\n"; + } + echo "
".get_string("optionaladjustment", + unset($numbers); + for ($j = 20; $j >= -20; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[$workshop->nelements]->grade)) { + choose_from_menu($numbers, "grade[$workshop->nelements]", $grades[$workshop->nelements]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[$workshop->nelements]", 0, ""); + } + echo "
cellheading2\"> cellheading2\">". get_string("criterion","workshop")."cellheading2\">".get_string("select", "workshop")."cellheading2\">".get_string("suggestedgrade", "workshop")."
$iplus1".text_to_html($elements[$i]->description)."{$elements[$i]->maxscore}
\n"; + echo "

\n"; - break; - - case 4: // rubric grading - // now run through the elements... - for ($i=0; $i < count($elements); $i++) { - $iplus1 = $i+1; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - if (isset($grades[$i])) { - $selection = $grades[$i]->grade; - } else { - $selection = 0; - } - // ...and the rubrics - if ($rubricsraw = get_records_select("workshop_rubrics", "workshopid = $workshop->id AND - elementno = $i", "rubricno ASC")) { - unset($rubrics); - foreach ($rubricsraw as $rubic) { - $rubrics[] = $rubic; // to renumber index 0,1,2... - } - for ($j=0; $j<5; $j++) { - if (empty($rubrics[$j]->description)) { - break; // out of inner for loop - } - echo "\n"; - if ($selection == $j) { - echo " \n"; - }else { - echo " \n"; - } - echo "\n"; - } - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - } - } - break; - } // end of outer switch - - // now get the general comment (present in all types) - echo "\n"; - switch ($workshop->gradingstrategy) { - case 0: - case 1: - case 4 : // no grading, accumulative and rubic - echo " \n"; - break; - default : - echo " \n"; - } - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - - $timenow = time(); - // now show the teacher's comment if available... - if ($assessment->timegraded and (($timenow - $assessment->timegraded) > $CFG->maxeditingtime)) { - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - // only show the grading grade if it's the teacher - if (isteacher($course->id)) { - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - } - echo "\n"; - echo "\n"; - echo "\n"; - } - - // ...and close the table, show submit button if needed... - echo "
".get_string("optionaladjustment", "workshop")."\n"; - unset($numbers); - for ($j = 20; $j >= -20; $j--) { - $numbers[$j] = $j; - } - if (isset($grades[1]->grade)) { - choose_from_menu($numbers, "grade[1]", $grades[1]->grade, ""); - } - else { - choose_from_menu($numbers, "grade[1]", 0, ""); - } - echo "
".get_string("element", "workshop")." $iplus1:".text_to_html($elements[$i]->description). - "

".get_string("weight", "workshop").": ". - number_format($WORKSHOP_EWEIGHTS[$elements[$i]->weight], 2)."

cellheading2\" align=\"center\">".get_string("select", "workshop")."cellheading2\">". get_string("criterion","workshop")."
".text_to_html($rubrics[$j]->description)."

". get_string("feedback").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - echo text_to_html($grades[$i]->feedback); - } - echo "
cellheading2\"> 

". get_string("generalcomment", "workshop").":

". get_string("reasonforadjustment", "workshop").":

\n"; - if ($allowchanges) { - echo " \n"; - } - else { - if ($assessment) { - if (isset($assessment->generalcomment)) { - echo text_to_html($assessment->generalcomment); - } - } - else { - print_string("yourfeedbackgoeshere", "workshop"); - } - } - echo " 
cellheading2\"> 

". get_string("teacherscomment", "workshop").":

\n"; - echo text_to_html($assessment->teachercomment); - echo " 

". get_string("teachersgrade", "workshop").":

\n"; - echo number_format($assessment->gradinggrade * 100 / COMMENTSCALE, 0)."%"; - echo " 
cellheading2\"> 
\n"; - if ($assessment) { - if ($allowchanges) { - echo "\n"; - } - // ...if user is author, assessment not agreed, there's no comments, the showcommentlinks flag is set and - // it's not self assessment then show some buttons! - if (($submission->userid == $USER->id) and !$assessment->timeagreed and !$comments and $showcommentlinks and - $submission->userid != $assessment->userid) { - echo "\n"; - echo "\n"; - } - } - echo "
"; - echo "\n"; - } + unset($numbers); + for ($j = 20; $j >= -20; $j--) { + $numbers[$j] = $j; + } + if (isset($grades[1]->grade)) { + choose_from_menu($numbers, "grade[1]", $grades[1]->grade, ""); + } + else { + choose_from_menu($numbers, "grade[1]", 0, ""); + } + echo "
".get_string("element", "workshop")." $iplus1:".text_to_html($elements[$i]->description). + "

".get_string("weight", "workshop").": ". + number_format($WORKSHOP_EWEIGHTS[$elements[$i]->weight], 2)."

cellheading2\" align=\"center\">".get_string("select", "workshop")."cellheading2\">". get_string("criterion","workshop")."
".text_to_html($rubrics[$j]->description)."

". get_string("feedback").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + echo text_to_html($grades[$i]->feedback); + } + echo "
cellheading2\"> 

". get_string("generalcomment", "workshop").":

". get_string("reasonforadjustment", "workshop").":

\n"; + if ($allowchanges) { + echo " \n"; + } + else { + if ($assessment) { + if (isset($assessment->generalcomment)) { + echo text_to_html($assessment->generalcomment); + } + } + else { + print_string("yourfeedbackgoeshere", "workshop"); + } + } + echo " 
cellheading2\"> 

". get_string("teacherscomment", "workshop").":

\n"; + echo text_to_html($assessment->teachercomment); + echo " 

". get_string("teachersgrade", "workshop").":

\n"; + echo number_format($assessment->gradinggrade * 100 / COMMENTSCALE, 0)."%"; + echo " 
cellheading2\"> 
\n"; + if ($assessment) { + if ($allowchanges) { + echo "\n"; + } + // ...if user is author, assessment not agreed, there's no comments, the showcommentlinks flag is set and + // it's not self assessment then show some buttons! + if (($submission->userid == $USER->id) and !$assessment->timeagreed and !$comments and $showcommentlinks and + $submission->userid != $assessment->userid) { + echo "\n"; + echo "\n"; + } + } + echo "

"; + echo "\n"; + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_print_assessments_by_user_for_admin($workshop, $user) { - if ($assessments =workshop_get_user_assessments($workshop, $user)) { - foreach ($assessments as $assessment) { - echo "

".get_string("assessmentby", "workshop", $user->firstname." ".$user->lastname)."

\n"; - workshop_print_assessment($workshop, $assessment); - echo "

id&aid=$assessment->id\">". - get_string("delete", "workshop")."


\n"; - } - } - } + if ($assessments =workshop_get_user_assessments($workshop, $user)) { + foreach ($assessments as $assessment) { + echo "

".get_string("assessmentby", "workshop", $user->firstname." ".$user->lastname)."

\n"; + workshop_print_assessment($workshop, $assessment); + echo "

id&aid=$assessment->id\">". + get_string("delete", "workshop")."


\n"; + } + } + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_print_assessments_for_admin($workshop, $submission) { - if ($assessments =workshop_get_assessments($submission)) { - foreach ($assessments as $assessment) { - if (!$user = get_record("user", "id", $assessment->userid)) { - error (" workshop_print_assessments_for_admin: unable to get user record"); - } - echo "

".get_string("assessmentby", "workshop", $user->firstname." ".$user->lastname)."

\n"; - workshop_print_assessment($workshop, $assessment); - echo "

id&aid=$assessment->id\">". - get_string("delete", "workshop")."


\n"; - } - } - } + if ($assessments =workshop_get_assessments($submission)) { + foreach ($assessments as $assessment) { + if (!$user = get_record("user", "id", $assessment->userid)) { + error (" workshop_print_assessments_for_admin: unable to get user record"); + } + echo "

".get_string("assessmentby", "workshop", $user->firstname." ".$user->lastname)."

\n"; + workshop_print_assessment($workshop, $assessment); + echo "

id&aid=$assessment->id\">". + get_string("delete", "workshop")."


\n"; + } + } + } ////////////////////////////////////////////////////////////////////////////////////// function workshop_print_assignment_info($workshop) { - if (! $course = get_record("course", "id", $workshop->course)) { + if (! $course = get_record("course", "id", $workshop->course)) { error("Course is misconfigured"); } if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id)) { error("Course Module ID was incorrect"); - } - // print standard assignment heading - $strdifference = format_time($workshop->deadline - time()); - if (($workshop->deadline - time()) < 0) { - $strdifference = "$strdifference"; - } - $strduedate = userdate($workshop->deadline)." ($strdifference)"; - print_simple_box_start("center"); - print_heading($workshop->name, "center"); - print_simple_box_start("center"); - echo "".get_string("duedate", "assignment").": $strduedate
"; - echo "".get_string("maximumgrade").": $workshop->grade
"; - echo "".get_string("detailsofassessment", "workshop").": - id&action=displaygradingform\">". - get_string("specimenassessmentform", "workshop")."
"; - print_simple_box_end(); - echo "
"; - echo format_text($workshop->description, $workshop->format); - print_simple_box_end(); - echo "
"; - } + } + // print standard assignment heading + $strdifference = format_time($workshop->deadline - time()); + if (($workshop->deadline - time()) < 0) { + $strdifference = "$strdifference"; + } + $strduedate = userdate($workshop->deadline)." ($strdifference)"; + print_simple_box_start("center"); + print_heading($workshop->name, "center"); + print_simple_box_start("center"); + echo "".get_string("duedate", "assignment").": $strduedate
"; + echo "".get_string("maximumgrade").": $workshop->grade
"; + echo "".get_string("detailsofassessment", "workshop").": + id&action=displaygradingform\">". + get_string("specimenassessmentform", "workshop")."
"; + print_simple_box_end(); + echo "
"; + echo format_text($workshop->description, $workshop->format); + print_simple_box_end(); + echo "
"; + } ////////////////////////////////////////////////////////////////////////////////////// @@ -3451,126 +3463,126 @@ function workshop_print_feedback($course, $submission) { ////////////////////////////////////////////////////////////////////////////////////// function workshop_print_league_table($workshop) { - // print an order table of (student) submissions showing teacher's and student's assessments - - if (! $course = get_record("course", "id", $workshop->course)) { - error("Print league table: Course is misconfigured"); - } - $nentries = $workshop->showleaguetable; - if ($nentries == 99) { - $nentries = 999999; // a large number - } - - if ($workshop->anonymous and isstudent($course->id)) { - $table->head = array (get_string("title", "workshop"), - get_string("teacherassessments", "workshop", $course->teacher), - get_string("studentassessments", "workshop", $course->student), get_string("overallgrade", "workshop")); - $table->align = array ("left", "center", "center", "center"); - $table->size = array ("*", "*", "*", "*"); - } - else { // show names - $table->head = array (get_string("title", "workshop"), get_string("name"), - get_string("teacherassessments", "workshop", $course->teacher), - get_string("studentassessments", "workshop", $course->student), get_string("overallgrade", "workshop")); - $table->align = array ("left", "left", "center", "center", "center"); - $table->size = array ("*", "*", "*", "*", "*"); - } - $table->cellpadding = 2; - $table->cellspacing = 0; - - if ($submissions = workshop_get_student_submissions($workshop, "grade")) { - $n = 1; - foreach ($submissions as $submission) { - if (!$user = get_record("user", "id", $submission->userid)) { - error("Print league table: user not found"); - } - if ($workshop->anonymous and isstudent($course->id)) { - $table->data[] = array(workshop_print_submission_title($workshop, $submission), - workshop_print_submission_assessments($workshop, $submission, "teacher"), - workshop_print_submission_assessments($workshop, $submission, "student"), - number_format(($workshop->teacherweight * $submission->teachergrade + $workshop->peerweight * - $submission->peergrade) / ($workshop->teacherweight + $workshop->peerweight), 1)) ; - } - else { - $table->data[] = array(workshop_print_submission_title($workshop, $submission), $user->firstname." ". - $user->lastname, workshop_print_submission_assessments($workshop, $submission, "teacher"), - workshop_print_submission_assessments($workshop, $submission, "student"), - number_format(($workshop->teacherweight * $submission->teachergrade + $workshop->peerweight * - $submission->peergrade) / ($workshop->teacherweight + $workshop->peerweight), 1)) ; - } - $n++; - if ($n > $nentries) { - break; - } - } - print_heading(get_string("leaguetable", "workshop")); - print_table($table); + // print an order table of (student) submissions showing teacher's and student's assessments + + if (! $course = get_record("course", "id", $workshop->course)) { + error("Print league table: Course is misconfigured"); + } + $nentries = $workshop->showleaguetable; + if ($nentries == 99) { + $nentries = 999999; // a large number + } + + if ($workshop->anonymous and isstudent($course->id)) { + $table->head = array (get_string("title", "workshop"), + get_string("teacherassessments", "workshop", $course->teacher), + get_string("studentassessments", "workshop", $course->student), get_string("overallgrade", "workshop")); + $table->align = array ("left", "center", "center", "center"); + $table->size = array ("*", "*", "*", "*"); + } + else { // show names + $table->head = array (get_string("title", "workshop"), get_string("name"), + get_string("teacherassessments", "workshop", $course->teacher), + get_string("studentassessments", "workshop", $course->student), get_string("overallgrade", "workshop")); + $table->align = array ("left", "left", "center", "center", "center"); + $table->size = array ("*", "*", "*", "*", "*"); + } + $table->cellpadding = 2; + $table->cellspacing = 0; + + if ($submissions = workshop_get_student_submissions($workshop, "grade")) { + $n = 1; + foreach ($submissions as $submission) { + if (!$user = get_record("user", "id", $submission->userid)) { + error("Print league table: user not found"); + } + if ($workshop->anonymous and isstudent($course->id)) { + $table->data[] = array(workshop_print_submission_title($workshop, $submission), + workshop_print_submission_assessments($workshop, $submission, "teacher"), + workshop_print_submission_assessments($workshop, $submission, "student"), + number_format(($workshop->teacherweight * $submission->teachergrade + $workshop->peerweight * + $submission->peergrade) / ($workshop->teacherweight + $workshop->peerweight), 1)) ; + } + else { + $table->data[] = array(workshop_print_submission_title($workshop, $submission), $user->firstname." ". + $user->lastname, workshop_print_submission_assessments($workshop, $submission, "teacher"), + workshop_print_submission_assessments($workshop, $submission, "student"), + number_format(($workshop->teacherweight * $submission->teachergrade + $workshop->peerweight * + $submission->peergrade) / ($workshop->teacherweight + $workshop->peerweight), 1)) ; + } + $n++; + if ($n > $nentries) { + break; + } + } + print_heading(get_string("leaguetable", "workshop")); + print_table($table); echo "

< > ".get_string("assessmentdropped", "workshop")."

\n"; - } - } - + } + } + ////////////////////////////////////////////////////////////////////////////////////// function workshop_print_submission_assessments($workshop, $submission, $type) { - // Returns the teacher or peer grade and a hyperlinked list of grades for this submission - - $str = ''; - if ($assessments = workshop_get_assessments($submission)) { - switch ($type) { - case "teacher" : - if ($submission->teachergrade) { // if there's a final teacher's grade... - $str = "$submission->teachergrade "; - } - foreach ($assessments as $assessment) { - if (isteacher($workshop->course, $assessment->userid)) { + // Returns the teacher or peer grade and a hyperlinked list of grades for this submission + + $str = ''; + if ($assessments = workshop_get_assessments($submission)) { + switch ($type) { + case "teacher" : + if ($submission->teachergrade) { // if there's a final teacher's grade... + $str = "$submission->teachergrade "; + } + foreach ($assessments as $assessment) { + if (isteacher($workshop->course, $assessment->userid)) { - $str .= "id&aid=$assessment->id\">"; + $str .= "id&aid=$assessment->id\">"; if ($assessment->donotuse) { $str .= "<"; } else { $str .= "["; } - $str .= number_format($assessment->grade, 0); - if ($assessment->gradinggrade) { // funny, teacher is grading self! - $str .= "/".number_format($assessment->gradinggrade*100/COMMENTSCALE, 0)."%"; - } + $str .= number_format($assessment->grade, 0); + if ($assessment->gradinggrade) { // funny, teacher is grading self! + $str .= "/".number_format($assessment->gradinggrade*100/COMMENTSCALE, 0)."%"; + } if ($assessment->donotuse) { - $str .= "> "; + $str .= "> "; } else { - $str .= "] "; + $str .= "] "; } - } - } - break; - case "student" : - if ($submission->peergrade) { // if there's a final peer grade... - $str = "$submission->peergrade "; - } - foreach ($assessments as $assessment) { - if (isstudent($workshop->course, $assessment->userid)) { - $str .= "id&aid=$assessment->id\">"; + } + } + break; + case "student" : + if ($submission->peergrade) { // if there's a final peer grade... + $str = "$submission->peergrade "; + } + foreach ($assessments as $assessment) { + if (isstudent($workshop->course, $assessment->userid)) { + $str .= "id&aid=$assessment->id\">"; if ($assessment->donotuse) { $str .= "<"; } else { $str .= "{"; } - $str .= number_format($assessment->grade, 0); - if ($assessment->gradinggrade) { - $str .= "/".number_format($assessment->gradinggrade*100/COMMENTSCALE, 0)."%"; - } + $str .= number_format($assessment->grade, 0); + if ($assessment->gradinggrade) { + $str .= "/".number_format($assessment->gradinggrade*100/COMMENTSCALE, 0)."%"; + } if ($assessment->donotuse) { - $str .= "> "; + $str .= "> "; } else { - $str .= "} "; + $str .= "} "; } - } - } - break; - } - } - if (!$str) { - $str = " "; // be kind to Mozilla browsers! - } + } + } + break; + } + } + if (!$str) { + $str = " "; // be kind to Mozilla browsers! + } return $str; } @@ -3580,10 +3592,10 @@ function workshop_print_submission_title($workshop, $submission) { // Arguments are objects global $CFG; - - if (!$submission->timecreated) { // a "no submission" - return $submission->title; - } + + if (!$submission->timecreated) { // a "no submission" + return $submission->title; + } $filearea = workshop_file_area_name($workshop, $submission); if ($basedir = workshop_file_area($workshop, $submission)) { @@ -3605,26 +3617,26 @@ function workshop_print_submission_title($workshop, $submission) { function workshop_print_tabbed_heading($tabs) { // Prints a tabbed heading where one of the tabs highlighted. // $tabs is an object with several properties. -// $tabs->names is an array of tab names -// $tabs->urls is an array of links -// $tabs->align is an array of column alignments (defaults to "center") -// $tabs->size is an array of column sizes -// $tabs->wrap is an array of "nowrap"s or nothing -// $tabs->highlight is an index (zero based) of "active" heading . -// $tabs->width is an percentage of the page (defualts to 80%) -// $tabs->cellpadding padding on each cell (defaults to 5) - - global $CFG, $THEME; - +// $tabs->names is an array of tab names +// $tabs->urls is an array of links +// $tabs->align is an array of column alignments (defaults to "center") +// $tabs->size is an array of column sizes +// $tabs->wrap is an array of "nowrap"s or nothing +// $tabs->highlight is an index (zero based) of "active" heading . +// $tabs->width is an percentage of the page (defualts to 80%) +// $tabs->cellpadding padding on each cell (defaults to 5) + + global $CFG, $THEME; + if (isset($tabs->names)) { foreach ($tabs->names as $key => $name) { if (!empty($tabs->urls[$key])) { - $url =$tabs->urls[$key]; - if ($tabs->highlight == $key) { - $tabcontents[$key] = "$name"; - } else { - $tabcontents[$key] = "$name"; - } + $url =$tabs->urls[$key]; + if ($tabs->highlight == $key) { + $tabcontents[$key] = "$name"; + } else { + $tabcontents[$key] = "$name"; + } } else { $tabcontents[$key] = "$name"; } @@ -3645,43 +3657,43 @@ function workshop_print_tabbed_heading($tabs) { if (!empty($tabs->names)) { echo ""; - echo "". - "wwwroot/pix/spacer.gif\" alt=\"\">\n"; + echo "". + "wwwroot/pix/spacer.gif\" alt=\"\">\n"; foreach ($tabcontents as $key => $tab) { if (isset($align[$key])) { - $alignment = "align=\"$align[$key]\""; - } else { + $alignment = "align=\"$align[$key]\""; + } else { $alignment = "align=\"center\""; } if (isset($size[$key])) { $width = "width=\"$size[$key]\""; } else { - $width = ""; - } + $width = ""; + } if (isset($wrap[$key])) { - $wrapping = "no wrap"; - } else { + $wrapping = "no wrap"; + } else { $wrapping = ""; } - if ($key == $tabs->highlight) { - echo "cellheading2\">$tab\n"; - } else { - echo "cellheading\">$tab\n"; - } - echo "". - "wwwroot/pix/spacer.gif\" alt=\"\">\n"; + if ($key == $tabs->highlight) { + echo "cellheading2\">$tab\n"; + } else { + echo "cellheading\">$tab\n"; + } + echo "". + "wwwroot/pix/spacer.gif\" alt=\"\">\n"; } echo "\n"; } else { - echo "No names specified\n"; - } - // bottom stripe - $ncells = count($tabs->names)*2 +1; - $height = 2; - echo "cellheading2\">". - "wwwroot/pix/spacer.gif\" alt=\"\">\n"; + echo "No names specified\n"; + } + // bottom stripe + $ncells = count($tabs->names)*2 +1; + $height = 2; + echo "cellheading2\">". + "wwwroot/pix/spacer.gif\" alt=\"\">\n"; echo "\n"; - // print_simple_box_end(); + // print_simple_box_end(); return true; } @@ -3706,13 +3718,13 @@ function workshop_print_upload_form($workshop) { } if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id)) { error("Course Module ID was incorrect"); - } + } echo "
"; echo "
"; echo " maxbytes\">"; echo " id\">"; - echo "".get_string("title", "workshop").":

\n"; + echo "".get_string("title", "workshop").":

\n"; echo " "; echo " "; echo "
"; @@ -3722,59 +3734,59 @@ function workshop_print_upload_form($workshop) { ////////////////////////////////////////////////////////////////////////////////////// function workshop_print_user_assessments($workshop, $user) { - // Returns the number of assessments and a hyperlinked list of grading grades for the assessments made by this user - - if ($assessments = workshop_get_user_assessments_done($workshop, $user)) { - $n = count($assessments); - $str = "$n ("; - foreach ($assessments as $assessment) { - if ($assessment->timegraded) { - $gradingscaled = intval($assessment->gradinggrade * $workshop->grade / COMMENTSCALE); - $str .= "id&aid=$assessment->id\">"; - $str .= "$gradingscaled "; - } - else { - $str .= "id&aid=$assessment->id\">"; + // Returns the number of assessments and a hyperlinked list of grading grades for the assessments made by this user + + if ($assessments = workshop_get_user_assessments_done($workshop, $user)) { + $n = count($assessments); + $str = "$n ("; + foreach ($assessments as $assessment) { + if ($assessment->timegraded) { + $gradingscaled = intval($assessment->gradinggrade * $workshop->grade / COMMENTSCALE); + $str .= "id&aid=$assessment->id\">"; + $str .= "$gradingscaled "; + } + else { + $str .= "id&aid=$assessment->id\">"; if ($assessment->donotuse) { $str .= "<".number_format($assessment->grade, 0)."> "; } else { $str .= number_format($assessment->grade, 0)." "; } - } - } - $str .= ")"; - } - else { - $str ="0"; - } + } + } + $str .= ")"; + } + else { + $str ="0"; + } return $str; } ////////////////////////////////////////////////////////////////////////////////////// function workshop_test_user_assessments($workshop, $user) { - // see if user has assessed required number of assessments of teachers submissions... - global $CFG; - - $result = true; - $n = 0; - $timenow =time(); - if ($submissions = workshop_get_teacher_submissions($workshop)) { - foreach ($submissions as $submission) { - if ($assessment = workshop_get_submission_assessment($submission, $user)) { - // ...the date stamp on the assessment should be in the past - if ($assessment->timecreated < $timenow) { - $n++; - } - } - } - if ($n < min($workshop->ntassessments, workshop_count_teacher_submissions($workshop))) { - $result = false; - } - } - return $result; - } - + // see if user has assessed required number of assessments of teachers submissions... + global $CFG; + + $result = true; + $n = 0; + $timenow =time(); + if ($submissions = workshop_get_teacher_submissions($workshop)) { + foreach ($submissions as $submission) { + if ($assessment = workshop_get_submission_assessment($submission, $user)) { + // ...the date stamp on the assessment should be in the past + if ($assessment->timecreated < $timenow) { + $n++; + } + } + } + if ($n < min($workshop->ntassessments, workshop_count_teacher_submissions($workshop))) { + $result = false; + } + } + return $result; + } + function workshop_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $workshop="0", $user="", $groupid="") { // Returns all workshop posts since a given time. If workshop is specified then