当前位置: 首页>>代码示例>>PHP>>正文


PHP SessionManager::subscribe_users_to_session_course方法代码示例

本文整理汇总了PHP中SessionManager::subscribe_users_to_session_course方法的典型用法代码示例。如果您正苦于以下问题:PHP SessionManager::subscribe_users_to_session_course方法的具体用法?PHP SessionManager::subscribe_users_to_session_course怎么用?PHP SessionManager::subscribe_users_to_session_course使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SessionManager的用法示例。


在下文中一共展示了SessionManager::subscribe_users_to_session_course方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: importSubscribeStatic

 /**
  * @param string $file
  */
 private function importSubscribeStatic($file)
 {
     $data = Import::csv_reader($file);
     if (!empty($data)) {
         $this->logger->addInfo(count($data) . " records found.");
         foreach ($data as $row) {
             $chamiloUserName = $row['UserName'];
             $chamiloCourseCode = $row['CourseCode'];
             $chamiloSessionId = $row['SessionID'];
             $type = $row['Type'];
             $sessionInfo = api_get_session_info($chamiloSessionId);
             if (empty($sessionInfo)) {
                 $this->logger->addError('Session does not exists: ' . $chamiloSessionId);
                 continue;
             }
             $courseInfo = api_get_course_info($chamiloCourseCode);
             if (empty($courseInfo)) {
                 $this->logger->addError('Course does not exists: ' . $courseInfo);
                 continue;
             }
             $userId = Usermanager::get_user_id_from_username($chamiloUserName);
             if (empty($userId)) {
                 $this->logger->addError('User does not exists: ' . $chamiloUserName);
                 continue;
             }
             $status = null;
             switch ($type) {
                 case 'student':
                     SessionManager::subscribe_users_to_session_course(array($userId), $chamiloSessionId, $courseInfo['code'], null, false);
                     break;
                 case 'teacher':
                     SessionManager::set_coach_to_course_session($userId, $chamiloSessionId, $courseInfo['real_id']);
                     break;
             }
             $this->logger->addError("User '{$chamiloUserName}' with status {$type} was added to session: #{$chamiloSessionId} - Course: " . $courseInfo['code']);
         }
     }
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:41,代码来源:import_csv.php

示例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        Session ID
  * @param    array    List of courses IDs
  * @param    bool    Whether to unsubscribe existing users (true, default) or not (false)
  * @return    void    Nothing, or false on error
  **/
 public static function add_courses_to_session($id_session, $course_list, $empty_courses = true)
 {
     // security checks
     if ($id_session != strval(intval($id_session))) {
         return false;
     }
     // initialisation
     $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 general coach ID
     $id_coach = Database::query("SELECT id_coach FROM {$tbl_session} WHERE id={$id_session}");
     $id_coach = Database::fetch_array($id_coach);
     $id_coach = $id_coach[0];
     // get list of courses subscribed to this session
     $rs = Database::query("SELECT c_id FROM {$tbl_session_rel_course} WHERE id_session={$id_session}");
     $existingCourses = Database::store_result($rs, 'ASSOC');
     $nbr_courses = count($existingCourses);
     // get list of users subscribed to this session
     $sql = "SELECT id_user\n            FROM {$tbl_session_rel_user}\n            WHERE id_session = {$id_session} AND relation_type<>" . SESSION_RELATION_TYPE_RRHH . "";
     $result = Database::query($sql);
     $user_list = Database::store_result($result, 'ASSOC');
     // Remove existing courses from the session
     if ($empty_courses === true) {
         foreach ($existingCourses as $existingCourse) {
             if (!in_array($existingCourse['c_id'], $course_list)) {
                 Database::query("DELETE FROM {$tbl_session_rel_course} WHERE c_id='" . $existingCourse['c_id'] . "' AND id_session={$id_session}");
                 Database::query("DELETE FROM {$tbl_session_rel_course_rel_user} WHERE c_id='" . $existingCourse['c_id'] . "' AND id_session={$id_session}");
             }
         }
         $nbr_courses = 0;
     }
     // Pass through the courses list we want to add to the session
     foreach ($course_list as $courseId) {
         $courseId = Database::escape_string($courseId);
         $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 == false) {
             CourseManager::update_course_ranking($courseId, $id_session);
             //if the course isn't subscribed yet
             $sql_insert_rel_course = "INSERT INTO {$tbl_session_rel_course} (id_session, c_id) VALUES ('{$id_session}','{$courseId}')";
             Database::query($sql_insert_rel_course);
             //We add the current course in the existing courses array, to avoid adding another time the current course
             $existingCourses[] = array('c_id' => $courseId);
             $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 = Database::escape_string($enreg_user['id_user']);
                 $sql_insert = "INSERT IGNORE INTO {$tbl_session_rel_course_rel_user} (id_session, c_id, id_user) VALUES ('{$id_session}','{$courseId}','{$enreg_user_id}')";
                 $result = Database::query($sql_insert);
                 if (Database::affected_rows($result)) {
                     $nbr_users++;
                 }
             }
             SessionManager::subscribe_users_to_session_course($user_list, $id_session, $courseId);
             Database::query("UPDATE {$tbl_session_rel_course} SET nbr_users={$nbr_users} WHERE id_session='{$id_session}' AND c_id = '{$courseId}'");
         }
     }
     Database::query("UPDATE {$tbl_session} SET nbr_courses={$nbr_courses} WHERE id='{$id_session}'");
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:74,代码来源:sessionmanager.lib.php

