Skip to content

Commit

Permalink
MDL-65116 mod_assign : Assignment due date does not update for groups.
Browse files Browse the repository at this point in the history
This commit fixes the assignment due date not showing correctly according to groups selected by users who can view grades
  • Loading branch information
John Yao committed Aug 23, 2019
1 parent 7e16c70 commit 62f1640
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
26 changes: 24 additions & 2 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5592,7 +5592,7 @@ public function get_assign_grading_summary_renderable($activitygroup = null) {
$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,
Expand All @@ -5612,7 +5612,7 @@ public function get_assign_grading_summary_renderable($activitygroup = null) {
$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,
Expand All @@ -5627,6 +5627,28 @@ public function get_assign_grading_summary_renderable($activitygroup = null) {
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).
*
Expand Down
69 changes: 69 additions & 0 deletions mod/assign/tests/locallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4157,4 +4157,73 @@ public function assign_get_default_instance_provider() {
],
];
}

/**
* 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);
}
}

0 comments on commit 62f1640

Please sign in to comment.