dirroot/files/mimetypes.php");
/*** Constants **********************************/
$WORKSHOP_TYPE = array (0 => get_string("notgraded", "workshop"),
1 => get_string("accumulative", "workshop"),
2 => get_string("errorbanded", "workshop"),
3 => get_string("criteria", "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', 'size' => 2, 'start' => 'yes', 'end' => 'no'),
1 => array( 'name' => get_string("scalepresent", "workshop"), 'type' => 'radio', 'size' => 2, 'start' => 'present', 'end' => 'absent'),
2 => array( 'name' => get_string("scalecorrect", "workshop"), 'type' => 'radio', 'size' => 2, 'start' => 'correct', 'end' => 'incorrect'),
3 => array( 'name' => get_string("scalegood3", "workshop"), 'type' => 'radio', 'size' => 3, 'start' => 'good', 'end' => 'poor'),
4 => array( 'name' => get_string("scaleexcellent4", "workshop"), 'type' => 'radio', 'size' => 4, 'start' => 'excellent', 'end' => 'very poor'),
5 => array( 'name' => get_string("scaleexcellent5", "workshop"), 'type' => 'radio', 'size' => 5, 'start' => 'excellent', 'end' => 'very poor'),
6 => array( 'name' => get_string("scaleexcellent7", "workshop"), 'type' => 'radio', 'size' => 7, 'start' => 'excellent', 'end' => 'very poor'),
7 => array( 'name' => get_string("scale10", "workshop"), 'type' => 'selection', 'size' => 10),
8 => array( 'name' => get_string("scale20", "workshop"), 'type' => 'selection', 'size' => 20),
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, 14 => 4.0);
$WORKSHOP_FWEIGHTS = array( 0 => 0, 1 => 0.1, 2 => 0.25, 3 => 0.5, 4 => 0.75, 5 => 1, 6 => 1.5,
7 => 2.0, 8 => 3.0, 9 => 5.0, 10 => 7.5, 11=> 10.0);
if (!defined("COMMENTSCALE")) {
define("COMMENTSCALE", 20);
}
if (!defined("PASSGRADE")) {
define("PASSGRADE", 8); // 40% of COMMENTSCALE
}
/*** Standard Moodle functions ******************
function workshop_add_instance($workshop)
function workshop_update_instance($workshop)
function workshop_delete_instance($id)
function workshop_user_outline($course, $user, $mod, $workshop)
function workshop_user_complete($course, $user, $mod, $workshop)
function workshop_cron ()
function workshop_print_recent_activity(&$logs, $isteacher=false)
function workshop_grades($workshopid)
**********************************************/
function workshop_add_instance($workshop) {
// Given an object containing all the necessary data,
// (defined by the form in mod.html) this function
// will create a new instance and return the id number
// of the new instance.
$workshop->timemodified = time();
$workshop->deadline = make_timestamp($workshop->deadlineyear,
$workshop->deadlinemonth, $workshop->deadlineday, $workshop->deadlinehour,
$workshop->deadlineminute);
return insert_record("workshop", $workshop);
}
function workshop_choose_from_menu ($options, $name, $selected="", $nothing="choose", $script="", $nothingvalue="0", $return=false) {
/// Given an array of value, creates a popup menu to be part of a form
/// $options["value"]["label"]
if ($nothing == "choose") {
$nothing = get_string("choose")."...";
}
if ($script) {
$javascript = "onChange=\"$script\"";
} else {
$javascript = "";
}
$output = "\n";
if ($nothing) {
$output .= " $label) {
$output .= " timemodified = time();
$workshop->deadline = make_timestamp($workshop->deadlineyear,
$workshop->deadlinemonth, $workshop->deadlineday, $workshop->deadlinehour,
$workshop->deadlineminute);
$workshop->id = $workshop->instance;
return update_record("workshop", $workshop);
}
function workshop_delete_instance($id) {
// Given an ID of an instance of this module,
// this function will permanently delete the instance
// and any data that depends on it.
if (! $workshop = get_record("workshop", "id", "$id")) {
return false;
}
// delete all the associated records in the workshop tables, start positive...
$result = true;
if (! delete_records("workshop_comments", "workshopid", "$workshop->id")) {
$result = false;
}
if (! delete_records("workshop_grades", "workshopid", "$workshop->id")) {
$result = false;
}
if (! delete_records("workshop_elements", "workshopid", "$workshop->id")) {
$result = false;
}
if (! delete_records("workshop_assessments", "workshopid", "$workshop->id")) {
$result = false;
}
if (! delete_records("workshop_submissions", "workshopid", "$workshop->id")) {
$result = false;
}
if (! delete_records("workshop", "id", "$workshop->id")) {
$result = false;
}
return $result;
}
function workshop_user_outline($course, $user, $mod, $workshop) {
if ($submission = workshop_get_submission($workshop, $user)) {
if ($submission->grade) {
$result->info = get_string("grade").": $submission->grade";
}
$result->time = $submission->timemodified;
return $result;
}
return NULL;
}
function workshop_user_complete($course, $user, $mod, $workshop) {
if ($submission = workshop_get_submission($workshop, $user)) {
if ($basedir = workshop_file_area($workshop, $user)) {
if ($files = get_directory_list($basedir)) {
$countfiles = count($files)." ".get_string("submissions", "workshop");
foreach ($files as $file) {
$countfiles .= "; $file";
}
}
}
print_simple_box_start();
echo "";
echo get_string("lastmodified").": ";
echo userdate($submission->timemodified);
echo workshop_print_difference($workshop->timedue - $submission->timemodified);
echo "
";
workshop_print_user_files($workshop, $user);
echo " ";
workshop_print_feedback($course, $submission);
print_simple_box_end();
} else {
print_string("notsubmittedyet", "workshop");
}
}
function workshop_cron () {
// Function to be run periodically according to the moodle cron
// Finds all workshop notifications that have yet to be mailed out, and mails them
global $CFG, $USER;
$cutofftime = time() - $CFG->maxeditingtime;
// look for new assessments
if ($assessments = workshop_get_unmailed_assessments($cutofftime)) {
$timenow = time();
foreach ($assessments as $assessment) {
echo "Processing workshop assessment $assessment->id\n";
if (! $submission = get_record("workshop_submissions", "id", "$assessment->submissionid")) {
echo "Could not find submission $assessment->submissionid\n";
continue;
}
if (! $submissionowner = get_record("user", "id", "$submission->userid")) {
echo "Could not find user $submission->userid\n";
continue;
}
if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) {
echo "Could not find user $assessment->userid\n";
continue;
}
if (! $course = get_record("course", "id", "$assessment->course")) {
echo "Could not find course $assessment->course\n";
continue;
}
if (! isstudent($course->id, $submissionowner->id) and !isteacher($course->id, $submissionowner->id)) {
continue; // Not an active participant
}
if (! isstudent($course->id, $assessmentowner->id) and !isteacher($course->id, $assessmentowner->id)) {
continue; // Not an active participant
}
if (! $workshop = get_coursemodule_from_instance("workshop", $assessment->workshopid, $course->id)) {
echo "Could not find course module for workshop id $submission->workshop\n";
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;
$msg = "Your assignment \"$submission->title\" has been assessed.\n".
"The comments and grade can be seen in ".
"the workshop assignment '$workshop->name'\n\n";
$postsubject = "$course->shortname: $strworkshops: $workshop->name";
$posttext = "$course->shortname -> $strworkshops -> $workshop->name\n";
$posttext .= "---------------------------------------------------------------------\n";
$posttext .= $msg;
$posttext .= "You can see it in your workshop assignment:\n";
$posttext .= " $CFG->wwwroot/mod/workshop/view.php?a=$workshop->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?a=$workshop->id\">$workshop->name
";
$posthtml .= "";
$posthtml .= "$msg
";
$posthtml .= "You can see it wwwroot/mod/workshop/view.php?a=$workshop->id\">";
$posthtml .= "in your workshop assignment .
";
} 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_assessments", "mailed", "1", "id", "$assessment->id")) {
echo "Could not update the mailed field for id $assessment->id\n";
}
}
}
// look for new comments
if ($comments = workshop_get_unmailed_comments($cutofftime)) {
$timenow = time();
foreach ($comments as $comment) {
echo "Processing workshop comment $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 (! $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 (! $course = get_record("course", "id", "$comment->course")) {
echo "Could not find course $comment->course\n";
continue;
}
if (! isstudent($course->id, $submissionowner->id) and !isteacher($course->id, $submissionowner->id)) {
continue; // Not an active participant
}
if (! isstudent($course->id, $assessmentowner->id) and !isteacher($course->id, $assessmentowner->id)) {
continue; // Not an active participant
}
if (! $workshop = get_coursemodule_from_instance("workshop", $assessment->workshopid, $course->id)) {
echo "Could not find course module for workshop id $submission->workshop\n";
continue;
}
$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;
$msg = "A comment has been added to the assignment \"$submission->title\".\n".
"The new comment can be seen in ".
"the workshop assignment '$workshop->name'\n\n";
$postsubject = "$course->shortname: $strworkshops: $workshop->name";
$posttext = "$course->shortname -> $strworkshops -> $workshop->name\n";
$posttext .= "---------------------------------------------------------------------\n";
$posttext .= $msg;
$posttext .= "You can see it in your workshop assignment:\n";
$posttext .= " $CFG->wwwroot/mod/workshop/view.php?a=$workshop->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?a=$workshop->id\">$workshop->name
";
$posthtml .= "";
$posthtml .= "$msg
";
$posthtml .= "You can see it wwwroot/mod/workshop/view.php?a=$workshop->id\">";
$posthtml .= "in your workshop assignment .
";
}
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";
}
}
// see if the assessor needs to to told
if ($comment->userid != $assessment->userid) {
$USER->lang = $assessmentowner->lang;
$sendto = $assessmentowner;
$msg = "A comment has been added to the assignment \"$submission->title\".\n".
"The new comment can be seen in ".
"the workshop assignment '$workshop->name'\n\n";
$postsubject = "$course->shortname: $strworkshops: $workshop->name";
$posttext = "$course->shortname -> $strworkshops -> $workshop->name\n";
$posttext .= "---------------------------------------------------------------------\n";
$posttext .= $msg;
$posttext .= "You can see it in your workshop assignment:\n";
$posttext .= " $CFG->wwwroot/mod/workshop/view.php?a=$workshop->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?a=$workshop->id\">$workshop->name
";
$posthtml .= "";
$posthtml .= "$msg
";
$posthtml .= "You can see it wwwroot/mod/workshop/view.php?a=$workshop->id\">";
$posthtml .= "in your workshop assignment .
";
}
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";
}
}
}
}
// look for new gradings
if ($assessments = workshop_get_unmailed_graded_assessments($cutofftime)) {
$timenow = time();
foreach ($assessments as $assessment) {
echo "Processing workshop assessment $assessment->id (graded)\n";
if (! $submission = get_record("workshop_submissions", "id", "$assessment->submissionid")) {
echo "Could not find submission $assessment->submissionid\n";
continue;
}
if (! $submissionowner = get_record("user", "id", "$submission->userid")) {
echo "Could not find user $submission->userid\n";
continue;
}
if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) {
echo "Could not find user $assessment->userid\n";
continue;
}
if (! $course = get_record("course", "id", "$assessment->course")) {
echo "Could not find course $assessment->course\n";
continue;
}
if (! isstudent($course->id, $submissionowner->id) and !isteacher($course->id, $submissionowner->id)) {
continue; // Not an active participant
}
if (! isstudent($course->id, $assessmentowner->id) and !isteacher($course->id, $assessmentowner->id)) {
continue; // Not an active participant
}
if (! $workshop = get_coursemodule_from_instance("workshop", $assessment->workshopid, $course->id)) {
echo "Could not find course module for workshop id $submission->workshop\n";
continue;
}
$strworkshops = get_string("modulenameplural", "workshop");
$strworkshop = get_string("modulename", "workshop");
// it's a grading tell the assessment owner
$USER->lang = $assessmentowner->lang;
$sendto = $assessmentowner;
$msg = "Your assessment of the assignment \"$submission->title\" has by graded.\n".
"The comments and grade given by the $course->teacher can be seen in ".
"the workshop assignment '$workshop->name'\n\n";
$postsubject = "$course->shortname: $strworkshops: $workshop->name";
$posttext = "$course->shortname -> $strworkshops -> $workshop->name\n";
$posttext .= "---------------------------------------------------------------------\n";
$posttext .= $msg;
$posttext .= "You can see it in your workshop assignment:\n";
$posttext .= " $CFG->wwwroot/mod/workshop/view.php?a=$workshop->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?a=$workshop->id\">$workshop->name
";
$posthtml .= "";
$posthtml .= "$msg
";
$posthtml .= "You can see it wwwroot/mod/workshop/view.php?a=$workshop->id\">";
$posthtml .= "in your workshop assignment .
";
} 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_assessments", "mailed", "1", "id", "$assessment->id")) {
echo "Could not update the mailed field for id $assessment->id\n";
}
}
}
return true;
}
function workshop_print_recent_activity($course, $isteacher, $timestart) {
global $CFG;
$content = false;
$submissions = NULL;
// only show submissions and assessments to teachers
if ($isteacher) {
if ($logs = get_records_select("log", "time > '$timestart' AND ".
"course = '$course->id' AND ".
"module = 'workshop' AND ".
"action = 'submit' ", "time ASC")) {
foreach ($logs as $log) {
//Create a temp valid module structure (course,id)
$tempmod->course = $log->course;
$tempmod->id = $log->info;
//Obtain the visible property from the instance
$modvisible = instance_is_visible($log->module,$tempmod);
//Only if the mod is visible
if ($modvisible) {
$submissions[$log->info] = workshop_log_info($log);
$submissions[$log->info]->time = $log->time;
$submissions[$log->info]->url = $log->url;
}
}
if ($submissions) {
$strftimerecent = get_string("strftimerecent");
$content = true;
print_headline(get_string("newsubmissions", "workshop").":");
foreach ($submissions as $submission) {
$date = userdate($submission->time, $strftimerecent);
echo "$date - $submission->firstname $submission->lastname ";
echo "\"wwwroot/mod/workshop/$submission->url\">";
echo "$submission->name";
echo " \"
";
}
}
}
$assessments = NULL;
if ($logs = get_records_select("log", "time > '$timestart' AND ".
"course = '$course->id' AND ".
"module = 'workshop' AND ".
"action = 'assess' ", "time ASC")) {
foreach ($logs as $log) {
//Create a temp valid module structure (course,id)
$tempmod->course = $log->course;
$tempmod->id = $log->info;
//Obtain the visible property from the instance
$modvisible = instance_is_visible($log->module,$tempmod);
//Only if the mod is visible
if ($modvisible) {
$assessments[$log->info] = workshop_log_info($log);
$assessments[$log->info]->time = $log->time;
$assessments[$log->info]->url = $log->url;
}
}
if ($assessments) {
$strftimerecent = get_string("strftimerecent");
$content = true;
print_headline(get_string("newassessments", "workshop").":");
foreach ($assessments as $assessment) {
$date = userdate($assessment->time, $strftimerecent);
echo "$date - $assessment->firstname $assessment->lastname ";
echo "\"wwwroot/mod/workshop/$assessment->url\">";
echo "$assessment->name";
echo " \"
";
}
}
}
}
$gradings = NULL;
if ($logs = get_records_select("log", "time > '$timestart' AND ".
"course = '$course->id' AND ".
"module = 'workshop' AND ".
"action = 'grade' ", "time ASC")) {
foreach ($logs as $log) {
//Create a temp valid module structure (course,id)
$tempmod->course = $log->course;
$tempmod->id = $log->info;
//Obtain the visible property from the instance
$modvisible = instance_is_visible($log->module,$tempmod);
//Only if the mod is visible
if ($modvisible) {
$gradings[$log->info] = workshop_log_info($log);
$gradings[$log->info]->time = $log->time;
$gradings[$log->info]->url = $log->url;
}
}
if ($gradings) {
$strftimerecent = get_string("strftimerecent");
$content = true;
print_headline(get_string("newgradings", "workshop").":");
foreach ($gradings as $grading) {
$date = userdate($grading->time, $strftimerecent);
echo "$date - $grading->firstname $grading->lastname ";
echo "\"wwwroot/mod/workshop/$grading->url\">";
echo "$grading->name";
echo " \"
";
}
}
}
return $content;
}
function workshop_grades($workshopid) {
/// Must return an array of grades, indexed by user, and a max grade.
$return->grades = get_records_select_menu("workshop_submissions",
"workshopid = $workshopid", "", "userid, finalgrade");
$return->maxgrade = get_field("workshop", "grade", "id", "$workshopid");
return $return;
}
function workshop_log_info($log) {
global $CFG;
return get_record_sql("SELECT a.name, u.firstname, u.lastname
FROM {$CFG->prefix}workshop a,
{$CFG->prefix}user u
WHERE a.id = '$log->info'
AND u.id = '$log->userid'");
}
//////////////////////////////////////////////////////////////////////////////////////
/*** Functions for the workshop module ******
function workshop_count_all_assessments($workshop, $user) {
function workshop_count_all_submissions_for_assessment($workshop, $user) {
function workshop_count_comments($assessment) {
function workshop_count_peer_assessments($workshop, $user) {
function workshop_count_student_submissions($workshop) {
function workshop_count_student_submissions_for_assessment($workshop, $user) {
function workshop_count_teacher_assessments($workshop, $user) {
function workshop_count_teacher_submissions($workshop) {
function workshop_count_teacher_submissions_for_assessment($workshop, $user) {
function workshop_count_ungraded_assessments_student($workshop) {
function workshop_count_ungraded_assessments_teacher($workshop) {
function workshop_delete_submitted_files($workshop, $submission) {
function workshop_delete_user_files($workshop, $user, $exception) {
function workshop_file_area($workshop, $submission) {
function workshop_file_area_name($workshop, $submission) {
function workshop_get_assessments($submission) {
function workshop_get_comments($assessment) {
function workshop_get_student_assessments($workshop, $user) {
function workshop_get_student_submission_assessments($workshop) {
function workshop_get_student_submissions($workshop) {
function workshop_get_submission_assessment($submission, $user) {
function workshop_get_teacher_submission_assessments($workshop) {
function workshop_get_teacher_submissions($workshop) {
function workshop_get_ungraded_assessments($workshop) {
function workshop_get_unmailed_assessments($cutofftime) {
function workshop_get_unmailed_marked_assessments($cutofftime) {
function workshop_get_user_assessments($workshop, $user) {
function workshop_get_user_submissions($workshop, $user) {
function workshop_get_users_done($workshop) {
function workshop_list_all_submissions($workshop) {
function workshop_list_all_ungraded_assessments($workshop) {
function workshop_list_assessed_submissions($workshop, $user) {
function workshop_list_peer_assessments($workshop, $user) {
function workshop_list_student_submissions($workshop, $user) {
function workshop_list_submissions_for_admin($workshop, $order) {
function workshop_list_teacher_assessments($workshop, $user) {
function workshop_list_teacher_submissions($workshop) {
function workshop_list_unassessed_student_submissions($workshop, $user) {
function workshop_list_unassessed_teacher_submissions($workshop, $user) {
function workshop_list_ungraded_assessments($workshop, $stype) {
function workshop_list_user_submissions($workshop, $user) {
function workshop_print_assessment($workshop, $assessment, $allowchanges, $showcommentlinks)
function workshop_print_difference($time) {
function workshop_print_feedback($course, $submission) {
function workshop_print_submission_assessments($workshop, $submission, $type) {
function workshop_print_submission_title($workshop, $user) {
function workshop_print_time_to_deadline($time) {
function workshop_print_upload_form($workshop) {
function workshop_print_user_assessments($workshop, $user) {
function workshop_test_user_assessments($workshop, $user) {
***************************************/
function workshop_count_all_assessments($workshop, $user) {
return count_records("workshop_assessments", "workshopid", $workshop->id, "userid", $user->id);
}
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 timecreated > 0")) {
$n =count($submissions);
foreach ($submissions as $submission) {
$n -= count_records("workshop_assessments", "submissionid", $submission->id, "userid", $user->id);
}
}
return $n;
}
function workshop_count_assessments($workshop, $stype, $user) {
// returns the number of assessments made by a user on either the student or teacher submissions
// the maxeditingtime is NOT taken into account here
switch ($stype) {
case "student" :
$submissions = workshop_get_student_submissions($workshop);
break;
case "teacher" :
$submissions = workshop_get_teacher_submissions($workshop);
break;
}
$n = 0;
if ($submissions) {
foreach ($submissions as $submission) {
$n += count_records_select("workshop_assessments", "(submissionid = $submission->id) AND
(userid = $user->id)");
}
}
return $n;
}
function workshop_count_comments($assessment) {
// Return the number comments for this assessment provided they are newer than the assessment,
return count_records_select("workshop_comments", "(assessmentid = $assessment->id) AND
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;
}
function workshop_count_student_submissions($workshop) {
global $CFG;
return count_records_sql("SELECT count(*) FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}user_students u
WHERE u.course = $workshop->course
AND s.userid = u.userid
AND s.workshopid = $workshop->id
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;
}
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;
}
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
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;
}
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 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 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!");
}
}
}
}
}
function workshop_delete_user_files($workshop, $user, $exception) {
// Deletes all the user files in the workshop area for a user
// 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!");
}
}
}
}
}
}
function workshop_file_area($workshop, $submission) {
return make_upload_directory( workshop_file_area_name($workshop, $submission) );
}
function workshop_file_area_name($workshop, $submission) {
// Creates a directory file name, suitable for make_upload_directory()
global $CFG;
return "$workshop->course/$CFG->moddata/workshop/$submission->id";
}
function workshop_get_assessments($submission) {
// Return all assessments for this submission provided they are after the editing time, ordered oldest first, newest last
global $CFG;
$timenow = time();
return get_records_select("workshop_assessments", "(submissionid = $submission->id) AND
(timecreated < $timenow - $CFG->maxeditingtime)", "timecreated DESC");
}
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 get_records_select("workshop_comments", "(assessmentid = $assessment->id) AND
timecreated > $assessment->timecreated",
"timecreated DESC");
}
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;
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.userid = $user->id
ORDER BY a.timecreated DESC");
}
function workshop_get_student_submission_assessments($workshop) {
// Return all assessments on the student submissions, order by youngest first, oldest last
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");
}
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 = "firstname, lastname";
}
return get_records_sql("SELECT s.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}user_students u,
{$CFG->prefix}user
WHERE u.course = $workshop->course
AND s.userid = u.userid
AND user.id = u.userid
AND s.workshopid = $workshop->id
AND s.timecreated > 0
ORDER BY $order");
}
function workshop_get_submission_assessment($submission, $user) {
// Return the user's assessment for this submission
return get_record("workshop_assessments", "submissionid", $submission->id, "userid", $user->id);
}
function workshop_get_teacher_submission_assessments($workshop) {
// Return all assessments on the teacher submissions, order by youngest first, oldest last
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");
}
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, {$CFG->prefix}user_teachers u
WHERE u.course = $workshop->course
AND s.userid = u.userid
AND s.workshopid = $workshop->id
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;
return get_records_select("workshop_assessments", "workshopid = $workshop->id AND (timegraded = 0 OR
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;
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");
}
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;
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");
}
function workshop_get_unmailed_assessments($cutofftime) {
/// 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.timecreated < $cutofftime
AND g.id = a.workshopid");
}
function workshop_get_unmailed_comments($cutofftime) {
/// 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 g.id = c.workshopid");
}
function workshop_get_unmailed_graded_assessments($cutofftime) {
/// 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 g.id = a.workshopid");
}
function workshop_get_user_assessments($workshop, $user) {
// Return all the user's assessments, newest first, oldest last
return get_records_select("workshop_assessments", "workshopid = $workshop->id AND userid = $user->id",
"timecreated DESC");
}
function workshop_get_user_submissions($workshop, $user) {
// return submission of user newest first, oldest last
return get_records_select("workshop_submissions ",
"workshopid = $workshop->id AND userid = $user->id", "timecreated DESC" );
}
function workshop_get_users_done($workshop) {
global $CFG;
return get_records_sql("SELECT u.*
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'
ORDER BY a.timemodified DESC");
}
function workshop_list_all_submissions($workshop, $user) {
// 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"), 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, $comment);
}
print_table($table);
}
echo "".get_string("studentsubmissions", "workshop", $course->student)."
\n";
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, $comment);
}
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);
}
}
}
function workshop_list_assessed_submissions($workshop, $user) {
// list the submissions that have been assessed by this user
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;
if ($assessments = workshop_get_student_assessments($workshop, $user)) {
$timenow = time();
foreach ($assessments as $assessment) {
$comment = "";
$submission = get_record("workshop_submissions", "id", $assessment->submissionid);
if (($timenow - $assessment->timecreated) > $CFG->maxeditingtime) {
$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")." ";
}
}
else { // there's still time left to edit...
$action = "id&sid=$submission->id\">".
get_string("edit", "workshop")." ";
}
$comment = get_string("assessedon", "workshop", userdate($assessment->timecreated));
// 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, $comment);
}
}
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)) {
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 (isstudent($workshop->course, $assessment->userid)) { // assessments by students only
$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 ($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, $comment);
}
}
}
}
}
}
if (isset($table->data)) {
print_table($table);
}
else {
echo "".get_string("noassessmentsdone", "workshop")." \n";
}
}
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;
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 = workshop_count_assessments($workshop, "student", $user);
// count the number of assessments for each student submission
if ($submissions = workshop_get_student_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);
$nsassessments = $workshop->nsassessments;
if ($workshop->includeself) { // add one if self assessment flag is set
$nsassessments++;
}
foreach ($nassessments as $submissionid =>$n) {
$comment = "";
$submission = get_record("workshop_submissions", "id", $submissionid);
if (($submission->userid != $user->id) or $workshop->includeself) {
// add if user has NOT already assessed this submission
if (!$assessment = get_record_select("workshop_assessments", "submissionid = $submissionid
AND userid = $user->id")) {
if ($submission->userid == $user->id) {
$comment = get_string("ownwork", "workshop");
}
if ($nassessed < $nsassessments) {
$action = "id&sid=$submission->id\">".
get_string("assess", "workshop")." ";
$table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment);
$nassessed++;
}
else {
break;
}
}
}
}
}
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;
if (! $course = get_record("course", "id", $workshop->course)) {
error("Course is misconfigured");
}
$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 (($curtime - $assessment->timecreated) > $CFG->maxeditingtime) {
$action .= " | id&aid=$assessment->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_table($table);
}
echo "".get_string("studentsubmissions", "workshop", $course->student)."
\n";
unset($table);
switch ($order) {
case "title" :
$table->head = array (get_string("title", "workshop"), "id&order=name\">".
get_string("submittedby", "workshop")." ", get_string("action", "workshop"));
break;
case "name" :
$table->head = array ("id&order=title\">".
get_string("title", "workshop")." ", get_string("submittedby", "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&aid=$assessment->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 ($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), "$user->firstname $user->lastname", $action);
}
print_table($table);
}
}
function workshop_list_teacher_assessments($workshop, $user) {
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";
}
}
function workshop_list_teacher_submissions($workshop, $user) {
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 successfully assessed enough display one of 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);
echo "";
print_r($nassessments);
reset($nassessments);
$comment = "";
foreach ($nassessments as $submissionid => $n) { // actually only the first one is displayed...
$comment = '';
$submission = get_record("workshop_submissions", "id", $submissionid);
// ... provided the user has NOT already assessed that submission
if (!$assessment = get_record_select("workshop_assessments", "submissionid = $submissionid
AND userid = $user->id")) {
$action = "id&sid=$submission->id\">".
get_string("assess", "workshop")." ";
$table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment);
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: still fresh; graded but not passed; and static (may or may not be graded
if (($timenow - $assessment->timecreated) < $CFG->maxeditingtime) { // there's still time left to edit...
$action = "id&sid=$submission->id\">".
get_string("edit", "workshop")." ";
}
// has teacher graded user's assessment and it has not passed?
elseif ($assessment->timegraded and (($timenow - $assessment->timegraded) > $CFG->maxeditingtime) and
($assessment->gradinggrade < PASSGRADE)) { // allow the user to have another go
$action = "id&sid=$submission->id\">"
.get_string("reassess", "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("gradedbyteacher", "workshop", $course->teacher);
$comment .= " (".number_format($assessment->gradinggrade*100/COMMENTSCALE,0)."%)";
}
$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("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) {
$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_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);
}
}
}
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("name"),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);
$user = get_record("user", "id", $assessment->userid);
$table->data[] = array(workshop_print_submission_title($workshop, $submission),
$user->firstname." ".$user->lastname, userdate($assessment->timecreated), $action);
}
}
if (isset($table->data)) {
print_table($table);
}
}
}
function workshop_list_user_submissions($workshop, $user) {
$table->head = array (get_string("title", "workshop"), get_string("submitted", "assignment"), get_string("assessments", "workshop"));
$table->align = array ("LEFT", "LEFT", "LEFT");
$table->size = array ("*", "*", "*");
$table->cellpadding = 2;
$table->cellspacing = 0;
if ($submissions = workshop_get_user_submissions($workshop, $user)) {
foreach ($submissions as $submission) {
$n = count_records("workshop_assessments", "submissionid", $submission->id);
$table->data[] = array(workshop_print_submission_title($workshop, $submission), userdate($submission->timecreated), $n);
}
print_table($table);
}
}
function workshop_print_assessment($workshop, $assessment = false, $allowchanges = false,
$showcommentlinks = false) {
// $allowchanges added 14/7/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 $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";
// 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 "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";
}
echo "
\n";
}
// only show the grade if grading strategy > 0 and the grade is positive
if ($showgrades and $assessment->grade >= 0) {
echo "".get_string("thegradeis", "workshop").": ".number_format($assessment->grade, 2)."% (".
get_string("maximumgrade")." ".number_format($workshop->grade)."%) \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";
}
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";
}
}
}
function workshop_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)";
}
}
function workshop_print_feedback($course, $submission) {
global $CFG, $THEME, $RATING;
if (! $teacher = get_record("user", "id", $submission->teacher)) {
error("Weird workshop error");
}
echo "\n";
echo "\n";
echo "\n";
echo "\nbody\" WIDTH=35 VALIGN=TOP>";
print_user_picture($teacher->id, $course->id, $teacher->picture);
echo " ";
echo "cellheading\">$teacher->firstname $teacher->lastname";
echo " ".userdate($submission->timemarked)." ";
echo " ";
echo "\ncellcontent\">";
echo "";
if ($submission->grade) {
echo get_string("grade").": $submission->grade";
} else {
echo get_string("nograde");
}
echo "
";
echo text_to_html($submission->assessorcomment);
echo "
";
echo "
";
}
function workshop_print_submission_assessments($workshop, $submission, $type) {
// Returns the teacher or peer grade and a hyperlinked list of grades for this submission
if ($assessments = workshop_get_assessments($submission)) {
switch ($type) {
case "teacher" :
$str = "$submission->teachergrade (";
foreach ($assessments as $assessment) {
if (isteacher($workshop->course, $assessment->userid)) {
$str .= "id&aid=$assessment->id\">";
$str .= number_format($assessment->grade, 1)." ";
}
}
break;
case "student" :
$str = "$submission->peergrade (";
foreach ($assessments as $assessment) {
if (isstudent($workshop->course, $assessment->userid)) {
$str .= "id&aid=$assessment->id\">";
$str .= number_format($assessment->grade, 1)." ";
}
}
break;
}
$str .= ")";
}
else {
$str ="0";
}
return $str;
}
function workshop_print_submission_title($workshop, $submission) {
// Arguments are objects
global $CFG;
if (!$submission->timecreated) { // a "no submission"
return $submission->title;
}
$filearea = workshop_file_area_name($workshop, $submission);
if ($basedir = workshop_file_area($workshop, $submission)) {
if (list($file) = get_directory_list($basedir)) {
$icon = mimeinfo("icon", $file);
if ($CFG->slasharguments) {
$ffurl = "file.php/$filearea/$file";
} else {
$ffurl = "file.php?file=/$filearea/$file";
}
return " wwwroot/files/pix/$icon\" HEIGHT=16 WIDTH=16 BORDER=0 ALT=\"File\">".
" wwwroot/$ffurl\">$submission->title ";
}
}
}
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($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\">";
$str .= "- ";
}
}
$str .= ")";
}
else {
$str ="0";
}
return $str;
}
function workshop_print_time_to_deadline($time) {
if ($time < 0) {
$timetext = get_string("afterdeadline", "workshop", format_time($time));
return " ($timetext )";
} else {
$timetext = get_string("beforedeadline", "workshop", format_time($time));
return " ($timetext)";
}
}
function workshop_print_upload_form($workshop) {
// Arguments are objects, needs title coming in
echo "";
echo "
";
echo " maxbytes\">";
echo " id\">";
echo get_string("title", "workshop")." \n";
echo " ";
echo " ";
echo " ";
echo "";
}
function workshop_test_user_assessments($workshop, $user) {
// see if user has passed the required number of assessments of teachers submissions
global $CFG;
$result = true;
$n = 0;
$timenow =time();
if ($workshop->ntassessments) { // they have to pass some!
if ($submissions = workshop_get_teacher_submissions($workshop)) {
foreach ($submissions as $submission) {
if ($assessment = workshop_get_submission_assessment($submission, $user)) {
if (($assessment->gradinggrade >= PASSGRADE) and
(($timenow - $assessment->timegraded) > $CFG->maxeditingtime)) {
$n++;
}
}
}
}
if ($n < min($workshop->ntassessments, workshop_count_teacher_submissions($workshop))) {
$result = false;
}
}
return $result;
}
?>