Skip to content

Commit ffe7f75

Browse files
IDzyrebmcutler
andauthored
[Bugfix:InstructorUI] Notify on Self Registration (Submitty#11451)
### What is the current behavior? Currently all instructors in Submitty are receiving emails when a user self registers for a course. This is because the function used is just getting all of a certain type of user. Closes Submitty#11434 ### What is the new behavior? This function has two more parameters added, allowing for the ability to specify if you want that group for a specific course and term. ### Other information? This changes the SelfRejoin function as well, as that is supposed to notify the instructors of that given course, not all instructors of Submitty. The original use of this function remains unchanged, as `term` and `course` are optional parameters, and the query defaults to being the same query as before. --------- Co-authored-by: Barb Cutler <[email protected]>
1 parent b302da5 commit ffe7f75

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

site/app/controllers/SelfRejoinController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private function sendRejoinedStudentEmail($joined_section): void {
215215
you may move the student to the Null section.
216216
EMAIL;
217217

218-
$instructor_ids = $this->core->getQueries()->getActiveUserIds(true, false, false, false, false);
218+
$instructor_ids = $this->core->getQueries()->getActiveUserIds(true, false, false, false, false, $term, $course);
219219
$emails = [];
220220
$details = ["subject" => $subject, "body" => $body];
221221
foreach ($instructor_ids as $instructor_id) {

site/app/controllers/course/CourseRegistrationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function registerCourseUser(string $term, string $course): void {
4848
$default_section = $this->core->getQueries()->getDefaultRegistrationSection($term, $course);
4949
$this->core->getUser()->setRegistrationSection($default_section);
5050
$this->core->getQueries()->insertCourseUser($this->core->getUser(), $term, $course);
51-
$instructor_ids = $this->core->getQueries()->getActiveUserIds(true, false, false, false, false);
51+
$instructor_ids = $this->core->getQueries()->getActiveUserIds(true, false, false, false, false, $term, $course);
5252
$this->notifyInstructors($this->core->getUser()->getId(), $term, $course, $instructor_ids);
5353
}
5454
}

site/app/libraries/database/DatabaseQueries.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ public function getGroupForUserInClass($semester, $course_name, $user_id) {
11471147
* @param bool $faculty to include faculty level users or not
11481148
* @return array - array of userids active in the specified semester
11491149
*/
1150-
public function getActiveUserIds(bool $instructor, bool $fullAccess, bool $limitedAccess, bool $student, bool $faculty): array {
1150+
public function getActiveUserIds(bool $instructor, bool $fullAccess, bool $limitedAccess, bool $student, bool $faculty, ?string $term = null, ?string $course = null): array {
11511151
$args = ['-1'];
11521152
$extra_join = '';
11531153
$extra_where = '';
@@ -1168,13 +1168,20 @@ public function getActiveUserIds(bool $instructor, bool $fullAccess, bool $limit
11681168
$extra_join = ' INNER JOIN users ON courses_users.user_id = users.user_id ';
11691169
$extra_where = ' OR users.user_access_level <= 2';
11701170
}
1171+
$on_phrase = ' ON courses_users.term = courses.term AND courses_users.course = courses.course ';
1172+
$parameters = $args;
1173+
if ($term !== null && $course !== null) {
1174+
$parameters = [$term, $course];
1175+
$parameters = array_merge($parameters, $args);
1176+
$on_phrase = ' ON courses_users.term = ? AND courses_users.course = ? ';
1177+
}
11711178
$result_rows = [];
11721179
$this->submitty_db->query(
11731180
"SELECT DISTINCT courses_users.user_id as user_id
11741181
FROM courses_users INNER JOIN courses
1175-
ON courses_users.term = courses.term AND courses_users.course = courses.course
1176-
" . $extra_join . "
1177-
WHERE courses.status = 1 AND user_group IN (" . implode(', ', $args) . ")" . $extra_where
1182+
" . $on_phrase . $extra_join . "
1183+
WHERE courses.status = 1 AND user_group IN " . $this->createParameterList(count($args)) . $extra_where,
1184+
$parameters
11781185
);
11791186
return array_map(
11801187
function ($row) {

0 commit comments

Comments
 (0)