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


PHP SessionManager::getUserSession方法代码示例

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


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

示例1: api_get_session_visibility

/**
 * Gets the session visibility by session id
 * @param int $session_id
 * @param int $courseId
 * @param bool $ignore_visibility_for_admins
 * @return int
 *  0 = session still available,
 *  SESSION_VISIBLE_READ_ONLY = 1,
 *  SESSION_VISIBLE = 2,
 *  SESSION_INVISIBLE = 3
 */
function api_get_session_visibility($session_id, $courseId = null, $ignore_visibility_for_admins = true)
{
    // Means that the session is still available.
    $visibility = 0;
    if (api_is_platform_admin()) {
        if ($ignore_visibility_for_admins) {
            return SESSION_AVAILABLE;
        }
    }
    $now = time();
    if (!empty($session_id)) {
        $session_id = intval($session_id);
        $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
        $sql = "SELECT * FROM {$tbl_session}\n                WHERE id = {$session_id} ";
        $result = Database::query($sql);
        if (Database::num_rows($result) > 0) {
            $row = Database::fetch_array($result, 'ASSOC');
            $visibility = $original_visibility = $row['visibility'];
            // I don't care the session visibility.
            if (empty($row['access_start_date']) && empty($row['access_end_date'])) {
                // Session duration per student.
                if (isset($row['duration']) && !empty($row['duration'])) {
                    $duration = $row['duration'] * 24 * 60 * 60;
                    $courseAccess = CourseManager::getFirstCourseAccessPerSessionAndUser($session_id, api_get_user_id());
                    // If there is a session duration but there is no previous
                    // access by the user, then the session is still available
                    if (count($courseAccess) == 0) {
                        return SESSION_AVAILABLE;
                    }
                    $currentTime = time();
                    $firstAccess = 0;
                    if (isset($courseAccess['login_course_date'])) {
                        $firstAccess = api_strtotime($courseAccess['login_course_date'], 'UTC');
                    }
                    $userDurationData = SessionManager::getUserSession(api_get_user_id(), $session_id);
                    $userDuration = 0;
                    if (isset($userDurationData['duration'])) {
                        $userDuration = intval($userDurationData['duration']) * 24 * 60 * 60;
                    }
                    $totalDuration = $firstAccess + $duration + $userDuration;
                    if ($totalDuration > $currentTime) {
                        return SESSION_AVAILABLE;
                    } else {
                        return SESSION_INVISIBLE;
                    }
                }
                return SESSION_AVAILABLE;
            } else {
                // If start date was set.
                if (!empty($row['access_start_date'])) {
                    if ($now > api_strtotime($row['access_start_date'], 'UTC')) {
                        $visibility = SESSION_AVAILABLE;
                    } else {
                        $visibility = SESSION_INVISIBLE;
                    }
                }
                // If the end date was set.
                if (!empty($row['access_end_date'])) {
                    // Only if date_start said that it was ok
                    if ($visibility == SESSION_AVAILABLE) {
                        if ($now < api_strtotime($row['access_end_date'], 'UTC')) {
                            // Date still available
                            $visibility = SESSION_AVAILABLE;
                        } else {
                            // Session ends
                            $visibility = $row['visibility'];
                        }
                    }
                }
            }
            /* If I'm a coach the visibility can change in my favor depending in
               the coach dates */
            $is_coach = api_is_coach($session_id, $courseId);
            if ($is_coach) {
                // Test end date.
                if (!empty($row['coach_access_end_date'])) {
                    $endDateCoach = api_strtotime($row['coach_access_end_date'], 'UTC');
                    if ($endDateCoach >= $now) {
                        $visibility = SESSION_AVAILABLE;
                    } else {
                        $visibility = SESSION_INVISIBLE;
                    }
                }
                // Test start date.
                if (!empty($row['coach_access_start_date'])) {
                    $start = api_strtotime($row['coach_access_start_date'], 'UTC');
                    if ($start < $now) {
                        $visibility = SESSION_AVAILABLE;
                    } else {
//.........这里部分代码省略.........
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:101,代码来源:api.lib.php

示例2: get_session_title_box

 /**
  * Get the session box details as an array
  * @param int       Session ID
  * @return array    Empty array or session array ['title'=>'...','category'=>'','dates'=>'...','coach'=>'...','active'=>true/false,'session_category_id'=>int]
  */
 public static function get_session_title_box($session_id)
 {
     global $nosession;
     if (!$nosession) {
         global $now, $date_start, $date_end;
     }
     $output = array();
     if (!$nosession) {
         $main_user_table = Database::get_main_table(TABLE_MAIN_USER);
         $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
         $active = false;
         // Request for the name of the general coach
         $sql = 'SELECT tu.lastname, tu.firstname, ts.*
                 FROM ' . $tbl_session . ' ts  LEFT JOIN ' . $main_user_table . ' tu ON ts.id_coach = tu.user_id
                 WHERE ts.id = ' . intval($session_id);
         $rs = Database::query($sql);
         $session_info = Database::store_result($rs, 'ASSOC');
         $session_info = $session_info[0];
         $session = array();
         $session['title'] = $session_info['name'];
         $session['coach'] = '';
         $session['dates'] = '';
         if ($session_info['date_end'] == '0000-00-00' && $session_info['date_start'] == '0000-00-00') {
             if (api_get_setting('show_session_coach') === 'true') {
                 $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($session_info['firstname'], $session_info['lastname']);
             }
             if (isset($session_info['duration']) && !empty($session_info['duration'])) {
                 $userDurationData = SessionManager::getUserSession(api_get_user_id(), $session_id);
                 $userDuration = 0;
                 if (isset($userDurationData['duration'])) {
                     $userDuration = intval($userDurationData['duration']);
                 }
                 $totalDuration = $session_info['duration'] + $userDuration;
                 $daysLeft = SessionManager::getDayLeftInSession($session_id, api_get_user_id(), $totalDuration);
                 $session['duration'] = sprintf(get_lang('SessionDurationXDaysLeft'), $daysLeft);
             }
             $active = true;
         } else {
             $start = $stop = false;
             $start_buffer = $stop_buffer = '';
             if ($session_info['date_start'] == '0000-00-00') {
                 $session_info['date_start'] = '';
             } else {
                 $start = true;
                 $start_buffer = $session_info['date_start'];
                 $session_info['date_start'] = get_lang('From') . ' ' . $session_info['date_start'];
             }
             if ($session_info['date_end'] == '0000-00-00') {
                 $session_info['date_end'] = '';
             } else {
                 $stop = true;
                 $stop_buffer = $session_info['date_end'];
                 $session_info['date_end'] = get_lang('Until') . ' ' . $session_info['date_end'];
             }
             if ($start && $stop) {
                 $session['dates'] = Display::tag('i', sprintf(get_lang('FromDateXToDateY'), $start_buffer, $stop_buffer));
             } else {
                 $session['dates'] = Display::tag('i', $session_info['date_start'] . ' ' . $session_info['date_end']);
             }
             if (api_get_setting('show_session_coach') === 'true') {
                 $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($session_info['firstname'], $session_info['lastname']);
             }
             $active = $date_start <= $now && $date_end >= $now;
         }
         $session['active'] = $active;
         $session['session_category_id'] = $session_info['session_category_id'];
         if (array_key_exists('show_description', $session_info)) {
             if (!empty($session_info['show_description'])) {
                 $session['description'] = $session_info['description'];
             }
         }
         $output = $session;
     }
     return $output;
 }
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:80,代码来源:display.lib.php

示例3: api_not_allowed

}
if (!isset($sessionInfo['duration']) || isset($sessionInfo['duration']) && empty($sessionInfo['duration'])) {
    api_not_allowed(true);
}
if (!SessionManager::durationPerUserIsEnabled()) {
    api_not_allowed(true);
}
if (empty($sessionId) || empty($userId)) {
    api_not_allowed(true);
}
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'session_list.php', 'name' => get_lang('SessionList'));
$interbreadcrumb[] = array('url' => "resume_session.php?id_session=" . $sessionId, "name" => get_lang('SessionOverview'));
$form = new FormValidator('edit', 'post', api_get_self() . '?session_id=' . $sessionId . '&user_id=' . $userId);
$form->add_header(get_lang('EditUserSessionDuration'));
$data = SessionManager::getUserSession($userId, $sessionId);
$userInfo = api_get_user_info($userId);
// Show current end date for the session for this user, if any
$userAccess = CourseManager::getFirstCourseAccessPerSessionAndUser($sessionId, $userId);
if (count($userAccess) == 0) {
    // User never accessed the session. End date is still open
    $msg = sprintf(get_lang('UserNeverAccessedSessionDefaultDurationIsX'), $sessionInfo['duration']);
} else {
    // The user already accessed the session. Show a clear detail of the days count.
    $duration = $sessionInfo['duration'];
    if (!empty($data['duration'])) {
        $duration = $duration + $data['duration'];
    }
    $days = SessionManager::getDayLeftInSession($sessionId, $userId, $duration);
    $firstAccess = api_strtotime($userAccess['login_course_date'], 'UTC');
    $firstAccessString = api_convert_and_format_date($userAccess['login_course_date'], DATE_FORMAT_SHORT, 'UTC');
开发者ID:ragebat,项目名称:chamilo-lms,代码行数:31,代码来源:session_user_edit.php

示例4: get_session_title_box

 /**
  * Get the session box details as an array
  * @param int       Session ID
  * @return array    Empty array or session array
  * ['title'=>'...','category'=>'','dates'=>'...','coach'=>'...','active'=>true/false,'session_category_id'=>int]
  */
 public static function get_session_title_box($session_id)
 {
     global $nosession;
     if (!$nosession) {
         global $now, $date_start, $date_end;
     }
     $output = array();
     if (!$nosession) {
         $main_user_table = Database::get_main_table(TABLE_MAIN_USER);
         $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
         $active = false;
         // Request for the name of the general coach
         $sql = 'SELECT tu.lastname, tu.firstname, ts.*
                 FROM ' . $tbl_session . ' ts
                 LEFT JOIN ' . $main_user_table . ' tu
                 ON ts.id_coach = tu.user_id
                 WHERE ts.id = ' . intval($session_id);
         $rs = Database::query($sql);
         $session_info = Database::store_result($rs, 'ASSOC');
         $session_info = $session_info[0];
         $session = array();
         $session['title'] = $session_info['name'];
         $session['coach'] = '';
         $session['dates'] = '';
         if ($session_info['access_end_date'] == '0000-00-00' && $session_info['access_start_date'] == '0000-00-00' || empty($session_info['access_end_date']) && empty($session_info['access_start_date'])) {
             if (api_get_setting('session.show_session_coach') === 'true') {
                 $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($session_info['firstname'], $session_info['lastname']);
             }
             if (isset($session_info['duration']) && !empty($session_info['duration'])) {
                 $userDurationData = SessionManager::getUserSession(api_get_user_id(), $session_id);
                 $userDuration = 0;
                 if (isset($userDurationData['duration'])) {
                     $userDuration = intval($userDurationData['duration']);
                 }
                 $totalDuration = $session_info['duration'] + $userDuration;
                 $daysLeft = SessionManager::getDayLeftInSession($session_id, api_get_user_id(), $totalDuration);
                 $session['duration'] = sprintf(get_lang('SessionDurationXDaysLeft'), $daysLeft);
             }
             $active = true;
         } else {
             $start = $stop = false;
             $start_buffer = $stop_buffer = '';
             if ($session_info['access_start_date'] == '0000-00-00' || empty($session_info['access_start_date'])) {
                 $session_info['access_start_date'] = '';
             } else {
                 $start = true;
                 $start_buffer = $session_info['access_start_date'];
                 $session_info['access_start_date'] = $session_info['access_start_date'];
             }
             if ($session_info['access_end_date'] == '0000-00-00' || empty($session_info['access_end_date'])) {
                 $session_info['access_end_date'] = '';
             } else {
                 $stop = true;
                 $stop_buffer = $session_info['access_end_date'];
                 $session_info['access_end_date'] = $session_info['access_end_date'];
             }
             if ($start && $stop) {
                 $session['dates'] = Display::tag('em', sprintf(get_lang('FromDateXToDateY'), api_format_date($start_buffer), api_format_date($stop_buffer)));
             } else {
                 $start_buffer = $stop_buffer = null;
                 if (!empty($session_info['access_start_date'])) {
                     $start_buffer = sprintf(get_lang('FromDateX'), api_format_date($session_info['access_start_date']));
                 }
                 if (!empty($session_info['access_end_date'])) {
                     $stop_buffer = sprintf(get_lang('UntilDateX'), api_format_date($session_info['access_end_date']));
                 }
                 $session['dates'] = Display::tag('em', "{$start_buffer} {$stop_buffer}");
             }
             if (api_get_setting('session.show_session_coach') === 'true') {
                 $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($session_info['firstname'], $session_info['lastname']);
             }
             $active = $date_start <= $now && $date_end >= $now;
         }
         $session['active'] = $active;
         $session['session_category_id'] = $session_info['session_category_id'];
         $session['description'] = $session_info['description'];
         $session['show_description'] = $session_info['show_description'];
         $entityManager = Database::getManager();
         $fieldValuesRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraFieldValues');
         $extraFieldValues = $fieldValuesRepo->getVisibleValues(Chamilo\CoreBundle\Entity\ExtraField::SESSION_FIELD_TYPE, $session_id);
         $session['extra_fields'] = [];
         foreach ($extraFieldValues as $value) {
             $session['extra_fields'][] = ['field' => ['variable' => $value->getField()->getVariable(), 'display_text' => $value->getField()->getDisplayText()], 'value' => $value->getValue()];
         }
         $output = $session;
     }
     return $output;
 }
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:94,代码来源:display.lib.php

示例5: api_get_session_visibility

/**
 * Gets the session visibility by session id
 * @param int $session_id
 * @param string $course_code
 * @param bool $ignore_visibility_for_admins
 * @return int
 *  0 = session still available,
 *  SESSION_VISIBLE_READ_ONLY = 1,
 *  SESSION_VISIBLE = 2,
 *  SESSION_INVISIBLE = 3
 */
function api_get_session_visibility($session_id, $course_code = null, $ignore_visibility_for_admins = true)
{
    // Means that the session is still available.
    $visibility = 0;
    if (api_is_platform_admin()) {
        if ($ignore_visibility_for_admins) {
            return SESSION_AVAILABLE;
        }
    }
    $now = time();
    if (!empty($session_id)) {
        $session_id = intval($session_id);
        $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
        $sql = "SELECT * FROM {$tbl_session}\n                WHERE id = {$session_id} ";
        $result = Database::query($sql);
        if (Database::num_rows($result) > 0) {
            $row = Database::fetch_array($result, 'ASSOC');
            $visibility = $original_visibility = $row['visibility'];
            // I don't care the session visibility.
            if ($row['date_start'] == '0000-00-00' && $row['date_end'] == '0000-00-00') {
                // Session duration per student.
                if (SessionManager::durationPerUserIsEnabled()) {
                    if (isset($row['duration']) && !empty($row['duration'])) {
                        $duration = $row['duration'] * 24 * 60 * 60;
                        $courseAccess = CourseManager::getFirstCourseAccessPerSessionAndUser($session_id, api_get_user_id());
                        // If there is a session duration but there is no previous
                        // access by the user, then the session is still available
                        if (count($courseAccess) == 0) {
                            return SESSION_AVAILABLE;
                        }
                        $currentTime = time();
                        $firstAccess = 0;
                        if (isset($courseAccess['login_course_date'])) {
                            $firstAccess = api_strtotime($courseAccess['login_course_date'], 'UTC');
                        }
                        $userDurationData = SessionManager::getUserSession(api_get_user_id(), $session_id);
                        $userDuration = 0;
                        if (isset($userDurationData['duration'])) {
                            $userDuration = intval($userDurationData['duration']) * 24 * 60 * 60;
                        }
                        $totalDuration = $firstAccess + $duration + $userDuration;
                        if ($totalDuration > $currentTime) {
                            return SESSION_AVAILABLE;
                        } else {
                            return SESSION_INVISIBLE;
                        }
                    }
                }
                return SESSION_AVAILABLE;
            } else {
                // If start date was set.
                if (!empty($row['date_start']) && $row['date_start'] != '0000-00-00') {
                    // The beginning of the day starts at 00:00:00
                    $row['date_start'] = $row['date_start'] . ' 00:00:00';
                    if ($now > api_strtotime($row['date_start'], 'UTC')) {
                        $visibility = SESSION_AVAILABLE;
                    } else {
                        $visibility = SESSION_INVISIBLE;
                    }
                }
                // If the end date was set.
                if (!empty($row['date_end']) && $row['date_end'] != '0000-00-00') {
                    // End date finish at midnight.
                    $row['date_end'] = $row['date_end'] . ' 23:59:59';
                    // Only if date_start said that it was ok
                    if ($visibility == SESSION_AVAILABLE) {
                        if ($now < api_strtotime($row['date_end'], 'UTC')) {
                            // Date still available
                            $visibility = SESSION_AVAILABLE;
                        } else {
                            // Session ends
                            $visibility = $row['visibility'];
                        }
                    }
                }
            }
            /* If I'm a coach the visibility can change in my favor depending in
               the nb_days_access_after_end and nb_days_access_before_beginning */
            $is_coach = api_is_coach($session_id, $course_code);
            if ($is_coach) {
                // Test end date.
                if (isset($row['date_end']) && !empty($row['date_end']) && $row['date_end'] != '0000-00-00' && $row['nb_days_access_after_end'] != '0') {
                    $end_date_for_coach = new DateTime(substr($row['date_end'], 0, 10) . ' 23:59:59');
                    $number_of_days = "P" . intval($row['nb_days_access_after_end']) . 'D';
                    $end_date_for_coach->add(new DateInterval($number_of_days));
                    if ($end_date_for_coach->getTimestamp() >= $now) {
                        $visibility = SESSION_AVAILABLE;
                    } else {
                        $visibility = SESSION_INVISIBLE;
//.........这里部分代码省略.........
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:101,代码来源:main_api.lib.php


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