--- mod/assignment/db/install.xml 2009-05-01 17:04:38.000000000 -0700 +++ mod/assignment/db/install.xml 2011-04-05 13:39:10.000000000 -0700 @@ -14,8 +14,9 @@ - - + + + @@ -37,8 +38,9 @@ - - + + + --- mod/assignment/db/upgrade.php 2011-02-02 16:03:05.000000000 -0800 +++ mod/assignment/db/upgrade.php 2011-04-05 14:42:59.000000000 -0700 @@ -154,6 +154,25 @@ function xmldb_assignment_upgrade($oldve upgrade_mod_savepoint(true, 2009042001, 'assignment'); } + if ($oldversion < 2011040500) { + /// Add field 'groupassignment' on table assignment + $table = new xmldb_table('assignment'); + $field = new xmldb_field('groupassignment', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'emailteachers'); + + /// Launch add field emailteachers + $dbman->add_field($table, $field, true, true); + + /// Add field 'groupid' on table assignment_submissions + $table = new xmldb_table('assignment_submissions'); + $field = new xmldb_field('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'userid'); + + /// Launch add field emailteachers + $dbman->add_field($table, $field, true, true); + + /// assignment savepoint reached + upgrade_mod_savepoint(true, 2011040500, 'assignment'); + } + return true; } --- mod/assignment/lang/en/assignment.php 2010-11-29 16:01:37.000000000 -0800 +++ mod/assignment/lang/en/assignment.php 2011-04-05 13:39:10.000000000 -0700 @@ -127,6 +127,10 @@ $string['invalidassignment'] = 'incorrec $string['invalidid'] = 'assignment ID was incorrect'; $string['invalidtype'] = 'Incorrect assignment type'; $string['invaliduserid'] = 'Invalid user ID'; +$string['isgroupassignment'] = 'Shared team assignment'; +$string['isgroupassignment_help'] = 'Shared team assignments allow one submission per TEAM, as opposed to one submission per USER'; +$string['groupsubmissionindicator'] = 'Team Submission'; +$string['groupsubmissionindividualindicator'] = 'Team Submission (Individually graded)'; $string['itemstocount'] = 'Count'; $string['lastgrade'] = 'Last grade'; $string['late'] = '{$a} late'; --- mod/assignment/lib.php 2011-03-03 16:03:36.000000000 -0800 +++ mod/assignment/lib.php 2011-04-05 13:39:10.000000000 -0700 @@ -79,6 +79,7 @@ class assignment_base { /** @var string */ var $type; + /** * Constructor for the base assignment class * @@ -269,7 +270,13 @@ class assignment_base { } if (!$submission) { /// Get submission for this assignment - $submission = $this->get_submission($USER->id); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($user->id); + } else { + if (! $submission = $this->get_submission($user->id)) { + $submission = $this->get_submission($user->id, false, false, $this->current_group(), true); + } + } } // Check the user can submit $cansubmit = has_capability('mod/assignment:submit', $this->context, $USER->id, false); @@ -385,7 +392,14 @@ class assignment_base { } } else { if (isloggedin()) { - if ($submission = $this->get_submission($USER->id)) { + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $submission = $this->get_submission($USER->id)) { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } + if ($submission) { if ($submission->timemodified) { if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) { $submitted = ''.userdate($submission->timemodified).''; @@ -667,7 +681,22 @@ class assignment_base { $this->process_outcomes($id); - if (!$submission = $this->get_submission($id)) { + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($id); + } else { + if (!$submission = $this->get_submission($id, false)) { + $group_submission = $this->get_submission($id, false, false, $this->current_group($id), true); + $submission = $this->get_submission($id, true); + if ($group_submission) { + foreach (get_object_vars($group_submission) as $key => $value) { + if (($key != "id") and ($key != "userid") and ($key != "groupid")) { + $submission->$key = $value; + } + } + } + } + } + if (!$submission) { $submission = $this->prepare_new_submission($id); $newsubmission = true; } else { @@ -927,7 +956,14 @@ class assignment_base { print_error('nousers'); } - if (!$submission = $this->get_submission($user->id)) { + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($user->id); + } else { + if (! $submission = $this->get_submission($user->id)) { + $submission = $this->get_submission($user->id, false, false, $this->current_group($user->id), true); + } + } + if (!$submission) { $submission = $this->prepare_new_submission($userid); } if ($submission->timemodified > $submission->timemarked) { @@ -974,7 +1010,7 @@ class assignment_base { s.timemodified, s.timemarked, COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status "; $sql = 'FROM {user} u '. - 'LEFT JOIN {assignment_submissions} s ON u.id = s.userid + 'LEFT JOIN {assignment_submissions} s ON u.id = s.userid AND s.groupid = 0 AND s.assignment = '.$this->assignment->id.' '. 'WHERE '.$where.'u.id IN ('.implode(',', $users).') '; @@ -1020,9 +1056,17 @@ class assignment_base { $mformdata->nextid = $nextid; $mformdata->submissioncomment= $submission->submissioncomment; $mformdata->submissioncommentformat= FORMAT_HTML; - $mformdata->submission_content= $this->print_user_files($user->id,true); + $user_groups = groups_get_user_groups($this->course->id, $user->id); + if (($this->assignment->groupassignment) && (count($user_groups[0]) > 1)) { + $mformdata->submission_content=""; + foreach ($user_groups[0] as $user_group) { + $mformdata->submission_content= $mformdata->submission_content . $this->print_user_files($user->id,true,$user_group); + } + } else { + $mformdata->submission_content= $this->print_user_files($user->id,true); + } $mformdata->filter = $filter; - if ($assignment->assignmenttype == 'upload') { + if ($assignment->assignmenttype == 'upload') { $mformdata->fileui_options = array('subdirs'=>1, 'maxbytes'=>$assignment->maxbytes, 'maxfiles'=>$assignment->var1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL); } elseif ($assignment->assignmenttype == 'uploadsingle') { $mformdata->fileui_options = array('subdirs'=>0, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL); @@ -1295,12 +1339,53 @@ class assignment_base { s.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.timemarked, COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status "; - $sql = 'FROM {user} u '. - 'LEFT JOIN {assignment_submissions} s ON u.id = s.userid - AND s.assignment = '.$this->assignment->id.' '. - 'WHERE '.$where.'u.id IN ('.implode(',',$users).') '; - $ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size()); + if (! $this->assignment->groupassignment) { + $sql = 'FROM {user} u '. + 'LEFT JOIN {assignment_submissions} s ON u.id = s.userid + AND s.assignment = '.$this->assignment->id.' '. + 'WHERE '.$where.'u.id IN ('.implode(',',$users).') '; + $ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size()); + } else { + $entiresql = ' +SELECT DISTINCT i.id,i.picture,i.firstname,i.lastname,i.imagealt,i.email, + ifnull(i.submissionid,g.submissionid) submissionid, + ifnull(i.grade,g.grade) grade, + ifnull(i.submissioncomment,g.submissioncomment) submissioncomment, + ifnull(i.timemodified,g.timemodified) timemodified, + ifnull(i.timemarked,g.timemarked) timemarked, + ifnull(i.groupid,g.groupid) groupid, + ifnull(i.status,g.status) status +FROM + (SELECT u.id,u.picture,u.firstname,u.lastname,u.imagealt,u.email, + s.id AS submissionid, s.grade, s.submissioncomment, + s.timemodified, s.timemarked, s.groupid, + COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status + FROM {user} u + LEFT JOIN {assignment_submissions} s ON u.id = s.userid + AND s.assignment = ' .$this->assignment->id. ' + AND s.groupid = 0 + WHERE u.id IN (' .implode(',',$users). ')) i +LEFT JOIN + (SELECT u.id,u.picture,u.firstname,u.lastname,u.imagealt,u.email, + s.id AS submissionid, s.grade, s.submissioncomment, + s.timemodified, s.timemarked, s.groupid, + COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status + FROM {assignment_submissions} s + JOIN {groups_members} g ON g.groupid = s.groupid AND s.groupid > 0 + AND s.assignment = ' .$this->assignment->id. ' + JOIN (SELECT u.id,u.picture,u.firstname,u.lastname,u.imagealt,u.email FROM {user} u WHERE u.id IN ('.implode(',',$users).')) u ON u.id = g.userid +) g +ON i.id = g.id + '; + $ausers = $DB->get_records_sql($entiresql, $params, $table->get_page_start(), $table->get_page_size()); + } + + $users_in_groups_in_this_course = array_keys($DB->get_records_sql("SELECT DISTINCT userid + FROM mdl_groups_members m + JOIN mdl_groups g + ON g.id = m.groupid + WHERE g.courseid = " . $cm->course)); $table->pagesize($perpage, count($users)); @@ -1332,17 +1417,61 @@ class assignment_base { $auser->grade = -1; //no submission yet } - if (!empty($auser->submissionid)) { - ///Prints student answer and student modified date - ///attach file or print link to student answer, depending on the type of the assignment. - ///Refer to print_student_answer in inherited classes. - if ($auser->timemodified > 0) { - $studentmodified = '
'.$this->print_student_answer($auser->id) +// Get the user's groups. +// If the user is in more than one group, get the submissions for all the groups. + $auser_groups = groups_get_user_groups($this->course->id, $auser->id); + if (($this->assignment->groupassignment) && (count($auser_groups[0]) > 1)) { + $studentmodified = '
'; + foreach ($auser_groups[0] as $auser_group) { + $submission = $this->get_submission($auser->id, false, false, $auser_group, true); + if ($submission) { + $groupsubmissionindicator = '' . get_string("groupsubmissionindicator", "assignment") . ': ' .groups_get_group_name($auser_group). ''; + if ($submission->timemodified > 0) { + $studentmodified = $studentmodified + . $groupsubmissionindicator + . $this->print_student_answer($auser->id, false, $auser_group) + . userdate($submission->timemodified).'
'; + } else { + $studentmodified = $studentmodified . ' '; + } + } + } + $studentmodified = $studentmodified . '
'; + } else { + if (!empty($auser->submissionid)) { + ///Prints student answer and student modified date + ///attach file or print link to student answer, depending on the type of the assignment. + ///Refer to print_student_answer in inherited classes. + if ($auser->groupid > 0) { + $groupsubmissionindicator = '' . get_string("groupsubmissionindicator", "assignment") . ': ' .groups_get_group_name($auser->groupid). ''; + if ($auser->timemodified > 0) { + $studentmodified = '
' + . $groupsubmissionindicator + . $this->print_student_answer($auser->id) . userdate($auser->timemodified).'
'; - } else { - $studentmodified = '
 
'; + } else { + $studentmodified = '
 
'; + } + } else { + if (in_array($auser->id, $users_in_groups_in_this_course)) { + $groupsubmissionindicator = '' . get_string("groupsubmissionindividualindicator", "assignment") . ': '; + } else { + $groupsubmissionindicator = ''; + } + if ($auser->timemodified > 0) { + $studentmodified = '
' + . $groupsubmissionindicator + . $this->print_student_answer($auser->id) + . userdate($auser->timemodified).'
'; + } else { + $studentmodified = '
 
'; + } + } } - ///Print grade, dropdown or text + } + + if (!empty($auser->submissionid)) { + ///Print grade, dropdown or text if ($auser->timemarked > 0) { $teachermodified = '
'.userdate($auser->timemarked).'
'; @@ -1544,8 +1673,21 @@ class assignment_base { // store outcomes if needed $this->process_outcomes($feedback->userid); - $submission = $this->get_submission($feedback->userid, true); // Get or make one - + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($feedback->userid, true); + } else { + if (!$submission = $this->get_submission($feedback->userid, false)) { + $group_submission = $this->get_submission($feedback->userid, false, false, $this->current_group($feedback->userid), true); + $submission = $this->get_submission($feedback->userid, true); + if ($group_submission) { + foreach (get_object_vars($group_submission) as $key => $value) { + if (($key != "id") and ($key != "userid") and ($key != "groupid")) { + $submission->$key = $value; + } + } + } + } + } if (!($grading_info->items[0]->grades[$feedback->userid]->locked || $grading_info->items[0]->grades[$feedback->userid]->overridden) ) { @@ -1624,26 +1766,35 @@ class assignment_base { * @param $userid int The id of the user whose submission we want or 0 in which case USER->id is used * @param $createnew boolean optional Defaults to false. If set to true a new submission object will be created in the database * @param bool $teachermodified student submission set if false + * @param $groupid int The id of the group whose submission we want + * @param bool $groupassignment if true, submission is for a group, not a user * @return object The submission */ - function get_submission($userid=0, $createnew=false, $teachermodified=false) { + function get_submission($userid=0, $createnew=false, $teachermodified=false, $groupid=0, $groupassignment=false) { global $USER, $DB; if (empty($userid)) { $userid = $USER->id; } - - $submission = $DB->get_record('assignment_submissions', array('assignment'=>$this->assignment->id, 'userid'=>$userid)); - - if ($submission || !$createnew) { - return $submission; - } - $newsubmission = $this->prepare_new_submission($userid, $teachermodified); - $DB->insert_record("assignment_submissions", $newsubmission); - - return $DB->get_record('assignment_submissions', array('assignment'=>$this->assignment->id, 'userid'=>$userid)); - } - + $usergroups = groups_get_user_groups($this->course->id, $userid); + if ((! $groupassignment) or (empty($usergroups[0]))) { + $submission = $DB->get_record('assignment_submissions', array('assignment'=>$this->assignment->id, 'userid'=>$userid, 'groupid'=>0)); + if ($submission || !$createnew) { + return $submission; + } + $newsubmission = $this->prepare_new_submission($userid, $teachermodified); + $DB->insert_record("assignment_submissions", $newsubmission); + return $DB->get_record('assignment_submissions', array('assignment'=>$this->assignment->id, 'userid'=>$userid, 'groupid'=>0)); + } else { + $submission = $DB->get_record('assignment_submissions', array('assignment'=>$this->assignment->id, 'groupid'=>$groupid)); + if ($submission || !$createnew) { + return $submission; + } + $newsubmission = $this->prepare_new_submission($userid, $teachermodified, $groupid, true); + $DB->insert_record("assignment_submissions", $newsubmission); + return $DB->get_record('assignment_submissions', array('assignment'=>$this->assignment->id, 'groupid'=>$groupid)); + } +} /** * Instantiates a new submission object for a given user * @@ -1651,9 +1802,11 @@ class assignment_base { * * @param int $userid The userid for which we want a submission object * @param bool $teachermodified student submission set if false + * @param int $groupid The groupid for which we want a submission object (if it's a group assignment) + * @param bool $groupassignmnet Set if this is a group assignment. * @return object The submission */ - function prepare_new_submission($userid, $teachermodified=false) { + function prepare_new_submission($userid, $teachermodified=false, $groupid=0, $groupassignment=false) { $submission = new stdClass(); $submission->assignment = $this->assignment->id; $submission->userid = $userid; @@ -1664,6 +1817,11 @@ class assignment_base { } else { $submission->timemodified = $submission->timecreated; } + if ($groupassignment) { + $submission->groupid = $groupid; + } else { + $submission->groupid = '0'; + } $submission->numfiles = 0; $submission->data1 = ''; $submission->data2 = ''; @@ -1851,7 +2009,7 @@ class assignment_base { * @param $return boolean optional defaults to false. If true the list is returned rather than printed * @return string optional */ - function print_user_files($userid=0, $return=false) { + function print_user_files($userid=0, $return=false, $groupid=0) { global $CFG, $USER, $OUTPUT; if (!$userid) { @@ -1861,13 +2019,23 @@ class assignment_base { $userid = $USER->id; } + if (!$groupid) { + $groupid = $this->current_group(); + } + $output = ''; $fs = get_file_storage(); $found = false; - $submission = $this->get_submission($userid); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($userid); + } else { + if (! $submission = $this->get_submission($userid)) { + $submission = $this->get_submission($userid, false, false, $groupid, true); + } + } if (($submission) && $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) { require_once($CFG->libdir.'/portfoliolib.php'); @@ -1974,7 +2142,14 @@ class assignment_base { } } - if ($submission = $this->get_submission($user->id)) { + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $submission = $this->get_submission($USER->id)) { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } + if ($submission) { $fs = get_file_storage(); @@ -2647,7 +2822,7 @@ function assignment_get_user_grades($ass $sql = "SELECT u.id, u.id AS userid, s.grade AS rawgrade, s.submissioncomment AS feedback, s.format AS feedbackformat, s.teacher AS usermodified, s.timemarked AS dategraded, s.timemodified AS datesubmitted FROM {user} u, {assignment_submissions} s - WHERE u.id = s.userid AND s.assignment = :aid + WHERE u.id = s.userid AND s.groupid = 0 AND s.assignment = :aid $user"; return $DB->get_records_sql($sql, $params); @@ -3233,6 +3408,10 @@ function assignment_get_unmailed_submiss */ function assignment_count_real_submissions($cm, $groupid=0) { global $CFG, $DB; +// First, we'll check for group submissions. +// If any group submissions exist, this must be a group assignment, and it makes more sense +// to count the number of group submissions, instead of individually graded ones. + $context = get_context_instance(CONTEXT_MODULE, $cm->id); @@ -3254,11 +3433,44 @@ function assignment_count_real_submissio $userlists = implode(',', $users); - return $DB->count_records_sql("SELECT COUNT('x') + if ($groupid == 0) { + $group_submissions_count = $DB->count_records_sql("SELECT COUNT('x') + FROM {assignment_submissions} + WHERE assignment = ? AND + timemodified > 0 AND + groupid IN ( + SELECT id + FROM mdl_groups + WHERE courseid = " . $cm->course . ")", array($cm->instance)); + + if ($group_submissions_count > 0) { + $users_in_groups_in_this_course = $DB->get_records_sql("SELECT DISTINCT userid + FROM mdl_groups_members m + JOIN mdl_groups g + ON g.id = m.groupid + WHERE g.courseid = " . $cm->course); + $users = array_diff($users, array_keys($users_in_groups_in_this_course)); + $userlists = implode(',', array_values($users)); + } + + $individual_submissions_count = $DB->count_records_sql("SELECT COUNT('x') FROM {assignment_submissions} WHERE assignment = ? AND timemodified > 0 AND + groupid = 0 AND userid IN ($userlists)", array($cm->instance)); + + $total_submissions_count = $group_submissions_count + $individual_submissions_count; + } else { + $group_submissions_count = $DB->count_records_sql("SELECT COUNT('x') + FROM {assignment_submissions} + WHERE assignment = ? AND + timemodified > 0 AND + groupid = $groupid", array($cm->instance)); + $total_submissions_count = $group_submissions_count; + } + + return($total_submissions_count); } --- mod/assignment/type/upload/assignment.class.php 2010-11-05 17:01:32.000000000 -0700 +++ mod/assignment/type/upload/assignment.class.php 2011-04-05 13:39:10.000000000 -0700 @@ -40,6 +40,16 @@ class assignment_upload extends assignme $this->type = 'upload'; } + function group_assignment_participant($userid, $courseid) { + global $DB; + return $DB->count_records_sql("SELECT COUNT('X') + FROM mdl_groups_members m + JOIN mdl_groups g + ON g.id = m.groupid + WHERE g.courseid = $courseid + AND m.userid = $userid"); + } + function view() { global $USER, $OUTPUT; @@ -62,7 +72,17 @@ class assignment_upload extends assignme $this->view_dates(); if (is_enrolled($this->context, $USER)) { - if ($submission = $this->get_submission($USER->id)) { + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } + + if ($submission) { $filecount = $this->count_user_files($submission->id); } else { $filecount = 0; @@ -105,8 +125,12 @@ class assignment_upload extends assignme global $USER, $CFG, $DB, $OUTPUT; require_once($CFG->libdir.'/gradelib.php'); - if (!$submission) { /// Get submission for this assignment + if (! $this->assignment->groupassignment) { $submission = $this->get_submission($USER->id); + } else { + if (! $submission = $this->get_submission($USER->id)) { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } } if (empty($submission->timemarked)) { /// Nothing to show, so print nothing @@ -183,7 +207,15 @@ class assignment_upload extends assignme function view_upload_form() { global $CFG, $USER, $OUTPUT; - $submission = $this->get_submission($USER->id); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } if ($this->is_finalized($submission)) { // no uploading @@ -202,15 +234,28 @@ class assignment_upload extends assignme } else { $str = get_string('uploadfiles', 'assignment'); } - echo $OUTPUT->single_button(new moodle_url('/mod/assignment/type/upload/upload.php', array('contextid'=>$this->context->id, 'userid'=>$USER->id)), $str, 'get'); + if (!isset($_GET['group'])) { + $param_array = array('contextid'=>$this->context->id, 'userid'=>$USER->id); + } else { + $param_array = array('contextid'=>$this->context->id, 'userid'=>$USER->id, 'group'=>$_GET['group']); + } + echo $OUTPUT->single_button(new moodle_url('/mod/assignment/type/upload/upload.php', $param_array), $str, 'get'); } } function view_notes() { global $USER, $OUTPUT; + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } - if ($submission = $this->get_submission($USER->id) - and !empty($submission->data1)) { + if ($submission and !empty($submission->data1)) { echo $OUTPUT->box(format_text($submission->data1, FORMAT_HTML, array('overflowdiv'=>true)), 'generalbox boxaligncenter boxwidthwide'); } else { echo $OUTPUT->box(get_string('notesempty', 'assignment'), 'generalbox boxaligncenter'); @@ -226,8 +271,16 @@ class assignment_upload extends assignme function view_final_submission() { global $CFG, $USER, $OUTPUT; - $submission = $this->get_submission($USER->id); - + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } + if ($this->isopen() and $this->can_finalize($submission)) { //print final submit button echo $OUTPUT->heading(get_string('submitformarking','assignment'), 3); @@ -265,10 +318,22 @@ class assignment_upload extends assignme return ($this->assignment->var3 && (time() <= $this->assignment->timeavailable)); } - function print_student_answer($userid, $return=false){ + function print_student_answer($userid, $return=false, $groupid=0){ global $CFG, $OUTPUT, $PAGE; - $submission = $this->get_submission($userid); + if (!$groupid) { + $groupid = $this->current_group($userid); + } + + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($userid); + } else { + if (! $this->group_assignment_participant($userid, $this->course->id)) { + $submission = $this->get_submission($userid); + } else { + $submission = $this->get_submission($userid, false, false, $groupid, true); + } + } $output = ''; @@ -286,10 +351,11 @@ class assignment_upload extends assignme $renderer = $PAGE->get_renderer('mod_assignment'); - $output = $OUTPUT->box_start('files').$output; - $output .= $renderer->assignment_files($this->context, $submission->id); - $output .= $OUTPUT->box_end(); - + if ($submission) { + $output = $OUTPUT->box_start('files').$output; + $output .= $renderer->assignment_files($this->context, $submission->id); + $output .= $OUTPUT->box_end(); + } return $output; } @@ -301,7 +367,7 @@ class assignment_upload extends assignme * @param $return boolean optional defaults to false. If true the list is returned rather than printed * @return string optional */ - function print_user_files($userid=0, $return=false) { + function print_user_files($userid=0, $return=false, $groupid=0) { global $CFG, $USER, $OUTPUT, $PAGE; $mode = optional_param('mode', '', PARAM_ALPHA); @@ -314,9 +380,19 @@ class assignment_upload extends assignme $userid = $USER->id; } + if (!$groupid) { + $groupid = $this->current_group($userid); + } + $output = $OUTPUT->box_start('files'); - $submission = $this->get_submission($userid); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($userid); + } else { + // We ALWAYS show the group's files in a group submission, instead of the individual user's files + // because the user doesn't have any files... + $submission = $this->get_submission($userid, false, false, $groupid, true); + } // only during grading if ($this->drafts_tracked() and $this->isopen() and !$this->is_finalized($submission) and !empty($mode)) { @@ -393,7 +469,16 @@ class assignment_upload extends assignme $fs = get_file_storage(); $browser = get_file_browser(); - if ($submission = $this->get_submission($userid)) { + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } + if ($submission) { $renderer = $PAGE->get_renderer('mod_assignment'); $output .= $renderer->assignment_files($this->context, $submission->id, 'response'); } @@ -449,7 +534,16 @@ class assignment_upload extends assignme $defaults = new stdClass(); $defaults->id = $this->cm->id; - if ($submission = $this->get_submission($USER->id)) { + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } + if ($submission) { $defaults->text = clean_text($submission->data1); } else { $defaults->text = ''; @@ -471,7 +565,11 @@ class assignment_upload extends assignme } if ($data = $mform->get_data() and $action == 'savenotes') { - $submission = $this->get_submission($USER->id, true); // get or create submission + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id, true); + } else { + $submission = $this->get_submission($USER->id, true, false, $this->current_group(), true); + } $updated = new stdClass(); $updated->id = $submission->id; $updated->timemodified = time(); @@ -480,7 +578,15 @@ class assignment_upload extends assignme $DB->update_record('assignment_submissions', $updated); add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); redirect($returnurl); - $submission = $this->get_submission($USER->id); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } $this->update_grade($submission); } @@ -506,7 +612,11 @@ class assignment_upload extends assignme if ($formdata = $mform->get_data() and $this->can_manage_responsefiles()) { $fs = get_file_storage(); - $submission = $this->get_submission($userid, true, true); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id, true, true); + } else { + $submission = $this->get_submission($USER->id, true, true, $this->current_group(), true); + } if ($formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $this->context, 'mod_assignment', 'response', $submission->id)) { $returnurl = new moodle_url("/mod/assignment/submissions.php", array('id'=>$this->cm->id,'userid'=>$formdata->userid,'mode'=>$formdata->mode,'offset'=>$formdata->offset)); redirect($returnurl->out(false)); @@ -524,8 +634,16 @@ class assignment_upload extends assignme global $CFG, $USER, $DB, $OUTPUT; $returnurl = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id)); - $submission = $this->get_submission($USER->id); - $filecount = $this->count_user_files($submission->id); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } + $filecount = $this->count_user_files($submission->id); if (!$this->can_upload_file($submission)) { $this->view_header(get_string('upload')); @@ -537,7 +655,11 @@ class assignment_upload extends assignme if ($formdata = $mform->get_data()) { $fs = get_file_storage(); - $submission = $this->get_submission($USER->id, true); //create new submission if needed + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id, true); + } else { + $submission = $this->get_submission($USER->id, true, false, $this->current_group(), true); + } $fs->delete_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id); $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $this->context, 'mod_assignment', 'submission', $submission->id); $updates = new stdClass(); @@ -588,7 +710,11 @@ class assignment_upload extends assignme return false; } - if ($USER->id != $submission->userid and !has_capability('mod/assignment:grade', $this->context)) { + if ((!$this->assignment->groupassignment) and ($USER->id != $submission->userid) and ((!has_capability('mod/assignment:grade', $this->context)))) { + return false; + } + + if (($this->assignment->groupassignment) and ($submission->groupid != $this->current_group()) and (!has_capability('mod/assignment:grade', $this->context))) { return false; } @@ -631,7 +757,15 @@ class assignment_upload extends assignme $offset = optional_param('offset', 0, PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_BOOL); $returnurl = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id)); - $submission = $this->get_submission($userid); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } if ($forcemode!=null) { $returnurl = new moodle_url('/mod/assignment/submissions.php', @@ -665,7 +799,13 @@ class assignment_upload extends assignme $DB->update_record('assignment_submissions', $updated); add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finalize action to log 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); - $submission = $this->get_submission($userid); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $submission = $this->get_submission($USER->id)) { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } $this->update_grade($submission); $this->email_teachers($submission); @@ -692,7 +832,11 @@ class assignment_upload extends assignme $returnurl = new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id, 'userid'=>$userid, 'mode'=>$mode, 'offset'=>$offset, 'forcerefresh'=>1)); // create but do not add student submission date - $submission = $this->get_submission($userid, true, true); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id, true, true); + } else { + $submission = $this->get_submission($USER->id, true, true, $this->current_group(), true); + } if (!data_submitted() or !$this->can_finalize($submission) or !confirm_sesskey()) { redirect($returnurl); // probably closed already @@ -705,7 +849,13 @@ class assignment_upload extends assignme $DB->update_record('assignment_submissions', $updated); add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finalize action to log 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); - $submission = $this->get_submission($userid, false, true); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id, false, true); + } else { + if (! $submission = $this->get_submission($USER->id, false, true)) { + $submission = $this->get_submission($USER->id, false, true, $this->current_group(), true); + } + } $this->update_grade($submission); redirect($returnurl); } @@ -721,8 +871,18 @@ class assignment_upload extends assignme $mode=$forcemode; } $returnurl = new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id, 'userid'=>$userid, 'mode'=>$mode, 'offset'=>$offset, 'forcerefresh'=>1) ); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } + if (data_submitted() - and $submission = $this->get_submission($userid) + and $submission and $this->can_unfinalize($submission) and confirm_sesskey()) { @@ -732,7 +892,15 @@ class assignment_upload extends assignme $DB->update_record('assignment_submissions', $updated); //TODO: add unfinalize action to log add_to_log($this->course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->assignment->id, $this->assignment->id, $this->cm->id); - $submission = $this->get_submission($userid); + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } $this->update_grade($submission); } @@ -784,7 +952,16 @@ class assignment_upload extends assignme die; } - if ($submission = $this->get_submission($userid)) { + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } + if ($submission) { $fs = get_file_storage(); if ($file = $fs->get_file($this->context->id, 'mod_assignment', 'response', $submission->id, '/', $file)) { $file->delete(); @@ -815,7 +992,16 @@ class assignment_upload extends assignme $returnurl = new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id, 'offset'=>$offset, 'userid'=>$userid)); } - if (!$submission = $this->get_submission($userid) // incorrect submission + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } + if (!$submission // incorrect submission or !$this->can_delete_files($submission)) { // can not delete $this->view_header(get_string('delete')); echo $OUTPUT->notification(get_string('cannotdeletefiles', 'assignment')); @@ -860,7 +1046,8 @@ class assignment_upload extends assignme if (is_enrolled($this->context, $USER, 'mod/assignment:submit') and $this->isopen() // assignment not closed yet - and (empty($submission) or ($submission->userid == $USER->id)) // his/her own submission + and (empty($submission) + or (($submission->userid == $USER->id) or ($submission->groupid == $this->current_group()))) // submission is individual or a team submission and !$this->is_finalized($submission)) { // no uploading after final submission return true; } else { @@ -886,7 +1073,8 @@ class assignment_upload extends assignme if (is_enrolled($this->context, $USER, 'mod/assignment:submit') and $this->isopen() // assignment not closed yet and $this->assignment->resubmit // deleting allowed - and $USER->id == $submission->userid // his/her own submission + and (((!$this->assignment->groupassignment) and ($submission->userid == $USER->id)) // his/her own submission + or (($this->assignment->groupassignment) and ($submission->groupid == $this->current_group()))) // own team submission and !$this->is_finalized($submission)) { // no deleting after final submission return true; } else { @@ -947,7 +1135,8 @@ class assignment_upload extends assignme } else if (is_enrolled($this->context, $USER, 'mod/assignment:submit') and $this->isopen() // assignment not closed yet and !empty($submission) // submission must exist - and $submission->userid == $USER->id // his/her own submission + and (((!$this->assignment->groupassignment) and ($submission->userid == $USER->id)) // his/her own submission + or (($this->assignment->groupassignment) and ($submission->groupid == $this->current_group()))) // own team submission and ($this->count_user_files($submission->id) or ($this->notes_allowed() and !empty($submission->data1)))) { // something must be submitted @@ -963,7 +1152,9 @@ class assignment_upload extends assignme if (is_enrolled($this->context, $USER, 'mod/assignment:submit') and $this->notes_allowed() // notesd must be allowed and $this->isopen() // assignment not closed yet - and (empty($submission) or $USER->id == $submission->userid) // his/her own submission + and (empty($submission) + or (((!$this->assignment->groupassignment) and ($submission->userid == $USER->id)) // his/her own submission + or (($this->assignment->groupassignment) and ($submission->groupid == $this->current_group())))) // own team submission and !$this->is_finalized($submission)) { // no updateingafter final submission return true; } else { @@ -975,8 +1166,34 @@ class assignment_upload extends assignme return (boolean)$this->assignment->var2; } + function current_group($userid=null) { + global $USER; + if (!$userid) { + $userid = $USER->id; + } + + $usergroups = groups_get_user_groups($this->course->id, $userid); + + if (isset($_GET['group'])) { + if (in_array($_GET['group'], $usergroups[0])) { + return $_GET['group']; + } + } + foreach ($usergroups[0] as $primarygroup) { + return $primarygroup; + } + return null; + } + function count_responsefiles($userid) { - if ($submission = $this->get_submission($userid)) { + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($userid); + } else { + if (! $submission = $this->get_submission($userid)) { + $submission = $this->get_submission($userid, false, false, $this->current_group(), true); + } + } + if ($submission) { $fs = get_file_storage(); $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'response', $submission->id, "id", false); return count($files); @@ -1003,6 +1220,11 @@ class assignment_upload extends assignme for($i = 1; $i <= 20; $i++) { $options[$i] = $i; } + $mform->addElement('select', 'groupassignment', get_string('isgroupassignment', 'assignment'), $ynoptions); + $mform->addHelpButton('groupassignment', 'isgroupassignment', 'assignment'); + $mform->setDefault('groupassignment', 0); + $mform->disabledIf('groupassignment', 'groupmode', 'eq', 0); + $mform->addElement('select', 'var1', get_string('allowmaxfiles', 'assignment'), $options); $mform->addHelpButton('var1', 'allowmaxfiles', 'assignment'); $mform->setDefault('var1', 3); @@ -1034,8 +1256,16 @@ class assignment_upload extends assignme function extend_settings_navigation($node) { global $CFG, $USER, $OUTPUT; - // get users submission if there is one - $submission = $this->get_submission(); + // get users (or group) submission if there is one + if (! $this->assignment->groupassignment) { + $submission = $this->get_submission($USER->id); + } else { + if (! $this->group_assignment_participant($USER->id, $this->course->id)) { + $submission = $this->get_submission($USER->id); + } else { + $submission = $this->get_submission($USER->id, false, false, $this->current_group(), true); + } + } if (is_enrolled($this->context, $USER, 'mod/assignment:submit')) { $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked); } else { @@ -1116,7 +1346,17 @@ class assignment_upload extends assignme //get files new name. $fileext = strstr($file->get_filename(), '.'); $fileoriginal = str_replace($fileext, '', $file->get_filename()); - $fileforzipname = clean_filename(fullname($a_user) . "_" . $fileoriginal."_".$a_userid.$fileext); + if (! $this->assignment->groupassignment) { + $fileforzipname = clean_filename(fullname($a_user) . "_" . $fileoriginal."_".$a_userid.$fileext); + } else { + if (! $this->group_assignment_participant($a_userid, $this->course->id)) { + $fileforzipname = clean_filename(fullname($a_user) . "_" . $fileoriginal."_".$a_userid.$fileext); + } else { + $fileforzipname = clean_filename(groups_get_group_name($submission->groupid) . "_" . $fileoriginal . "_" . $a_userid.$fileext); + //Code for group filename + } + } + //save file name to array for zipping. $filesforzipping[$fileforzipname] = $file; } --- mod/assignment/type/upload/upload.php 2010-09-21 10:32:19.000000000 -0700 +++ mod/assignment/type/upload/upload.php 2011-04-05 13:49:07.000000000 -0700 @@ -57,7 +57,11 @@ $PAGE->set_title($title); $PAGE->set_heading($title); $instance = new assignment_upload($cm->id, $assignment, $cm, $course); -$submission = $instance->get_submission($formdata->userid, true); +if (! $instance->assignment->groupassignment) { + $submission = $instance->get_submission($formdata->userid, true); +} else { + $submission = $instance->get_submission($formdata->userid, true, false, $instance->current_group(), true); +} $filemanager_options = array('subdirs'=>1, 'maxbytes'=>$assignment->maxbytes, 'maxfiles'=>$assignment->var1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL); --- mod/assignment/version.php 2010-10-26 17:01:42.000000000 -0700 +++ mod/assignment/version.php 2011-04-05 14:16:34.000000000 -0700 @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2010102600; +$module->version = 2011040500; $module->requires = 2010102600; // Requires this Moodle version $module->cron = 60;