/** * helper to unregister a class from course * * @author Damien Garros <*****@*****.**> * * @param int class_id * @param string course_code * * @return Claro_BatchRegistrationResult */ function unregister_class_to_course($class_id, $course_code) { $claroClass = new Claro_Class(Claroline::getDatabase()); $claroClass->load($class_id); $courseObj = new Claro_Course($course_code); $courseObj->load(); $result = new Claro_BatchRegistrationResult(); return object_unregister_class_from_course($claroClass, $courseObj, $result); }
/** * insert or update course data * * @return boolean success */ public function save() { if (empty($this->courseId)) { // Insert $keys = define_course_keys($this->officialCode, '', get_conf('dbNamePrefix')); $courseSysCode = trim($keys['currentCourseId']); $courseDbName = trim($keys['currentCourseDbName']); $courseDirectory = trim($keys['currentCourseRepository']); if (empty($courseSysCode) || empty($courseDbName) || empty($courseDirectory)) { throw new Exception("Error missing data for course {$this->officialCode}"); } if (!$this->useExpirationDate) { $this->expirationDate = 'NULL'; } // Session courses are created without categories links: // so we duplicate the source course's categories links /*if ( !is_null($this->sourceCourseId) && !empty($this->sourceCourseId) ) { $sourceCourse = new claroCourse(); $sourceCourse->load(claroCourse::getCodeFromId($this->sourceCourseId)); $this->categories = $sourceCourse->categories; }*/ if (!is_null($this->sourceCourseId) && !empty($this->sourceCourseId)) { $sourceCourse = new claroCourse(); $sourceCourse->load(claroCourse::getCodeFromId($this->sourceCourseId)); if ($sourceCourse->sourceCourseId) { throw new Exception('You cannot create a course session from another course session'); } } if (prepare_course_repository($courseDirectory, $courseSysCode) && register_course($courseSysCode, $this->officialCode, $this->sourceCourseId, $courseDirectory, $courseDbName, $this->titular, $this->email, $this->categories, $this->title, $this->language, $GLOBALS['_uid'], $this->access, $this->registration, $this->registrationKey, $this->visibility, $this->departmentName, $this->extLinkUrl, $this->publicationDate, $this->expirationDate, $this->status, $this->userLimit) && install_course_database($courseDbName) && install_course_tools($courseDbName, $this->language, $courseDirectory)) { $courseObj = new Claro_Course($courseSysCode); $courseObj->load(); $courseRegistration = new Claro_CourseUserRegistration(AuthProfileManager::getUserAuthProfile($GLOBALS['_uid']), $courseObj, null, null); $courseRegistration->ignoreRegistrationKeyCheck(); $courseRegistration->ignoreCategoryRegistrationCheck(); $courseRegistration->setCourseAdmin(); $courseRegistration->setCourseTutor(); $courseRegistration->forceSuperUser(); if ($courseRegistration->addUser()) { // Set course id $this->courseId = $courseSysCode; // Notify event manager $args['courseSysCode'] = $courseSysCode; $args['courseDbName'] = $courseDbName; $args['courseDirectory'] = $courseDirectory; $args['courseCategory'] = $this->categories; $GLOBALS['eventNotifier']->notifyEvent("course_created", $args); return true; } else { $this->backlog->failure($courseRegistration->getErrorMessage()); return false; } } else { $lastFailure = claro_failure::get_last_failure(); $this->backlog->failure('Error : ' . $lastFailure); return false; } } else { // Update $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_course = $tbl_mdb_names['course']; $tbl_cdb_names = claro_sql_get_course_tbl(); $tbl_course_properties = $tbl_cdb_names['course_properties']; if (!$this->useExpirationDate) { $this->expirationDate = null; } $sqlExpirationDate = is_null($this->expirationDate) ? 'NULL' : 'FROM_UNIXTIME(' . claro_sql_escape($this->expirationDate) . ')'; $sqlCreationDate = is_null($this->publicationDate) ? 'NULL' : 'FROM_UNIXTIME(' . claro_sql_escape($this->publicationDate) . ')'; $sql = "UPDATE `" . $tbl_course . "`\n SET `intitule` = '" . claro_sql_escape($this->title) . "',\n `titulaires` = '" . claro_sql_escape($this->titular) . "',\n `administrativeNumber` = '" . claro_sql_escape($this->officialCode) . "',\n `language` = '" . claro_sql_escape($this->language) . "',\n `extLinkName` = '" . claro_sql_escape($this->departmentName) . "',\n `extLinkUrl` = '" . claro_sql_escape($this->extLinkUrl) . "',\n `email` = '" . claro_sql_escape($this->email) . "',\n `visibility` = '" . ($this->visibility ? 'visible' : 'invisible') . "',\n `access` = '" . claro_sql_escape($this->access) . "',\n `registration` = '" . claro_sql_escape($this->registration) . "',\n `registrationKey` = '" . claro_sql_escape($this->registrationKey) . "',\n `lastEdit` = NOW(),\n `creationDate` = " . $sqlCreationDate . ",\n `expirationDate` = " . $sqlExpirationDate . ",\n `status` = '" . claro_sql_escape($this->status) . "',\n `userLimit` = '" . (int) $this->userLimit . "'\n WHERE code='" . claro_sql_escape($this->courseId) . "'"; // Handle categories // 1/ Remove all links in database $this->unlinkCategories(); // 2/ Link new categories selection $this->linkCategories($this->categories); // If it's a source course, do the same for all its session courses if ($this->isSourceCourse) { $sql2 = "SELECT cours_id FROM `" . $tbl_course . "`\n WHERE sourceCourseId = " . $this->id; $sessionCourses = claro_sql_query_fetch_all_rows($sql2); foreach ($sessionCourses as $sessionCourse) { unlink_course_categories($sessionCourse['cours_id']); link_course_categories($sessionCourse['cours_id'], $this->categories); } } return claro_sql_query($sql); } }
} $assignmentPath = get_path('coursesRepositorySys') . claro_get_course_path(claro_get_current_course_id()) . '/work/assig_' . (int) $result['assignment_id'] . '/'; // count author's submissions for the name of directory if ($result['authors'] != $previousAuthors) { $i = 1; $previousAuthors = $result['authors']; } else { $i++; } $authorsDir = replace_dangerous_char($result['authors']) . '/'; if (!is_dir($zipPath . $assigDir . '/' . $authorsDir)) { mkdir($zipPath . $assigDir . '/' . $authorsDir, CLARO_FILE_PERMISSIONS, true); } if ($downloadScore && !(isset($currAssigId) && $currAssigId == $result['assignment_id'])) { $course = new Claro_Course(claro_get_current_course_id()); $course->load(); $assignment = new Assignment(); $assignment->load($result['assignment_id']); $currAssigId = $result['assignment_id']; $scoreList = new CLWRK_AssignementScoreList($assignment); if (!$downloadOnlyCurrentMembersSubmissions) { $scoreList->setOptAllUsers(); } $scoreListIterator = $scoreList->getScoreList(); $scoreListRenderer = new CLWRK_ScoreListRenderer($course, $assignment, $scoreListIterator); file_put_contents($zipPath . $assigDir . '/scores.html', $scoreListRenderer->render()); } $submissionPrefix = $assigDir . $authorsDir . replace_dangerous_char(get_lang('Submission')) . '_' . $i . '_'; // attached file if (!empty($result['submitted_doc_path'])) { if (file_exists($assignmentPath . $result['submitted_doc_path'])) {
/** * 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; }
default: $dialogBox->error(get_lang('Unable to remove your registration to the course')); break; } } $displayMode = DISPLAY_MESSAGE_SCREEN; } // end if ($cmd == 'exUnreg') /*---------------------------------------------------------------------------- Subscribe to a course ----------------------------------------------------------------------------*/ if ($cmd == 'exReg') { $registrationKey = isset($_REQUEST['registrationKey']) ? $_REQUEST['registrationKey'] : null; $categoryId = isset($_REQUEST['categoryId']) ? $_REQUEST['categoryId'] : null; $courseObj = new Claro_Course($courseCode); $courseObj->load(); $courseRegistration = new Claro_CourseUserRegistration(AuthProfileManager::getUserAuthProfile($userId), $courseObj, $registrationKey, $categoryId); if (!empty($classId)) { $claroClass = new Claro_Class(); $claroClass->load($classId); $courseRegistration->setClass($claroClass); } if ($courseRegistration->addUser()) { $claroline->log('COURSE_SUBSCRIBE', array('user' => $userId, 'course' => $courseCode)); $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')); }