MDL-67126 assign: set completion state for all group members

This commit is contained in:
Adrian Perez 2019-11-06 10:56:56 +01:00
parent d85118369d
commit c1bce8b4c7
2 changed files with 50 additions and 6 deletions

View File

@ -7422,6 +7422,7 @@ class assign {
}
$this->update_submission($submission, $userid, true, $instance->teamsubmission);
$users = [$userid];
if ($instance->teamsubmission && !$instance->requireallteammemberssubmit) {
$team = $this->get_submission_group_members($submission->groupid, true);
@ -7430,22 +7431,26 @@ class assign {
if ($member->id != $userid) {
$membersubmission = clone($submission);
$this->update_submission($membersubmission, $member->id, true, $instance->teamsubmission);
$users[] = $member->id;
}
}
}
// Logging.
if (isset($data->submissionstatement) && ($userid == $USER->id)) {
\mod_assign\event\statement_accepted::create_from_submission($this, $submission)->trigger();
}
$complete = COMPLETION_INCOMPLETE;
if ($submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
$complete = COMPLETION_COMPLETE;
}
$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, $userid);
foreach ($users as $id) {
$completion->update_state($this->get_course_module(), $complete, $id);
}
}
// Logging.
if (isset($data->submissionstatement) && ($userid == $USER->id)) {
\mod_assign\event\statement_accepted::create_from_submission($this, $submission)->trigger();
}
if (!$instance->submissiondrafts) {

View File

@ -3785,6 +3785,45 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
$this->assertEquals(1, $completiondata->completionstate);
}
/**
* Test updating activity completion when submitting an assessment for MDL-67126.
*/
public function test_update_activity_completion_records_team_submission_new() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]);
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$otherstudent = $this->getDataGenerator()->create_and_enrol($course, 'student');
$grouping = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
$group1 = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
groups_add_member($group1, $student);
groups_add_member($group1, $otherstudent);
$assign = $this->create_instance($course, [
'submissiondrafts' => 0,
'completion' => COMPLETION_TRACKING_AUTOMATIC,
'completionsubmit' => 1,
'teamsubmission' => 1,
'assignsubmission_onlinetext_enabled' => 1
]);
$cm = $assign->get_course_module();
$this->add_submission($student, $assign);
$completion = new completion_info($course);
// Completion should now be met.
$completiondata = $completion->get_data($cm, false, $student->id);
$this->assertEquals(1, $completiondata->completionstate);
$completiondata = $completion->get_data($cm, false, $otherstudent->id);
$this->assertEquals(1, $completiondata->completionstate);
}
/**
* Data provider for test_fix_null_grades
* @return array[] Test data for test_fix_null_grades. Each element should contain grade, expectedcount and gradebookvalue