本文整理汇总了PHP中CourseManager::remove_course_ranking方法的典型用法代码示例。如果您正苦于以下问题:PHP CourseManager::remove_course_ranking方法的具体用法?PHP CourseManager::remove_course_ranking怎么用?PHP CourseManager::remove_course_ranking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CourseManager
的用法示例。
在下文中一共展示了CourseManager::remove_course_ranking方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_courses_to_session
/**
* Subscribes courses to the given session and optionally (default)
* unsubscribes previous users
* @author Carlos Vargas from existing code
* @param int $sessionId
* @param array $courseList List of courses IDs
* @param bool $removeExistingCoursesUsers Whether to unsubscribe
* existing courses and users (true, default) or not (false)
* @return void Nothing, or false on error
* */
public static function add_courses_to_session(
$sessionId,
$courseList,
$removeExistingCoursesWithUsers = true
) {
$sessionId = intval($sessionId);
if (empty($sessionId) || empty($courseList)) {
return false;
}
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
// get list of courses subscribed to this session
$sql = "SELECT course_code
FROM $tbl_session_rel_course
WHERE id_session=$sessionId";
$rs = Database::query($sql );
$existingCourses = Database::store_result($rs);
$nbr_courses = count($existingCourses);
// get list of users subscribed to this session
$sql = "SELECT id_user
FROM $tbl_session_rel_user
WHERE
id_session = $sessionId AND
relation_type<>" . SESSION_RELATION_TYPE_RRHH . "";
$result = Database::query($sql);
$user_list = Database::store_result($result);
// Remove existing courses from the session.
if ($removeExistingCoursesWithUsers === true) {
foreach ($existingCourses as $existingCourse) {
if (!in_array($existingCourse['course_code'], $courseList)) {
$courseInfo = api_get_course_info($existingCourse['course_code']);
$sql = "DELETE FROM $tbl_session_rel_course
WHERE course_code='" . $existingCourse['course_code'] . "' AND id_session=$sessionId";
Database::query($sql);
$sql = "DELETE FROM $tbl_session_rel_course_rel_user
WHERE course_code='" . $existingCourse['course_code'] . "' AND id_session=$sessionId";
Database::query($sql);
CourseManager::remove_course_ranking(
$courseInfo['real_id'],
$sessionId
);
$nbr_courses--;
}
}
}
// Pass through the courses list we want to add to the session
foreach ($courseList as $enreg_course) {
$enreg_course = Database::escape_string($enreg_course);
$exists = false;
// check if the course we want to add is already subscribed
foreach ($existingCourses as $existingCourse) {
if ($enreg_course == $existingCourse['course_code']) {
$exists = true;
}
}
if (!$exists) {
//if the course isn't subscribed yet
$sql = "INSERT INTO $tbl_session_rel_course (id_session, course_code)
VALUES ('$sessionId','$enreg_course')";
Database::query($sql);
//We add the current course in the existing courses array, to avoid adding another time the current course
$existingCourses[] = array('course_code' => $enreg_course);
$nbr_courses++;
// subscribe all the users from the session to this course inside the session
$nbr_users = 0;
foreach ($user_list as $enreg_user) {
$enreg_user_id = intval($enreg_user['id_user']);
$sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user (id_session, course_code, id_user)
VALUES ($sessionId,'$enreg_course',$enreg_user_id)";
Database::query($sql);
if (Database::affected_rows()) {
$nbr_users++;
}
}
$sql = "UPDATE $tbl_session_rel_course
//.........这里部分代码省略.........
示例2: add_courses_to_session
/**
* Subscribes courses to the given session and optionally (default)
* unsubscribes previous users
* @author Carlos Vargas from existing code
* @param int $sessionId
* @param array $courseList List of courses int ids
* @param bool $removeExistingCoursesWithUsers Whether to unsubscribe
* existing courses and users (true, default) or not (false)
* @param $copyEvaluation from base course to session course
* @return void Nothing, or false on error
* */
public static function add_courses_to_session($sessionId, $courseList, $removeExistingCoursesWithUsers = true, $copyEvaluation = false)
{
$sessionId = intval($sessionId);
if (empty($sessionId) || empty($courseList)) {
return false;
}
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
// Get list of courses subscribed to this session
$sql = "SELECT c_id\n FROM {$tbl_session_rel_course}\n WHERE session_id = {$sessionId}";
$rs = Database::query($sql);
$existingCourses = Database::store_result($rs);
$nbr_courses = count($existingCourses);
// Get list of users subscribed to this session
$sql = "SELECT user_id\n FROM {$tbl_session_rel_user}\n WHERE\n session_id = {$sessionId} AND\n relation_type<>" . SESSION_RELATION_TYPE_RRHH . "";
$result = Database::query($sql);
$user_list = Database::store_result($result);
// Remove existing courses from the session.
if ($removeExistingCoursesWithUsers === true && !empty($existingCourses)) {
foreach ($existingCourses as $existingCourse) {
if (!in_array($existingCourse['c_id'], $courseList)) {
$sql = "DELETE FROM {$tbl_session_rel_course}\n WHERE\n c_id = " . $existingCourse['c_id'] . " AND\n session_id = {$sessionId}";
Database::query($sql);
$sql = "DELETE FROM {$tbl_session_rel_course_rel_user}\n WHERE\n c_id = " . $existingCourse['c_id'] . " AND\n session_id = {$sessionId}";
Database::query($sql);
Event::addEvent(LOG_SESSION_DELETE_COURSE, LOG_COURSE_ID, $existingCourse['c_id'], api_get_utc_datetime(), api_get_user_id(), $existingCourse['c_id'], $sessionId);
CourseManager::remove_course_ranking($existingCourse['c_id'], $sessionId);
$nbr_courses--;
}
}
}
// Pass through the courses list we want to add to the session
foreach ($courseList as $courseId) {
$courseInfo = api_get_course_info_by_id($courseId);
// If course doesn't exists continue!
if (empty($courseInfo)) {
continue;
}
$exists = false;
// check if the course we want to add is already subscribed
foreach ($existingCourses as $existingCourse) {
if ($courseId == $existingCourse['c_id']) {
$exists = true;
}
}
if (!$exists) {
// Copy gradebook categories and links (from base course)
// to the new course session
if ($copyEvaluation) {
$cats = Category::load(null, null, $courseInfo['code']);
if (!empty($cats)) {
$categoryIdList = [];
/** @var Category $cat */
foreach ($cats as $cat) {
$categoryIdList[$cat->get_id()] = $cat->get_id();
}
$newCategoryIdList = [];
foreach ($cats as $cat) {
$links = $cat->get_links(null, false, $courseInfo['code'], 0);
$cat->set_session_id($sessionId);
$oldCategoryId = $cat->get_id();
$newId = $cat->add();
$newCategoryIdList[$oldCategoryId] = $newId;
$parentId = $cat->get_parent_id();
if (!empty($parentId)) {
$newParentId = $newCategoryIdList[$parentId];
$cat->set_parent_id($newParentId);
$cat->save();
}
/** @var AbstractLink $link */
foreach ($links as $link) {
$newCategoryId = $newCategoryIdList[$link->get_category_id()];
$link->set_category_id($newCategoryId);
$link->add();
}
}
// Create
DocumentManager::generateDefaultCertificate($courseInfo, true, $sessionId);
}
}
// If the course isn't subscribed yet
$sql = "INSERT INTO {$tbl_session_rel_course} (session_id, c_id)\n VALUES ({$sessionId}, {$courseId})";
Database::query($sql);
Event::addEvent(LOG_SESSION_ADD_COURSE, LOG_COURSE_ID, $courseId, api_get_utc_datetime(), api_get_user_id(), $courseId, $sessionId);
// We add the current course in the existing courses array,
// to avoid adding another time the current course
$existingCourses[] = array('c_id' => $courseId);
//.........这里部分代码省略.........
示例3: foreach
foreach ($UserList as $enreg_user) {
$enreg_user = Database::escape_string($enreg_user['id_user']);
$sql_insert = "INSERT IGNORE INTO {$tbl_session_rel_course_rel_user}(id_session,course_code,id_user)\n VALUES('{$id_session}','{$enreg_course}','{$enreg_user}')";
Database::query($sql_insert);
if (Database::affected_rows()) {
$nbr_users++;
}
}
SessionManager::installCourse($id_session, $course_info['real_id']);
Database::query("UPDATE {$tbl_session_rel_course} SET nbr_users={$nbr_users} WHERE id_session='{$id_session}' AND course_code='{$enreg_course}'");
}
}
foreach ($existingCourses as $existingCourse) {
if (!in_array($existingCourse['course_code'], $CourseList)) {
$course_info = api_get_course_info($existingCourse['course_code']);
CourseManager::remove_course_ranking($course_info['real_id'], $id_session);
Database::query("DELETE FROM {$tbl_session_rel_course} WHERE course_code='" . $existingCourse['course_code'] . "' AND id_session={$id_session}");
Database::query("DELETE FROM {$tbl_session_rel_course_rel_user} WHERE course_code='" . $existingCourse['course_code'] . "' AND id_session={$id_session}");
SessionManager::unInstallCourse($id_session, $course_info['real_id']);
}
}
$nbr_courses = count($CourseList);
Database::query("UPDATE {$tbl_session} SET nbr_courses={$nbr_courses} WHERE id='{$id_session}'");
if (isset($add)) {
header('Location: add_users_to_session.php?id_session=' . $id_session . '&add=true');
} else {
header('Location: resume_session.php?id_session=' . $id_session);
}
exit;
}
// display the header