Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement - Session duration extension per user #6012

Open
wants to merge 1 commit into
base: 1.11.x
Choose a base branch
from

Conversation

juancp-contidosdixitais
Copy link

Issue #5638, currently, sessions can be configured with a duration in days. Once a student enrolls in a session, they can access it from their first login date until the maximum duration configured for the session.

The issue we encountered is that it is not possible to 'extend' the duration for individual users. To do so, the student would have to be removed and re-added to the session, resulting in the loss of their progress.

While reviewing the code to confirm this limitation, we discovered unused code suggesting that this functionality existed in the past. For example, there are functions that seem to validate this possibility:

/**
* Use the session duration to allow/block user access see BT#8317
* Needs these DB changes
* ALTER TABLE session ADD COLUMN duration int;
* ALTER TABLE session_rel_user ADD COLUMN duration int;.
*/
public static function durationPerUserIsEnabled()
{
return api_get_configuration_value('session_duration_feature');
}

/**
* Returns the number of days the student has left in a session when using
* sessions durations.
*
* @param int $userId
*
* @return int
*/
public static function getDayLeftInSession(array $sessionInfo, $userId)
{
$sessionId = $sessionInfo['id'];
$subscription = self::getUserSession($userId, $sessionId);
$duration = empty($subscription['duration'])
? $sessionInfo['duration']
: $sessionInfo['duration'] + $subscription['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 $duration;
}
$firstAccess = api_strtotime($courseAccess['login_course_date'], 'UTC');
$endDateInSeconds = $firstAccess + $duration * 24 * 60 * 60;
$leftDays = round(($endDateInSeconds - $currentTime) / 60 / 60 / 24);
return $leftDays;
}

/**
* @param int $duration
* @param int $userId
* @param int $sessionId
*
* @return bool
*/
public static function editUserSessionDuration($duration, $userId, $sessionId)
{
$duration = (int) $duration;
$userId = (int) $userId;
$sessionId = (int) $sessionId;
if (empty($userId) || empty($sessionId)) {
return false;
}
$table = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$parameters = ['duration' => $duration];
$where = ['session_id = ? AND user_id = ? ' => [$sessionId, $userId]];
Database::update($table, $parameters, $where);
return true;
}

/*
if (isset($sessionInfo['duration']) && !empty($sessionInfo['duration'])) {
$editUrl = $codePath . 'session/session_user_edit.php?session_id=' . $sessionId . '&user_id=' . $userId;
$editUrl = Display::url(
Display::return_icon('agenda.png', get_lang('SessionDurationEdit')),
$editUrl
);
}*/

This PR repurposes some of that unused code to enable the functionality of extending session durations for individual users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants