@@ -736,11 +736,11 @@ public static function get_course_code_from_course_id($id)
736736 * @author Hugues Peeters
737737 * @author Roan Embrechts
738738 *
739- * @param int $user_id the id of the user
740- * @param string $courseCode the course code
741- * @param int $status (optional) The user's status in the course
742- * @param int $userCourseCategoryId
743- * @param int The user category in which this subscription will be classified
739+ * @param int $user_id the id of the user
740+ * @param string $courseCode the course code
741+ * @param int $status (optional) The user's status in the course
742+ * @param int $userCourseCategoryId The user category in which this subscription will be classified
743+ * @param bool $checkTeacherPermission
744744 *
745745 * @return false|string true if subscription succeeds, boolean false otherwise
746746 * @assert ('', '') === false
@@ -749,7 +749,8 @@ public static function add_user_to_course(
749749 $ user_id ,
750750 $ courseCode ,
751751 $ status = STUDENT ,
752- $ userCourseCategoryId = 0
752+ $ userCourseCategoryId = 0 ,
753+ $ checkTeacherPermission = true
753754 ) {
754755 $ debug = false ;
755756 $ user_table = Database::get_main_table (TABLE_MAIN_USER );
@@ -789,7 +790,7 @@ public static function add_user_to_course(
789790 return false ; // The user has been subscribed to the course.
790791 }
791792
792- if (!api_is_course_admin ()) {
793+ if ($ checkTeacherPermission && !api_is_course_admin ()) {
793794 // Check in advance whether subscription is allowed or not for this course.
794795 $ sql = "SELECT code, visibility FROM $ course_table
795796 WHERE id = $ courseId AND subscribe = ' " .SUBSCRIBE_NOT_ALLOWED ."' " ;
0 commit comments