Skip to content

Commit d808c28

Browse files
Session: Enable user session duration extension days (#6012)
Author: juancpbinario <juan.cortizas@almabinaria.com>
1 parent e16b303 commit d808c28

File tree

2 files changed

+64
-14
lines changed

2 files changed

+64
-14
lines changed

main/session/resume_session.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,14 @@
434434
}
435435

436436
$editUrl = null;
437-
/*
437+
438438
if (isset($sessionInfo['duration']) && !empty($sessionInfo['duration'])) {
439439
$editUrl = $codePath . 'session/session_user_edit.php?session_id=' . $sessionId . '&user_id=' . $userId;
440440
$editUrl = Display::url(
441441
Display::return_icon('agenda.png', get_lang('SessionDurationEdit')),
442442
$editUrl
443443
);
444-
}*/
444+
}
445445

446446
$table->setCellContents($row, 0, $userLink);
447447
$link = $reportingLink.$courseUserLink.$removeLink.$addUserToUrlLink.$editUrl;

main/session/session_user_edit.php

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@
4343
$userId
4444
);
4545

46+
$extension = 0;
47+
4648
if (count($userAccess) == 0) {
4749
// User never accessed the session. End date is still open
4850
$msg = sprintf(get_lang('UserNeverAccessedSessionDefaultDurationIsX'), $sessionInfo['duration']);
4951
} else {
5052
// The user already accessed the session. Show a clear detail of the days count.
53+
$duration = $sessionInfo['duration'];
5154
$days = SessionManager::getDayLeftInSession($sessionInfo, $userId);
55+
$userSubscription = SessionManager::getUserSession($userId, $sessionId);
56+
$extension = $userSubscription['duration'];
5257
$firstAccess = api_strtotime($userAccess['login_course_date'], 'UTC');
5358
$firstAccessString = api_convert_and_format_date($userAccess['login_course_date'], DATE_FORMAT_SHORT, 'UTC');
5459
if ($days > 0) {
@@ -61,29 +66,74 @@
6166

6267
$msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateInZDays'), $firstAccessString, $duration, $days);
6368
} else {
69+
if (!empty($subscription['duration'])) {
70+
$duration = $duration + $subscription['duration'];
71+
}
6472
$endDateInSeconds = $firstAccess + $duration * 24 * 60 * 60;
6573
$last = api_convert_and_format_date($endDateInSeconds, DATE_FORMAT_SHORT);
6674
$msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateWasZ'), $firstAccessString, $duration, $last);
6775
}
6876
}
69-
$form->addElement('html', sprintf(get_lang('UserXSessionY'), $userInfo['complete_name'], $sessionInfo['name']));
70-
$form->addElement('html', '<br>');
71-
$form->addElement('html', $msg);
7277

73-
$form->addElement('text', 'duration', [get_lang('ExtraDurationForUser'), null, get_lang('Days')]);
78+
$header = '<div class="row">';
79+
$header .= '<div class="col-sm-5">';
80+
$header .= '<div class="thumbnail">';
81+
$header .= Display::img($userInfo['avatar'], $userInfo['complete_name']);
82+
$header .= '</div>';
83+
$header .= '</div>';
84+
85+
$header .= '<div class="col-sm-7">';
86+
87+
$userData = $userInfo['complete_name']
88+
.PHP_EOL
89+
.$user_info['mail']
90+
.PHP_EOL
91+
.$user_info['official_code'];
92+
93+
$header .= '<h3>Usuario: ' . Display::url(
94+
$userData,
95+
api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user_info['user_id']
96+
) .'</h3>';
97+
98+
$header .= '<p><h3>Sesión: ' . $sessionInfo['name'] . '<h3></p>';
99+
100+
$header .= '</div>';
101+
$header .='</div>';
102+
103+
$header .= '<div class="row">';
104+
$header .= '<div class="col-sm-12">';
105+
106+
$header .= $msg;
107+
$header .= '<p>'.'</p>';
108+
109+
$header .= '</div>';
110+
$header .= '</div>';
111+
112+
$form->addElement('html', $header);
113+
114+
$formData = '<div class="row">';
115+
$formData .= '<div class="col-sm-12">';
116+
117+
$form->addElement('html', $formData);
118+
$form->addElement('number', 'duration', [get_lang('ExtraDurationForUser'), null, get_lang('Days')]);
74119
$form->addButtonSave(get_lang('Save'));
75120

76-
$form->setDefaults(['duration' => 0]);
121+
$formData = '</div>';
122+
$formData .= '</div>';
123+
124+
$form->addElement('html', $formData);
125+
126+
$form->setDefaults(['duration' => $extension]);
77127
$message = null;
78128
if ($form->validate()) {
79129
$duration = $form->getSubmitValue('duration');
80-
// Only update if the duration is different from the default duration
81-
if ($duration != 0) {
82-
SessionManager::editUserSessionDuration($duration, $userId, $sessionId);
83-
$message = Display::return_message(get_lang('ItemUpdated'), 'confirmation');
84-
} else {
85-
$message = Display::return_message(get_lang('DurationIsSameAsDefault'), 'warning');
86-
}
130+
131+
SessionManager::editUserSessionDuration($duration, $userId, $sessionId);
132+
$message = Display::return_message(get_lang('ItemUpdated'), 'confirmation');
133+
134+
$url = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
135+
header("Location: " . $url);
136+
exit();
87137
}
88138

89139
// display the header

0 commit comments

Comments
 (0)