Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter course IDs associated with a given teacher #7702

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/fix-co-teachers-get-students
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Filter course IDs associated with a given teacher
donnapep marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 13 additions & 1 deletion includes/class-sensei-teacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,19 @@ public function filter_learners_query( $learners_sql ) {
return $learners_sql;
}

$teacher_course_ids = $this->get_teacher_courses( get_current_user_id(), true );
/**
* Filter the course IDs associated with a given teacher.
*
* @since $$next-version$$
*
* @hook sensei_teacher_course_ids
*
* @param {int[]} $course_ids Course IDs for which the current user is the teacher.
* @param {int} $teacher_id Teacher ID.
* @return {int[]} Filtered course IDs associated with a given teacher.
*/
$teacher_course_ids = apply_filters( 'sensei_teacher_course_ids', $this->get_teacher_courses( get_current_user_id(), true ), get_current_user_id() );

if ( ! $teacher_course_ids ) {
$teacher_course_ids = [ 0 ]; // Show no learners.
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests/test-class-teacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public function testUpdateCourseLessonsAuthor_WhenLessonsAreInDraftStatus_GetAut
$this->assertPostAuthor( $new_teacher_id, $course['lesson_ids'], 'All lessons must be from teacher B now' );
}

public function testFilterLearnersQuery_WhenUserIsNoATeacher_ReturnsSameInput() {
public function testFilterLearnersQuery_WhenUserIsNotATeacher_ReturnsSameInput() {
// Arrange.
set_current_screen( 'sensei-lms_page_sensei_learners' ); // Pretend we're on the students admin screen.

Expand Down
Loading