示例3: header

    $idChecked = $my_temp;
}
$session_info = SessionManager::fetch($id_session);
$courses = SessionManager::get_course_list_by_session_id($id_session);
if (!isset($courses[$course_info['real_id']])) {
    header('Location: session_course_list.php?id_session=' . $id_session);
    exit;
}
switch ($action) {
    case 'delete':
        SessionManager::unsubscribe_user_from_course_session($id_session, $idChecked, $courseId);
        header('Location: ' . api_get_self() . '?id_session=' . $id_session . '&course_code=' . urlencode($course_code) . '&sort=' . $sort);
        exit;
        break;
    case 'add':
        SessionManager::subscribe_users_to_session_course($idChecked, $id_session, $courseId);
        header('Location: ' . api_get_self() . '?id_session=' . $id_session . '&course_code=' . urlencode($course_code) . '&sort=' . $sort);
        exit;
        break;
}
$limit = 20;
$from = $page * $limit;
$is_western_name_order = api_is_western_name_order();
$Users = SessionManager::get_users_in_course_session($courseId, $id_session, $sort, $direction, $from, $limit);
if ($direction == 'desc') {
    $direction = 'asc';
} else {
    $direction = 'desc';
}
$nbr_results = sizeof($Users);
$tool_name = get_lang('Session') . ': ' . $session_info['name'] . ' - ' . get_lang('Course') . ': ' . $course_info['title'];
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:31,代码来源:session_course_user_list.php

