Ejemplo n.º 1
0
 /**
  * Gets the real session id based on the session id field name and value. Note that if the session id field name is "chamilo_session_id", it will use the session id
  * in the system database
  * 
  * @param string Session id field name
  * @param string Session id value
  * @return mixed System session id if the session was found, WSError otherwise
  */
 protected function getSessionId($session_id_field_name, $session_id_value)
 {
     if ($session_id_field_name == "chamilo_session_id") {
         $session = SessionManager::fetch((int) $session_id_value);
         if (!empty($session)) {
             return intval($session_id_value);
         } else {
             return new WSError(300, "Session not found");
         }
     } else {
         $session_id = SessionManager::get_session_id_from_original_id($session_id_value, $session_id_field_name);
         if ($session_id == 0) {
             return new WSError(300, "Session not found");
         } else {
             return $session_id;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Updates the session synchronize with the csv file.
  * @param string $file
  */
 private function importSessionsStatic($file)
 {
     $content = file($file);
     $sessions = array();
     if (!api_strstr($content[0], ';')) {
         $error_message = get_lang('NotCSV');
     } else {
         $tag_names = array();
         foreach ($content as $key => $enreg) {
             $enreg = explode(';', trim($enreg));
             if ($key) {
                 foreach ($tag_names as $tag_key => $tag_name) {
                     $sessions[$key - 1][$tag_name] = $enreg[$tag_key];
                 }
             } else {
                 foreach ($enreg as $tag_name) {
                     $tag_names[] = api_preg_replace('/[^a-zA-Z0-9_\\-]/', '', $tag_name);
                 }
                 if (!in_array('SessionName', $tag_names) || !in_array('DateStart', $tag_names) || !in_array('DateEnd', $tag_names)) {
                     $error_message = get_lang('NoNeededData');
                     break;
                 }
             }
         }
     }
     if (!empty($sessions)) {
         // Looping the sessions.
         foreach ($sessions as $session) {
             if (!empty($session['SessionID'])) {
                 $sessionId = SessionManager::get_session_id_from_original_id($session['SessionID'], $this->extraFieldIdNameList['session']);
                 $coachUserName = isset($session['Coach']) ? $session['Coach'] : null;
                 $categoryId = isset($session['category_id']) ? $session['category_id'] : null;
                 // 2014-06-30
                 $dateStart = explode('/', $session['DateStart']);
                 $dateEnd = explode('/', $session['DateEnd']);
                 $visibility = $this->defaultSessionVisibility;
                 $coachId = null;
                 if (!empty($coachUserName)) {
                     $coachInfo = api_get_user_info_from_username($coachUserName);
                     $coachId = $coachInfo['user_id'];
                 }
                 if (empty($sessionId)) {
                     $result = SessionManager::create_session($session['SessionName'], $dateStart[0], $dateStart[1], $dateStart[2], $dateEnd[0], $dateEnd[1], $dateEnd[2], $this->daysCoachAccessBeforeBeginning, $this->daysCoachAccessAfterBeginning, null, $coachUserName, $categoryId, $visibility, 1);
                     if (is_numeric($result)) {
                         $sessionId = $result;
                         SessionManager::update_session_extra_field_value($sessionId, $this->extraFieldIdNameList['session'], $session['SessionID']);
                     }
                 } else {
                     $sessionInfo = api_get_session_info($sessionId);
                     $accessBefore = null;
                     $accessAfter = null;
                     if (empty($sessionInfo['nb_days_access_before_beginning']) || !empty($sessionInfo['nb_days_access_before_beginning']) && $sessionInfo['nb_days_access_before_beginning'] < $this->daysCoachAccessBeforeBeginning) {
                         $accessBefore = intval($this->daysCoachAccessBeforeBeginning);
                     }
                     $accessAfter = null;
                     if (empty($sessionInfo['nb_days_access_after_end']) || !empty($sessionInfo['nb_days_access_after_end']) && $sessionInfo['nb_days_access_after_end'] < $this->daysCoachAccessAfterBeginning) {
                         $accessAfter = intval($this->daysCoachAccessAfterBeginning);
                     }
                     $showDescription = isset($sessionInfo['show_description']) ? $sessionInfo['show_description'] : 1;
                     $result = SessionManager::edit_session($sessionId, $session['SessionName'], $dateStart[0], $dateStart[1], $dateStart[2], $dateEnd[0], $dateEnd[1], $dateEnd[2], $accessBefore, $accessAfter, null, $coachId, $categoryId, $visibility, true, true, null, $showDescription);
                     if (is_numeric($result)) {
                         $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
                         $params = array('description' => $session['SessionDescription']);
                         Database::update($tbl_session, $params, array('id = ?' => $sessionId));
                     }
                 }
                 // Courses
                 $courses = explode('|', $session['Courses']);
                 $courseList = array();
                 foreach ($courses as $course) {
                     $courseArray = bracketsToArray($course);
                     $courseCode = $courseArray[0];
                     if (CourseManager::course_exists($courseCode)) {
                         $courseList[] = $courseCode;
                     }
                 }
                 SessionManager::add_courses_to_session($sessionId, $courseList, true);
                 if (!empty($sessionId)) {
                     $courses = explode('|', $session['Courses']);
                     foreach ($courses as $course) {
                         $courseArray = bracketsToArray($course);
                         $courseCode = $courseArray[0];
                         if (CourseManager::course_exists($courseCode)) {
                             // Coaches
                             $courseCoaches = isset($courseArray[1]) ? $courseArray[1] : null;
                             $courseCoaches = explode(',', $courseCoaches);
                             if (!empty($courseCoaches)) {
                                 $coachList = array();
                                 foreach ($courseCoaches as $courseCoach) {
                                     $courseCoachId = UserManager::get_user_id_from_username($courseCoach);
                                     if ($courseCoachId !== false) {
                                         // Just insert new coaches
                                         $coachList[] = $courseCoachId;
                                     }
                                 }
                                 SessionManager::updateCoaches($sessionId, $courseCode, $coachList, true);
                             }
                             // Students
                             $courseUsers = isset($courseArray[2]) ? $courseArray[2] : null;
                             $courseUsers = explode(',', $courseUsers);
                             if (!empty($courseUsers)) {
                                 $userList = array();
                                 foreach ($courseUsers as $username) {
                                     $userInfo = api_get_user_info_from_username(trim($username));
                                     if (!empty($userInfo)) {
                                         $userList[] = $userInfo['user_id'];
                                     }
                                 }
                                 SessionManager::subscribe_users_to_session_course($userList, $sessionId, $courseCode, SESSION_VISIBLE_READ_ONLY, true);
                             } else {
                                 $this->logger->addInfo("No users to register.");
                             }
                         } else {
                             $this->logger->addInfo("Course does not exists {$courseCode}");
                         }
                     }
                 } else {
                     $this->logger->addInfo('SessionID not found in system.');
                 }
             } else {
                 $this->logger->addInfo('SessionID does not exists');
             }
         }
     } else {
         $this->logger->addInfo($error_message);
     }
 }
Ejemplo n.º 3
0
/**
 * @param array $params
 * @return int|string
 */
function WSGetLpList($params)
{
    global $debug;
    if (!WSHelperVerifyKey($params)) {
        return return_error(WS_ERROR_SECRET_KEY);
    }
    require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpathList.class.php';
    require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpath.class.php';
    require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpathItem.class.php';
    $courseIdName = $params['course_id_name'];
    $courseIdValue = $params['course_id_value'];
    $sessionIdName = isset($params['session_id_name']) ? $params['session_id_name'] : null;
    $sessionIdValue = isset($params['session_id_value']) ? $params['session_id_value'] : null;
    $courseInfo = CourseManager::getCourseInfoFromOriginalId($courseIdValue, $courseIdName);
    if (empty($courseInfo)) {
        if ($debug) {
            error_log("Course not found: {$courseIdName} : {$courseIdValue}");
        }
        return 'Course not found';
    }
    $courseId = $courseInfo['real_id'];
    $sessionId = 0;
    if (!empty($sessionIdName) && !empty($sessionIdValue)) {
        $sessionId = SessionManager::get_session_id_from_original_id($sessionIdValue, $sessionIdName);
        if (empty($sessionId)) {
            if ($debug) {
                error_log('Session not found');
            }
            return 'Session not found';
        }
    }
    $list = new LearnpathList(null, $courseInfo['code'], $sessionId);
    $flatList = $list->get_flat_list();
    $result = array();
    foreach ($flatList as $id => $lp) {
        $result[] = array('id' => $id, 'name' => $lp['lp_name']);
    }
    return $result;
}