From 8762a70f5d8ceb2c2601b781c4077c5f2f150669 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Thu, 12 Dec 2013 13:29:41 +0800 Subject: [PATCH] MDL-43250 Assign: separate groups mode fix When in separate groups mode, only get graders in a group that is in the course module grouping. --- mod/assign/locallib.php | 2 +- mod/assign/tests/locallib_test.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index ab356ada5a5..e094709777d 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -3955,7 +3955,7 @@ class assign { $graders = array(); if (groups_get_activity_groupmode($this->get_course_module()) == SEPARATEGROUPS) { - if ($groups = groups_get_all_groups($this->get_course()->id, $userid)) { + if ($groups = groups_get_all_groups($this->get_course()->id, $userid, $this->get_course_module()->groupingid)) { foreach ($groups as $group) { foreach ($potentialgraders as $grader) { if ($grader->id == $userid) { diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index 6cfbfedd480..638aab159b6 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -609,27 +609,37 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase { public function test_get_graders() { $this->create_extra_users(); $this->setUser($this->editingteachers[0]); - $assign = $this->create_instance(); + // Create an assignment with no groups. + $assign = $this->create_instance(); $this->assertCount(self::DEFAULT_TEACHER_COUNT + self::DEFAULT_EDITING_TEACHER_COUNT + self::EXTRA_TEACHER_COUNT + self::EXTRA_EDITING_TEACHER_COUNT, $assign->testable_get_graders($this->students[0]->id)); - $assign = $this->create_instance(); // Force create an assignment with SEPARATEGROUPS. + $data = new stdClass(); + $data->courseid = $this->course->id; + $data->name = 'Grouping'; + $groupingid = groups_create_grouping($data); + groups_assign_grouping($groupingid, $this->groups[0]->id); + $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign'); $params = array('course'=>$this->course->id); $instance = $generator->create_instance($params); $cm = get_coursemodule_from_instance('assign', $instance->id); set_coursemodule_groupmode($cm->id, SEPARATEGROUPS); $cm->groupmode = SEPARATEGROUPS; + $cm->groupingid = $groupingid; $context = context_module::instance($cm->id); $assign = new testable_assign($context, $cm, $this->course); $this->setUser($this->students[1]); $this->assertCount(4, $assign->testable_get_graders($this->students[0]->id)); + // Note the second student is in a group that is not in the grouping. + // This means that we get all graders that are not in a group in the grouping. + $this->assertCount(10, $assign->testable_get_graders($this->students[1]->id)); } public function test_group_members_only() {