Skip to content

Commit 9ab965d

Browse files
committed
Webservice can register user to a course no matter the course config
Webservice is kind of "admin" $checkTeacherPermission parameter added BT#14613
1 parent ef82508 commit 9ab965d

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

main/inc/lib/course.lib.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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."'";

main/webservices/registration.soap.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4653,7 +4653,7 @@ function WSSubscribeUserToCourse($params)
46534653
if ($debug) {
46544654
error_log('WSSubscribeUserToCourse courseCode: '.$courseCode);
46554655
}
4656-
$result = CourseManager::add_user_to_course($user_id, $courseCode, $status, false);
4656+
$result = CourseManager::add_user_to_course($user_id, $courseCode, $status, false, false);
46574657
if ($result) {
46584658
$resultValue = 1;
46594659
if ($debug) {
@@ -4767,8 +4767,9 @@ function WSSubscribeUserToCourseSimple($params)
47674767
if ($debug) {
47684768
error_log('Try to register: user_id= '.$user_id.' to course: '.$course_data['code']);
47694769
}
4770-
if (!CourseManager::add_user_to_course($user_id, $course_data['code'], $status)) {
4771-
$result = 'User was not registered possible reasons: User already registered to the course, Course visibility doesnt allow user subscriptions ';
4770+
if (!CourseManager::add_user_to_course($user_id, $course_data['code'], $status, false, false)) {
4771+
$result = 'User was not registered possible reasons: User already registered to the course,
4772+
Course visibility doesnt allow user subscriptions ';
47724773
if ($debug) {
47734774
error_log($result);
47744775
}

0 commit comments

Comments
 (0)