Skip to content

Commit

Permalink
MDL-49852 mod_assign: Fix group assignment completion tracking
Browse files Browse the repository at this point in the history
Fixes completion tracking for group assignments where either only
one student is required to click Submit when submitting the
assignment for grading, all students are required to submit,
or no students are required to click submit (meaning that simply
uploading submits for grading).
  • Loading branch information
smbader authored and abgreeve committed May 26, 2016
1 parent 2c952b2 commit 9569b01
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
6 changes: 5 additions & 1 deletion mod/assign/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,11 @@ function assign_get_completion_state($course, $cm, $userid, $type) {

// If completion option is enabled, evaluate it and return true/false.
if ($assign->get_instance()->completionsubmit) {
$submission = $assign->get_user_submission($userid, false);
if ($assign->get_instance()->teamsubmission) {
$submission = $assign->get_group_submission($userid, 0, false);
} else {
$submission = $assign->get_user_submission($userid, false);
}
return $submission && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED;
} else {
// Completion option is not enabled so just return $type.
Expand Down
50 changes: 48 additions & 2 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5633,7 +5633,12 @@ public function submit_for_grading($data, $notices) {
$this->update_submission($submission, $userid, true, $instance->teamsubmission);
$completion = new completion_info($this->get_course());
if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) {
$completion->update_state($this->get_course_module(), COMPLETION_COMPLETE, $userid);
$this->update_activity_completion_records($instance->teamsubmission,
$instance->requireallteammemberssubmit,
$submission,
$userid,
COMPLETION_COMPLETE,
$completion);
}

if (!empty($data->submissionstatement) && $USER->id == $userid) {
Expand Down Expand Up @@ -6325,7 +6330,12 @@ public function copy_previous_attempt(&$notices) {
}
$completion = new completion_info($this->get_course());
if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) {
$completion->update_state($this->get_course_module(), $complete, $USER->id);
$this->update_activity_completion_records($instance->teamsubmission,
$instance->requireallteammemberssubmit,
$submission,
$USER->id,
$complete,
$completion);
}

if (!$instance->submissiondrafts) {
Expand Down Expand Up @@ -7991,6 +8001,42 @@ public function get_useridlist_key($id = null) {
}
return $this->get_course_module()->id . '_' . $id;
}

/**
* Updates and creates the completion records in mdl_course_modules_completion.
*
* @param int $teamsubmission value of 0 or 1 to indicate whether this is a group activity
* @param int $requireallteammemberssubmit value of 0 or 1 to indicate whether all group members must click Submit
* @param obj $submission the submission
* @param int $userid the user id
* @param int $complete
* @param obj $completion
*
* @return null
*/
protected function update_activity_completion_records($teamsubmission,
$requireallteammemberssubmit,
$submission,
$userid,
$complete,
$completion) {

if (($teamsubmission && $submission->groupid > 0 && !$requireallteammemberssubmit) ||
($teamsubmission && $submission->groupid > 0 && $requireallteammemberssubmit &&
$submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED)) {

$members = groups_get_members($submission->groupid);

foreach ($members as $member) {
$completion->update_state($this->get_course_module(), $complete, $member->id);
}
} else {
$completion->update_state($this->get_course_module(), $complete, $userid);
}

return;
}

}

/**
Expand Down

0 comments on commit 9569b01

Please sign in to comment.