From 62f1640df2b5a9ecd9631ca46bb6f24e2be3c2ba Mon Sep 17 00:00:00 2001 From: John Yao Date: Mon, 17 Jun 2019 14:04:04 +1000 Subject: [PATCH] MDL-65116 mod_assign : Assignment due date does not update for groups. This commit fixes the assignment due date not showing correctly according to groups selected by users who can view grades --- mod/assign/locallib.php | 26 ++++++++++- mod/assign/tests/locallib_test.php | 69 ++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 8850123d11f..0929b1fc03f 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -5592,7 +5592,7 @@ class assign { $this->is_any_submission_plugin_enabled(), $this->count_submissions_with_status($submitted, $activitygroup), $instance->cutoffdate, - $instance->duedate, + $this->get_duedate($activitygroup), $this->get_course_module()->id, $this->count_submissions_need_grading($activitygroup), $instance->teamsubmission, @@ -5612,7 +5612,7 @@ class assign { $this->is_any_submission_plugin_enabled(), $this->count_submissions_with_status($submitted, $activitygroup), $instance->cutoffdate, - $instance->duedate, + $this->get_duedate($activitygroup), $this->get_course_module()->id, $this->count_submissions_need_grading($activitygroup), $instance->teamsubmission, @@ -5627,6 +5627,28 @@ class assign { return $summary; } + /** + * Return group override duedate. + * + * @param int $activitygroup Activity active group + * @return int $duedate + */ + private function get_duedate($activitygroup = null) { + global $DB; + + if ($activitygroup === null) { + $activitygroup = groups_get_activity_group($this->get_course_module()); + } + if ($this->can_view_grades()) { + $params = array('groupid' => $activitygroup, 'assignid' => $this->get_instance()->id); + $groupoverride = $DB->get_record('assign_overrides', $params); + if (!empty($groupoverride->duedate)) { + return $groupoverride->duedate; + } + } + return $this->get_instance()->duedate; + } + /** * View submissions page (contains details of current submission). * diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index bb694a793de..29bd4b5a406 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -4157,4 +4157,73 @@ Anchor link 2:Link text ], ]; } + + /** + * Test showing group override duedate for admin + */ + public function test_view_group_override() { + global $DB, $PAGE; + + $this->resetAfterTest(); + $course = $this->getDataGenerator()->create_course(); + + $group1 = $this->getDataGenerator()->create_group(['courseid' => $course->id]); + $group2 = $this->getDataGenerator()->create_group(['courseid' => $course->id]); + + $student1 = $this->getDataGenerator()->create_and_enrol($course, 'student'); + $teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher'); + groups_add_member($group1, $student1); + groups_add_member($group1, $teacher); + + $student2 = $this->getDataGenerator()->create_and_enrol($course, 'student'); + groups_add_member($group2, $student2); + + $assign = $this->create_instance($course, [ + 'groupmode' => 1, + 'duedate' => 1558999899, + ]); + $instance = $assign->get_instance(); + + // Overrides for two groups. + $overrides = [ + (object) [ + 'assignid' => $instance->id, + 'groupid' => $group1->id, + 'userid' => null, + 'sortorder' => 1, + 'duedate' => 1568990258, + ], + (object) [ + 'assignid' => $instance->id, + 'groupid' => $group2->id, + 'userid' => null, + 'sortorder' => 2, + 'duedate' => 1559900258, + ], + ]; + + foreach ($overrides as &$override) { + $override->id = $DB->insert_record('assign_overrides', $override); + } + + $currenturl = new moodle_url('/mod/assign/view.php', array('id' => $assign->get_course_module()->id)); + $PAGE->set_url($currenturl); + $output1 = ''; + // Other users should see duedate of the assignment. + $this->setUser($student2); + $summary = $assign->get_assign_grading_summary_renderable($group1->id); + $output1 .= $assign->get_renderer()->render($summary); + $this->assertContains('Tuesday, 28 May 2019, 7:31 AM', $output1); + + $output2 = ''; + // Teacher should be able to see all group override duedate. + $this->setUser($teacher); + $summary = $assign->get_assign_grading_summary_renderable($group1->id); + $output2 .= $assign->get_renderer()->render($summary); + $this->assertContains('Friday, 20 September 2019, 10:37 PM', $output2); + $summary = $assign->get_assign_grading_summary_renderable($group2->id); + $output3 = ''; + $output3 .= $assign->get_renderer()->render($summary); + $this->assertContains('Friday, 7 June 2019, 5:37 PM', $output3); + } }