From c1bce8b4c77318281a4faf05cb9a9d5c57132a9b Mon Sep 17 00:00:00 2001 From: Adrian Perez Date: Wed, 6 Nov 2019 10:56:56 +0100 Subject: [PATCH] MDL-67126 assign: set completion state for all group members --- mod/assign/locallib.php | 17 ++++++++----- mod/assign/tests/locallib_test.php | 39 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 34f23e92176..4b50121a4b5 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -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) { diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index 33d9751207b..31c65ac483e 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -3785,6 +3785,45 @@ Anchor link 2:Link text $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