MDL-65116 mod_assign : Assignment due date does not update for groups.
authorJohn Yao <johnyao@catalyst-au.net>
Mon, 17 Jun 2019 04:04:04 +0000 (14:04 +1000)
committerJohn Yao <johnyao@catalyst-au.net>
Fri, 23 Aug 2019 03:08:53 +0000 (13:08 +1000)
This commit fixes the assignment due date not showing correctly according to groups selected by users who can view grades

mod/assign/locallib.php
mod/assign/tests/locallib_test.php

index 8850123..0929b1f 100644 (file)
@@ -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).
      *
index bb694a7..29bd4b5 100644 (file)
@@ -4157,4 +4157,73 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
             ],
         ];
     }
+
+    /**
+     * 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);
+    }
 }