diff --git a/classes/models/coursework.php b/classes/models/coursework.php index e06a8bf..7e8ecc1 100644 --- a/classes/models/coursework.php +++ b/classes/models/coursework.php @@ -1706,14 +1706,14 @@ public function get_student_group($student) { if ($this->grouping_id) { $sql = " - SELECT groups.* - FROM {groups} groups + SELECT g.* + FROM {groups} g INNER JOIN {groupings_groups} groupings - ON groups.id = groupings.groupid + ON g.id = groupings.groupid INNER JOIN {groups_members} gm - ON gm.groupid = groups.id + ON gm.groupid = g.id WHERE gm.userid = :userid - AND groups.courseid = :courseid + AND g.courseid = :courseid AND groupings.groupingid = :grouping_id LIMIT 1 @@ -1724,20 +1724,18 @@ public function get_student_group($student) { 'userid' => $student->id()]; } else { $sql = " - SELECT groups.* - FROM {groups} groups + SELECT g.* + FROM {groups} g INNER JOIN {groups_members} gm - ON gm.groupid = groups.id + ON gm.groupid = g.id WHERE gm.userid = :userid - AND groups.courseid = :courseid - LIMIT 1 - "; + AND g.courseid = :courseid + LIMIT 1"; $params = [ 'userid' => $student->id(), 'courseid' => $this->get_course()->id, ]; } - $group = $DB->get_record_sql($sql, $params); return group::find($group); @@ -2264,11 +2262,11 @@ public function get_allocatables() { if ($this->is_configured_to_have_group_submissions()) { if ($this->grouping_id) { $sql = " - SELECT groups.* - FROM {groups} groups + SELECT g.* + FROM {groups} g INNER JOIN {groupings_groups} groupings - ON groups.id = groupings.groupid - WHERE groups.courseid = :courseid + ON g.id = groupings.groupid + WHERE g.courseid = :courseid AND groupings.groupingid = :grouping_id "; $params = [ @@ -2276,11 +2274,7 @@ public function get_allocatables() { 'courseid' => $this->get_course()->id, ]; } else { - $sql = " - SELECT groups.* - FROM {groups} groups - WHERE groups.courseid = :courseid - "; + $sql = "SELECT * FROM {groups} WHERE courseid = :courseid"; $params = [ 'courseid' => $this->get_course()->id, ]; diff --git a/classes/warnings.php b/classes/warnings.php index 9a275e0..51aacfa 100644 --- a/classes/warnings.php +++ b/classes/warnings.php @@ -87,14 +87,14 @@ public function students_in_mutiple_grouos() { groupings.groupingid, u.firstname, u.lastname - FROM {groups} groups + FROM {groups} g INNER JOIN {groups_members} gm - ON groups.id = gm.groupid + ON g.id = gm.groupid INNER JOIN {groupings_groups} groupings - ON groups.id=groupings.groupid + ON g.id=groupings.groupid INNER JOIN {user} u ON u.id = gm.userid - WHERE groups.courseid = :courseid + WHERE g.courseid = :courseid AND groupings.groupingid = :groupingid GROUP BY gm.userid, groupings.groupingid, u.firstname, u.lastname)a WHERE noofgroups > 1"; @@ -107,12 +107,12 @@ public function students_in_mutiple_grouos() { count(gm.userid) as noofgroups, u.firstname, u.lastname - FROM {groups} groups + FROM {groups} g INNER JOIN {groups_members} gm - ON gm.groupid = groups.id + ON gm.groupid = g.id INNER JOIN {user} u ON u.id = gm.userid - WHERE groups.courseid = :courseid + WHERE g.courseid = :courseid GROUP BY gm.userid, u.firstname, u.lastname) a WHERE noofgroups > 1"; @@ -132,13 +132,13 @@ public function students_in_mutiple_grouos() { // Get group ids of these students if ($this->coursework->grouping_id) { - $sql = "SELECT groups.id,groups.name - FROM {groups} groups + $sql = "SELECT g.id, g.name + FROM {groups} g INNER JOIN {groupings_groups} groupings - ON groups.id = groupings.groupid + ON g.id = groupings.groupid INNER JOIN {groups_members} gm - ON gm.groupid = groups.id - WHERE groups.courseid = :courseid + ON gm.groupid = g.id + WHERE g.courseid = :courseid AND gm.userid = :userid AND groupings.groupingid =:grouping_id"; @@ -148,11 +148,11 @@ public function students_in_mutiple_grouos() { 'userid' => $student->userid]; } else { - $sql = "SELECT groups.id,groups.name - FROM {groups} groups + $sql = "SELECT g.id, g.name + FROM {groups} g INNER JOIN {groups_members} gm - ON gm.groupid = groups.id - WHERE groups.courseid = :courseid + ON gm.groupid = g.id + WHERE g.courseid = :courseid AND gm.userid = :userid"; $params = [ diff --git a/lib.php b/lib.php index 3f3e735..d754522 100644 --- a/lib.php +++ b/lib.php @@ -371,8 +371,9 @@ function coursework_grade_item_update($coursework, $grades = null) { throw new invalid_parameter_exception("Invalid type '$paramtype' for coursework"); } - if (get_class($coursework) != 'mod_coursework\models\coursework') { - // On activity rename, core will pass in stdClass object here, not a coursework. + if (get_class($coursework) == 'stdClass') { + // On activity rename, core will pass in stdClass object here. + // Otherwise expect coursework or coursework_groups_decorator to be passed. $coursework = \mod_coursework\models\coursework::find($coursework); } diff --git a/tests/behat/behat_mod_coursework.php b/tests/behat/behat_mod_coursework.php index 7b32577..65dd4e1 100644 --- a/tests/behat/behat_mod_coursework.php +++ b/tests/behat/behat_mod_coursework.php @@ -299,17 +299,6 @@ private function get_first_assesor_stage() { return reset($stages); } - /** - * - * - * @param $rolename - * @return string - */ - private function make_role_name_into_variable_name($rolename) { - $rolename = str_replace('other ', 'other_', $rolename); - return str_replace(' ', '', $rolename); - } - /** * Returns an xpath string to find a tag that has a class and contains some text. * @@ -1896,40 +1885,6 @@ public function there_is_some_general_feedback() { $this->get_coursework()->save(); } - /** - * @Given /^(I|the ([\w ]+)) (?:has|have) graded the submission as assessor (\d+)$/ - * - * @param $i - * @param string $rolename - * @param int $assessornumber - * @throws coding_exception - */ - public function the_other_teacher_has_graded_the_submission($i, $rolename = '', $assessornumber = 1) { - - if ($i == 'I') { - $rolename = 'teacher'; - } else { - // other editing teacher => other_editingteacher - $rolename = $this->make_role_name_into_variable_name($rolename); - } - - if (empty($this->$rolename)) { - throw new coding_exception('no ' . $rolename . ' user was found'); - } - - /** - * @var $generator mod_coursework_generator - */ - $generator = testing_util::get_data_generator()->get_plugin_generator('mod_coursework'); - - $feedback = new stdClass(); - $feedback->submissionid = $this->submission->id; - $feedback->assessorid = $this->$rolename->id; - $feedback->stage_identifier = 'assessor_'.$assessornumber; - $feedback->grade = 50; - $generator->create_feedback($feedback); - } - /** * @Then /^I should( not)? see the other teacher\'s grade as assessor (\d+)$/ * @param bool $negate @@ -2756,8 +2711,7 @@ public function i_should_see_that_the_submission_was_made_by_the_other_student($ * @throws coding_exception */ public function i_am_logged_in_as_a($rolename) { - - $rolename = $this->make_role_name_into_variable_name($rolename); + $rolename = str_replace(' ', '', $rolename); if (empty($this->$rolename)) { $this->$rolename = $this->create_user($rolename); @@ -2826,8 +2780,13 @@ protected function create_user($rolename, $displayname = '') { $user = \mod_coursework\models\user::find($user); $user->password = 'user' . $this->usersuffix; - $roleid = $DB->get_field('role', 'id', ['shortname' => $rolename], MUST_EXIST); + // If the role name starts with 'other_' here (e.g. 'other_teacher') we need to remove it. + $rolename = str_replace('other_', '', $rolename); + $roleid = $DB->get_field('role', 'id', ['shortname' => $rolename]); + if (!$roleid) { + throw new coding_exception("Cannot find role shortname '$rolename' in role table"); + } if (empty($this->course)) { throw new coding_exception('Must have a course to enrol the user onto'); }