Beispiel #1
0
/**
 * unsubscribe a specific user from a specific course
 *
 *
 * @param  int     $user_id        user ID from the course_user table
 * @param  mixed (string or array) $courseCodeList course sys code
 * @param  boolean $force  true  possible to remove a course admin from course
 *                        (default false)
 * @param  boolean $deleteTrackingData (default false)
 *
 * @return boolean TRUE        if unsubscribtion succeed
 *         boolean FALSE       otherwise.
 */
function user_remove_from_course($userId, $courseCodeList = array(), $force = false, $delTrackData = false, $class_id = null)
{
    if (!is_array($courseCodeList)) {
        $courseCodeList = array($courseCodeList);
    }
    if ($class_id) {
        $claroClass = new Claro_Class();
        $claroClass->load($class_id);
    } else {
        $claroClass = null;
    }
    $allWorksWell = true;
    foreach ($courseCodeList as $courseCode) {
        $course = new Claro_Course($courseCode);
        $course->load();
        $userCourseRegistration = new Claro_CourseUserRegistration(AuthProfileManager::getUserAuthProfile($userId), $course);
        if ($force) {
            $userCourseRegistration->forceUnregistrationOfManager();
        }
        if (!is_null($claroClass)) {
            $userCourseRegistration->setClass($claroClass);
        }
        $keepTrackingData = !$delTrackData;
        if (!$userCourseRegistration->removeUser($keepTrackingData, array())) {
            Console::warning("Cannot remove user {$userId} from {$courseCode}");
            $allWorksWell = false;
        }
    }
    return $allWorksWell;
}
Beispiel #2
0
         $unregisterdUserCount = count($result->getDeletedUserList());
         if ($unregisterdUserCount) {
             Console::log("{$req['user_id']} ({$unregisterdUserCount}) removed by user " . claro_get_current_user_id(), 'COURSE_UNSUBSCRIBE');
         }
         $dialogBox->info(get_lang('%number student(s) unregistered from this course', array('%number' => $unregisterdUserCount)));
     } else {
         Console::error("Error while deleting all users from course " . claro_get_current_course_id() . " : " . var_export($result->getErrorLog(), true));
         $dialogBox->error(get_lang('An error occured') . ' : <ul><li>' . implode('</li><li>', $result->getErrorLog()) . '</li></ul>');
     }
 } elseif (0 < (int) $req['user_id']) {
     if ($forceUnenrolment) {
         $course = new Claro_Course(claro_get_current_course_id());
         $course->load();
         $userCourseRegistration = new Claro_CourseUserRegistration(AuthProfileManager::getUserAuthProfile($req['user_id']), $course);
         if (claro_is_platform_admin()) {
             $userCourseRegistration->forceUnregistrationOfManager();
         }
         if (!$userCourseRegistration->forceRemoveUser(false, array())) {
             $dialogBox->error(get_lang('The user cannot be removed from the course'));
         } else {
             Console::log("{$req['user_id']} removed [forced] by admin " . claro_get_current_user_id(), 'COURSE_UNSUBSCRIBE');
             $dialogBox->success(get_lang('The user has been successfully unregistered from course'));
         }
     } else {
         // delete user from course user list
         if (user_remove_from_course($req['user_id'], claro_get_current_course_id(), false, false, null)) {
             Console::log("{$req['user_id']} removed by user " . claro_get_current_user_id(), 'COURSE_UNSUBSCRIBE');
             $dialogBox->success(get_lang('The user has been successfully unregistered from course'));
         } else {
             switch (claro_failure::get_last_failure()) {
                 case 'cannot_unsubscribe_the_last_course_manager':