Skip to content

Commit

Permalink
Add Session Reminder Option for User Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
fhelfer committed Jul 23, 2024
1 parent d90b33f commit 3c94d59
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public static function isGloballyActivated(): bool
);
}

public static function getMaxLeadTime(): int
{
$expires = ilSession::getSessionExpireValue();
return max(self::MIN_LEAD_TIME, ($expires / 60) - 1);
}
public function __construct(ilObjUser $user, ClockInterface $clock)
{
$this->user = $user;
Expand All @@ -82,10 +87,15 @@ public function __construct(ilObjUser $user, ClockInterface $clock)

private function init(): void
{
/** @var ilSetting $ilSetting */
global $DIC;

$ilSetting = $DIC['ilSetting'];

$this->setLeadTime(
((int) max(
self::MIN_LEAD_TIME,
(float) $this->getUser()->getPref('session_reminder_lead_time')
(float) $this->getUser()->getPref('session_reminder_lead_time') ?: $ilSetting->get('session_reminder')
)) * 60
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function __construct(
ilDBInterface $db,
ilIniFile $clientIni,
ilLogger $logger,
ClockInterface $utcClock
ClockInterface $utcClock,
private ilSetting $settings
) {
$this->http = $http;
$this->refinery = $refinery;
Expand Down Expand Up @@ -113,7 +114,7 @@ public function handle(): ResponseInterface

$reminderTime = $expirationTime - ((int) max(
ilSessionReminder::MIN_LEAD_TIME,
(float) $ilUser->getPref('session_reminder_lead_time')
(float) $ilUser->getPref('session_reminder_lead_time') ?: $this->settings->get('session_reminder')
)) * 60;
if ($reminderTime > $this->clock->now()->getTimestamp()) {
// session will expire in <lead_time> minutes
Expand Down
7 changes: 4 additions & 3 deletions components/ILIAS/Authentication/resources/sessioncheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use ILIAS\Data\Factory as DataFactory;

if (!file_exists(getcwd() . '/ilias.ini.php')) {
exit();
exit;
}

ilContext::init(ilContext::CONTEXT_SESSION_REMINDER);
Expand All @@ -38,9 +38,10 @@
$DIC->database(),
$DIC['ilClientIniFile'],
$DIC->logger()->auth(),
(new DataFactory())->clock()->utc()
(new DataFactory())->clock()->utc(),
$DIC->settings()
)
)->handle()
);
$DIC->http()->sendResponse();
$DIC->http()->close();
$DIC->http()->close();
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,19 @@ class ilUserProfileDefaultFields
'prg_export_hide' => true,
'search_hide' => true,
'group' => 'settings'
],
'session_reminder' => [
'input' => 'session_reminder_lead_time',
'default' => 'y',
'visible_hide' => true,
'visib_lua_hide' => true,
'required_hide' => true,
'visib_reg_hide' => true,
'course_export_hide' => true,
'group_export_hide' => true,
'prg_export_hide' => true,
'search_hide' => true,
'group' => 'settings'
]
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,27 +297,23 @@ public function initGeneralSettingsForm(): void
$this->form->addItem($lv);

if (ilSessionReminder::isGloballyActivated()) {
$cb = new ilCheckboxInputGUI($this->lng->txt('session_reminder'), 'session_reminder_enabled');
$cb->setInfo($this->lng->txt('session_reminder_info'));
$cb->setValue('1');
$cb->setChecked((bool) $this->user->getPref('session_reminder_enabled'));

$expires = ilSession::getSessionExpireValue();
$lead_time_gui = new ilNumberInputGUI(
$this->lng->txt('session_reminder_lead_time'),
$session_reminder = new ilNumberInputGUI(
$this->lng->txt('session_reminder'),
'session_reminder_lead_time'
);
$lead_time_gui->setInfo(
$expires = ilSession::getSessionExpireValue();
$session_reminder->setInfo(
sprintf(
$this->lng->txt('session_reminder_lead_time_info'),
ilDatePresentation::secondsToString($expires, true)
)
);
$session_reminder->setDisabled(!$this->workWithUserSetting('session_reminder'));

$min_value = ilSessionReminder::MIN_LEAD_TIME;
$max_value = max($min_value, ($expires / 60) - 1);
$max_value = ilSessionReminder::getMaxLeadTime();

$current_user_value = $this->user->getPref('session_reminder_lead_time');
$current_user_value = $this->user->getPref('session_reminder_lead_time') ?: $this->settings->get('session_reminder');
if ($current_user_value < $min_value || $current_user_value > $max_value) {
$current_user_value = ilSessionReminder::SUGGESTED_LEAD_TIME;
}
Expand All @@ -328,14 +324,13 @@ public function initGeneralSettingsForm(): void
),
$max_value
);

$lead_time_gui->setValue((string) $value);
$lead_time_gui->setSize(3);
$lead_time_gui->setMinValue($min_value);
$lead_time_gui->setMaxValue($max_value);
$cb->addSubItem($lead_time_gui);

$this->form->addItem($cb);
$session_reminder->setValue(
(string) $value
);
$session_reminder->setSize(3);
$session_reminder->setMinValue($min_value);
$session_reminder->setMaxValue($max_value);
$this->form->addItem($session_reminder);
}

// calendar settings (copied here to be reachable when calendar is inactive)
Expand Down Expand Up @@ -461,8 +456,7 @@ public function saveGeneralSettings(): void
}
}

