From ddb5438f9157e1bf377d869bbea01be48a38e6d6 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Mon, 4 Nov 2024 15:12:41 -0500 Subject: [PATCH 1/4] Add filter for course IDs associated with a given teacher --- includes/class-sensei-teacher.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/includes/class-sensei-teacher.php b/includes/class-sensei-teacher.php index f07bd33d5e..5db0c1cc3a 100755 --- a/includes/class-sensei-teacher.php +++ b/includes/class-sensei-teacher.php @@ -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. } From 2484f49161cfb4a4fb577f82a5a3e7e53b8d7f08 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Mon, 4 Nov 2024 15:13:03 -0500 Subject: [PATCH 2/4] Fix test name --- tests/unit-tests/test-class-teacher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit-tests/test-class-teacher.php b/tests/unit-tests/test-class-teacher.php index a10f2a6d7b..ade4e2e1dc 100644 --- a/tests/unit-tests/test-class-teacher.php +++ b/tests/unit-tests/test-class-teacher.php @@ -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. From a0deadb9066dd38117b288037b9c2c7e45ce8105 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Mon, 4 Nov 2024 16:12:46 -0500 Subject: [PATCH 3/4] Add change log entry --- changelog/fix-co-teachers-get-students | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/fix-co-teachers-get-students diff --git a/changelog/fix-co-teachers-get-students b/changelog/fix-co-teachers-get-students new file mode 100644 index 0000000000..ccf284d49c --- /dev/null +++ b/changelog/fix-co-teachers-get-students @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Filter course IDs associated with a given teacher From 76a2adcc425227640b10a4d9207d0e539b3c839a Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Wed, 6 Nov 2024 07:37:16 -0500 Subject: [PATCH 4/4] Update change log --- changelog/fix-co-teachers-get-students | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/fix-co-teachers-get-students b/changelog/fix-co-teachers-get-students index ccf284d49c..e998138638 100644 --- a/changelog/fix-co-teachers-get-students +++ b/changelog/fix-co-teachers-get-students @@ -1,4 +1,4 @@ -Significance: minor +Significance: development Type: added Filter course IDs associated with a given teacher