本文整理汇总了PHP中CourseManager::getFirstCourseAccessPerSessionAndUser方法的典型用法代码示例。如果您正苦于以下问题:PHP CourseManager::getFirstCourseAccessPerSessionAndUser方法的具体用法?PHP CourseManager::getFirstCourseAccessPerSessionAndUser怎么用?PHP CourseManager::getFirstCourseAccessPerSessionAndUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CourseManager
的用法示例。
在下文中一共展示了CourseManager::getFirstCourseAccessPerSessionAndUser方法的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 {
//.........这里部分代码省略.........
示例2: getDayLeftInSession
/**
* Returns the number of days the student has left in a session when using
* sessions durations
* @param int $userId
* @param int $sessionId
* @param int $duration in days
* @return int
*/
public static function getDayLeftInSession($sessionId, $userId, $duration)
{
// Get an array with the details of the first access of the student to
// this session
$courseAccess = CourseManager::getFirstCourseAccessPerSessionAndUser($sessionId, $userId);
$currentTime = time();
// If no previous access, return false
if (count($courseAccess) == 0) {
return false;
}
$firstAccess = api_strtotime($courseAccess['login_course_date'], 'UTC');
$endDateInSeconds = $firstAccess + $duration * 24 * 60 * 60;
$leftDays = round(($endDateInSeconds - $currentTime) / 60 / 60 / 24);
return $leftDays;
}
示例3: api_not_allowed
}
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');
if ($days > 0) {
$msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateInZDays'), $firstAccessString, $duration, $days);
} else {
示例4: getDayLeftInSession
/**
* @param int $userId
* @param int $sessionId
* @param int $duration in days
* @return int
*/
public static function getDayLeftInSession($sessionId, $userId, $duration)
{
$courseAccess = CourseManager::getFirstCourseAccessPerSessionAndUser($sessionId, $userId);
$currentTime = time();
$firstAccess = api_strtotime($courseAccess['login_course_date'], 'UTC');
$endDateInSeconds = $firstAccess + $duration * 24 * 60 * 60;
$leftDays = round(($endDateInSeconds - $currentTime) / 60 / 60 / 24);
return $leftDays;
}
示例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;
//.........这里部分代码省略.........