if (ilSessionReminder::isGloballyActivated()) {
$this->user->setPref('session_reminder_enabled', $this->form->getInput('session_reminder_enabled'));
if (ilSessionReminder::isGloballyActivated() && $this->workWithUserSetting('session_reminder')) {
$this->user->setPref(
'session_reminder_lead_time',
(string) $this->form->getInput('session_reminder_lead_time')
Expand Down
5 changes: 5 additions & 0 deletions components/ILIAS/User/classes/class.UserGUIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public function getSelect(): array
return $this->strArray('select');
}

public function getInput(): array
{
return $this->strArray('input');
}

public function getFiles(): array
{
return $this->strArray('file');
Expand Down
8 changes: 8 additions & 0 deletions components/ILIAS/User/classes/class.ilObjUserFolderGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,7 @@ public function saveGlobalUserSettingsObject(string $action = ''): void
{
$checked = $this->user_request->getChecked();
$selected = $this->user_request->getSelect();
$input = $this->user_request->getInput();

$user_settings_config = $this->user_settings_config;

Expand Down Expand Up @@ -2600,6 +2601,13 @@ public function saveGlobalUserSettingsObject(string $action = ''): void
);
}

if (isset($input['default_session_reminder'])) {
$this->ilias->setSetting(
'session_reminder',
$input['default_session_reminder']
);
}

$this->tpl->setOnScreenMessage('success', $this->lng->txt('usr_settings_saved'));
$this->settingsObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,30 @@ protected function fillRow(array $a_set): void
$this->tpl->setCurrentBlock("def_selection");
$this->tpl->setVariable("PROFILE_OPTION_DEFAULT_VALUE", "default_" . $field);
$this->tpl->parseCurrentBlock();
break;
case 'session_reminder_lead_time':
$this->tpl->setCurrentBlock('def_input');
$expires = ilSession::getSessionExpireValue();
$min_value = ilSessionReminder::MIN_LEAD_TIME;
$max_value = ilSessionReminder::getMaxLeadTime();

$current_user_value = $ilSetting->get('session_reminder');
if ($current_user_value < $min_value || $current_user_value > $max_value) {
$current_user_value = ilSessionReminder::SUGGESTED_LEAD_TIME;
}
$value = min(
max(
$min_value,
$current_user_value
),
$max_value
);
$this->tpl->setVariable('PROFILE_OPTION_DEFAULT_VALUE', 'default_' . $field);
$this->tpl->setVariable('CURRENT_OPTION_VISIBLE', $value);
$this->tpl->setVariable('CURRENT_OPTION_MAXIMUM', $max_value);

$this->tpl->parseCurrentBlock();

break;
}
$this->tpl->setCurrentBlock("default");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@
<option value="{OPTION_VALUE}" {OPTION_SELECTED}>{OPTION_TEXT}</option>
<!-- END def_sel_option -->
</select>
<!-- END def_selection -->
<!-- END def_selection -->
<!-- BEGIN def_input -->
<input type="number" class="form-control" name="input[{PROFILE_OPTION_DEFAULT_VALUE}]" value="{CURRENT_OPTION_VISIBLE}" max="{CURRENT_OPTION_MAXIMUM}" />
<!-- END def_input -->
<!-- END default -->
<!-- BEGIN action -->
<div><a class="il_ContainerItemCommand" href="{HREF_CMD}">{TXT_CMD}</a></div>
Expand Down

0 comments on commit 3c94d59

Please sign in to comment.