/** * Subscribe a specific user to a specific course. If this course is a session * course, the user will also be subscribed to the source course. * * Helper for Claro_CourseUserRegistration * * @param int $userId user ID from the course_user table * @param string $courseCode course code from the cours table * @param boolean $admin * @param boolean $tutor * @param int $class_id * @return boolean TRUE if it succeeds, FALSE otherwise */ function user_add_to_course($userId, $courseCode, $admin = false, $tutor = false, $class_id = null) { $courseObj = new Claro_Course($courseCode); $courseObj->load(); $courseRegistration = new Claro_CourseUserRegistration(AuthProfileManager::getUserAuthProfile($userId), $courseObj, null, null); if ($admin) { $courseRegistration->setCourseAdmin(); } if ($tutor) { $courseRegistration->setCourseTutor(); } if ($class_id) { $claroClass = new Claro_Class(); $claroClass->load($class_id); $courseRegistration->setClass($claroClass); } $courseRegistration->ignoreRegistrationKeyCheck(); if ($courseRegistration->addUser()) { return true; } else { // @todo should throw an exception here Console::error("Cannot register user {$userId} in course {$courseCode} [" . $courseRegistration->getStatus() . ":" . $courseRegistration->getErrorMessage() . "]"); return false; } }
$displayMode = DISPLAY_MESSAGE_SCREEN; if (claro_get_current_user_id() != $uidToEdit) { // Message for admin $dialogBox->success(get_lang('The user has been enroled to the course')); } else { $dialogBox->success(get_lang('You\'ve been enroled on the course')); } $properties = array(); if ($asTeacher && claro_is_platform_admin()) { $properties['isCourseManager'] = 1; $properties['role'] = get_lang('Course manager'); $properties['tutor'] = 1; user_set_course_properties($userId, $courseCode, $properties); } } else { switch ($courseRegistration->getStatus()) { case Claro_CourseUserRegistration::STATUS_KEYVALIDATION_FAILED: $displayMode = DISPLAY_REGISTRATION_KEY_FORM; $dialogBox->error($courseRegistration->getErrorMessage()); break; case Claro_CourseUserRegistration::STATUS_SYSTEM_ERROR: $displayMode = DISPLAY_MESSAGE_SCREEN; $dialogBox->error($courseRegistration->getErrorMessage()); break; case Claro_CourseUserRegistration::STATUS_REGISTRATION_NOTAVAILABLE: $displayMode = DISPLAY_REGISTRATION_DISABLED_FORM; $dialogBox->error($courseRegistration->getErrorMessage()); $dialogBox->info(get_lang('Please contact the course manager : %email', array('%email' => '<a href="mailto:' . $courseObj->email . '?body=' . $courseObj->officialCode . '&subject=[' . rawurlencode(get_conf('siteName')) . ']' . '">' . claro_htmlspecialchars($courseObj->titular) . '</a>'))); break; default: $displayMode = DISPLAY_MESSAGE_SCREEN;
if ($userData['courseAdmin']) { $courseRegistration->setCourseAdmin(); } if ($userData['profileId']) { $courseRegistration->setUserProfileIdInCourse($userData['profileId']); } if ($userData['courseTutor']) { $courseRegistration->setCourseTutor(); } $courseRegistration->ignoreRegistrationKeyCheck(); $courseRegistration->ignoreRegistrationKeyCheck(); if ($courseRegistration->addUser()) { $courseRegSucceed = true; } else { // @todo should throw an exception here Console::error("Cannot register user {$userId} in course {$courseCode} [" . $courseRegistration->getStatus() . ":" . $courseRegistration->getErrorMessage() . "]"); $courseRegSucceed = false; } Console::log("{$userId} enroled to course " . claro_get_current_course_id() . " by " . claro_get_current_user_id(), 'COURSE_SUBSCRIBE'); } else { $courseRegSucceed = false; } } // end if $cmd == 'registration' if ($cmd == 'applySearch') { // Search on username, official_code, ... $displayResultTable = true; if (!(empty($userData['lastname']) && empty($userData['firstname']) && empty($userData['email']) && empty($userData['username']) && empty($userData['officialCode']))) { $userList = user_search(array('lastname' => $userData['lastname'], 'firstname' => $userData['firstname'], 'email' => $userData['email'], 'officialCode' => $userData['officialCode'], 'username' => $userData['username']), claro_get_current_course_id(), true, false, !claro_is_platform_admin()); } else { $userList = array();