示例4: subscribe_user

 /**
  * Subscribe a user to a course. No checks are performed here to see if
  * course subscription is allowed.
  * @param   int     User ID
  * @param   string  Course code
  * @param   int     Status (STUDENT, COURSEMANAGER, COURSE_ADMIN, NORMAL_COURSE_MEMBER)
  * @return  bool    True on success, false on failure
  * @see add_user_to_course
  * @assert ('', '') === false
  */
 public static function subscribe_user($user_id, $course_code, $status = STUDENT, $session_id = 0, $userCourseCategoryId = 0)
 {
     if ($user_id != strval(intval($user_id))) {
         return false;
         //detected possible SQL injection
     }
     $course_code = Database::escape_string($course_code);
     $courseInfo = api_get_course_info($course_code);
     $courseId = $courseInfo['real_id'];
     $courseCode = $courseInfo['code'];
     $userCourseCategoryId = intval($userCourseCategoryId);
     if (empty($user_id) || empty($course_code)) {
         return false;
     }
     if (!empty($session_id)) {
         $session_id = intval($session_id);
     } else {
         $session_id = api_get_session_id();
     }
     $status = $status == STUDENT || $status == COURSEMANAGER ? $status : STUDENT;
     //$role_id = ($status == COURSEMANAGER) ? COURSE_ADMIN : NORMAL_COURSE_MEMBER;
     // A preliminary check whether the user has bben already registered on the platform.
     if (Database::num_rows(Database::query("SELECT status FROM " . Database::get_main_table(TABLE_MAIN_USER) . "\n                WHERE user_id = '{$user_id}' ")) == 0) {
         return false;
         // The user has not been registered to the platform.
     }
     // Check whether the user has not been already subscribed to the course.
     if (empty($session_id)) {
         if (Database::num_rows(Database::query("\n                    SELECT * FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "\n                    WHERE user_id = '{$user_id}' AND relation_type<>" . COURSE_RELATION_TYPE_RRHH . " AND c_id = '{$courseId}'")) > 0) {
             // The user has been already subscribed to the course.
             return false;
         }
     }
     if (!empty($session_id)) {
         SessionManager::subscribe_users_to_session_course(array($user_id), $session_id, $courseCode);
     } else {
         CourseManager::add_user_to_course($user_id, $courseCode, $status);
         // Add event to the system log
         Event::addEvent(LOG_SUBSCRIBE_USER_TO_COURSE, LOG_COURSE_CODE, $course_code, api_get_utc_datetime(), api_get_user_id());
         $user_info = api_get_user_info($user_id);
         Event::addEvent(LOG_SUBSCRIBE_USER_TO_COURSE, LOG_USER_OBJECT, $user_info, api_get_utc_datetime(), api_get_user_id());
     }
     return true;
 }
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:54,代码来源:course.lib.php

示例5: importCSV


//.........这里部分代码省略.........
                 if (count($courses) >= 2) {
                     // Only first teacher in course session;
                     $onlyAddFirstCoachOrTeacher = true;
                     // Remove all teachers from course.
                     $removeAllTeachersFromCourse = false;
                 }
             }
             foreach ($courses as $course) {
                 $courseArray = bracketsToArray($course);
                 $course_code = $courseArray[0];
                 if (CourseManager::course_exists($course_code)) {
                     $courseInfo = api_get_course_info($course_code);
                     $courseId = $courseInfo['real_id'];
                     // Adding the course to a session.
                     $sql = "INSERT IGNORE INTO {$tbl_session_course}\n                                SET c_id = '{$courseId}', session_id='{$session_id}'";
                     Database::query($sql);
                     SessionManager::installCourse($session_id, $courseInfo['real_id']);
                     if ($debug) {
                         $logger->addInfo("Sessions - Adding course '{$course_code}' to session #{$session_id}");
                     }
                     $course_counter++;
                     $course_coaches = isset($courseArray[1]) ? $courseArray[1] : null;
                     $course_users = isset($courseArray[2]) ? $courseArray[2] : null;
                     $course_users = explode(',', $course_users);
                     $course_coaches = explode(',', $course_coaches);
                     // Checking if the flag is set TeachersWillBeAddedAsCoachInAllCourseSessions (course_edit.php)
                     $addTeachersToSession = true;
                     if (array_key_exists('add_teachers_to_sessions_courses', $courseInfo)) {
                         $addTeachersToSession = $courseInfo['add_teachers_to_sessions_courses'];
                     }
                     // If any user provided for a course, use the users array.
                     if (empty($course_users)) {
                         if (!empty($userList)) {
                             SessionManager::subscribe_users_to_session_course($userList, $session_id, $course_code);
                             if ($debug) {
                                 $msg = "Sessions - Adding student list " . implode(', #', $userList) . " to course: '{$course_code}' and session #{$session_id}";
                                 $logger->addInfo($msg);
                             }
                         }
                     }
                     // Adding coaches to session course user.
                     if (!empty($course_coaches)) {
                         $savedCoaches = array();
                         // only edit if add_teachers_to_sessions_courses is set.
                         if ($addTeachersToSession) {
                             if ($addOriginalCourseTeachersAsCourseSessionCoaches) {
                                 // Adding course teachers as course session teachers.
                                 $alreadyAddedTeachers = CourseManager::get_teacher_list_from_course_code($course_code);
                                 if (!empty($alreadyAddedTeachers)) {
                                     $teachersToAdd = array();
                                     foreach ($alreadyAddedTeachers as $user) {
                                         $teachersToAdd[] = $user['username'];
                                     }
                                     $course_coaches = array_merge($course_coaches, $teachersToAdd);
                                 }
                             }
                             foreach ($course_coaches as $course_coach) {
                                 $coach_id = UserManager::get_user_id_from_username($course_coach);
                                 if ($coach_id !== false) {
                                     // Just insert new coaches
                                     SessionManager::updateCoaches($session_id, $courseId, array($coach_id), false);
                                     if ($debug) {
                                         $logger->addInfo("Sessions - Adding course coach: user #{$coach_id} ({$course_coach}) to course: '{$course_code}' and session #{$session_id}");
                                     }
                                     $savedCoaches[] = $coach_id;
                                 } else {
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:67,代码来源:sessionmanager.lib.php


注:本文中的SessionManager::subscribe_users_to_session_course方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。