Skip to content

Commit

Permalink
Session Reminder Lead Time Changeable in LUA
Browse files Browse the repository at this point in the history
  • Loading branch information
fhelfer committed Aug 20, 2024
1 parent d6b140f commit 44b26e4
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 123 deletions.
51 changes: 41 additions & 10 deletions components/ILIAS/Authentication/classes/class.ilSessionReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

declare(strict_types=1);

use ILIAS\Data\Factory as DataFactory;
use ILIAS\Data\Clock\ClockInterface;
use ILIAS\Data\Factory as DataFactory;

class ilSessionReminder
{
public const MIN_LEAD_TIME = 2;
public const SUGGESTED_LEAD_TIME = 5;

private ClockInterface $clock;
private ilObjUser $user;
private int $lead_time = self::SUGGESTED_LEAD_TIME;
Expand Down Expand Up @@ -53,14 +52,47 @@ public static function byLoggedInUser(): self
return $reminder;
}

public static function isGloballyActivated(): bool
public static function getGlobalSessionReminderLeadTime(): int
{
/** @var ilSetting $ilSetting */
global $DIC;

$ilSetting = $DIC['ilSetting'];

return (bool) $ilSetting->get('session_reminder_enabled');
return self::getAcceptableLeadTime(
(int) $ilSetting->get('session_reminder_lead_time')
);
}

private static function getAcceptableLeadTime(int $lead_time): int
{
$min_value = 0;
$max_value = self::getMaxLeadTime();

if ($lead_time < $min_value || $lead_time > $max_value) {
$lead_time = self::SUGGESTED_LEAD_TIME;
}

return min(
max(
$min_value,
$lead_time
),
$max_value
);
}

public static function getLocalSessionLeadTime(int $user_id): int
{
return self::getAcceptableLeadTime(
(int) ilObjUser::_lookupPref(
$user_id,
'session_reminder_lead_time'
) ?: self::getGlobalSessionReminderLeadTime()
);
}

public static function isLocallyActivated(int $user_id): bool
{
return self::getLocalSessionLeadTime($user_id) > 0;
}

public static function getMaxLeadTime(): int
Expand Down Expand Up @@ -114,13 +146,12 @@ private function isEnoughTimeLeftForReminder(): bool

public function isActive(): bool
{
return (
self::isGloballyActivated() &&
return
!$this->getUser()->isAnonymous() &&
$this->getUser()->getId() > 0 &&
(int) $this->getUser()->getPref('session_reminder_enabled') &&
self::isLocallyActivated($this->getUser()->getId()) &&
$this->isEnoughTimeLeftForReminder()
);
;
}

public function setUser(ilObjUser $user): self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,6 @@ class ilUserProfileDefaultFields
'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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public function initGeneralSettingsForm(): void
$lv->setValue($last_visited);
$this->form->addItem($lv);

if (ilSessionReminder::isGloballyActivated()) {
if ($this->userSettingVisible('session_reminder')) {
$session_reminder = new ilNumberInputGUI(
$this->lng->txt('session_reminder'),
'session_reminder_lead_time'
Expand All @@ -309,27 +309,12 @@ public function initGeneralSettingsForm(): void
)
);
$session_reminder->setDisabled(!$this->workWithUserSetting('session_reminder'));

$min_value = ilSessionReminder::MIN_LEAD_TIME;
$max_value = ilSessionReminder::getMaxLeadTime();

$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;
}
$value = min(
max(
$min_value,
$current_user_value
),
$max_value
);
$session_reminder->setValue(
(string) $value
(string) ilSessionReminder::getLocalSessionLeadTime($this->user->getId())
);
$session_reminder->setSize(3);
$session_reminder->setMinValue($min_value);
$session_reminder->setMaxValue($max_value);
$session_reminder->setMinValue(0);
$session_reminder->setMaxValue(ilSessionReminder::getMaxLeadTime());
$this->form->addItem($session_reminder);
}

Expand Down Expand Up @@ -456,7 +441,7 @@ public function saveGeneralSettings(): void
}
}

if (ilSessionReminder::isGloballyActivated() && $this->workWithUserSetting('session_reminder')) {
if ($this->workWithUserSetting('session_reminder')) {
$this->user->setPref(
'session_reminder_lead_time',
(string) $this->form->getInput('session_reminder_lead_time')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

use ILIAS\Setup;
use ILIAS\Refinery;
use ILIAS\Setup\Environment;
use ILIAS\Setup\Objective;
use ILIAS\UI;

/**
* @author Fabian Schmid <[email protected]>
*/
class ilUserDB10UpdateSteps implements ilDatabaseUpdateSteps
{
private const USER_DATA_TABLE_NAME = 'usr_data';

protected ilDBInterface $db;

public function prepare(ilDBInterface $db): void
{
$this->db = $db;
}



public function step_1(): void
{
$query = 'DELETE FROM settings WHERE module="common" AND keyword="session_reminder";';
$this->db->manipulate($query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public function getUpdateObjective(Setup\Config $config = null): Setup\Objective
),
new ilDatabaseUpdateStepsExecutedObjective(
new ilUserDB90()
),
new ilDatabaseUpdateStepsExecutedObjective(
new ilUserDB10UpdateSteps()
)
);
}
Expand Down
56 changes: 0 additions & 56 deletions components/ILIAS/User/classes/class.ilObjUserFolderGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1730,8 +1730,6 @@ protected function generalSettingsObject(): void
'dpro_withdrawal_usr_deletion' => (bool) $this->settings->get('dpro_withdrawal_usr_deletion'),
'tos_withdrawal_usr_deletion' => (bool) $this->settings->get('tos_withdrawal_usr_deletion'),

'session_reminder_enabled' => $this->settings->get('session_reminder_enabled'),

'login_max_attempts' => $security->getLoginMaxAttempts(),
'ps_prevent_simultaneous_logins' => (int) $security->isPreventionOfSimultaneousLoginsEnabled(),
'password_assistance' => (bool) $this->settings->get('password_assistance'),
Expand Down Expand Up @@ -1880,14 +1878,6 @@ public function saveGeneralSettingsObject(): void
$this->form->getInput('password_assistance')
);

// BEGIN SESSION SETTINGS

$this->settings->set(
'session_reminder_enabled',
$this->form->getInput('session_reminder_enabled')
);

// END SESSION SETTINGS
$this->settings->set(
'letter_avatars',
$this->form->getInput('letter_avatars')
Expand Down Expand Up @@ -2019,45 +2009,6 @@ protected function initFormGeneralSettings(): void
(string) ilSessionControl::DEFAULT_ALLOW_CLIENT_MAINTENANCE
);


// create session reminder subform
$session_reminder = new ilCheckboxInputGUI(
$this->lng->txt('session_reminder'),
'session_reminder_enabled'
);
$expires = ilSession::getSessionExpireValue();
$time = ilDatePresentation::secondsToString(
$expires,
true
);
$session_reminder->setInfo(
$this->lng->txt('session_reminder_info') . '<br />' .
sprintf(
$this->lng->txt('session_reminder_session_duration'),
$time
)
);

// add radio group to form
if ($allow_client_maintenance) {
// just shows the status wether the session
//setting maintenance is allowed by setup
$this->form->addItem($session_reminder);
} else {
// just shows the status wether the session
//setting maintenance is allowed by setup
$session_config = new ilNonEditableValueGUI(
$this->lng->txt('session_config'),
'session_config'
);
$session_config->setValue($this->lng->txt('session_config_maintenance_disabled'));
$session_reminder->setDisabled(true);
$session_config->addSubItem($session_reminder);
$this->form->addItem($session_config);
}

// END SESSION SETTINGS

$this->lng->loadLanguageModule('ps');

$pass = new ilFormSectionHeaderGUI();
Expand Down Expand Up @@ -2478,13 +2429,6 @@ 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
47 changes: 29 additions & 18 deletions components/ILIAS/User/classes/class.ilObjUserGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ public function saveObject(): void
if ($this->isSettingChangeable('hits_per_page')) {
$user_object->setPref('hits_per_page', $this->form_gui->getInput('hits_per_page'));
}
if ($this->isSettingChangeable('session_reminder')) {
$user_object->setPref('session_reminder_lead_time', (string) $this->form_gui->getInput('session_reminder_lead_time'));
}
if ($this->isSettingChangeable('hide_own_online_status')) {
$user_object->setPref(
'hide_own_online_status',
Expand All @@ -454,12 +457,6 @@ public function saveObject(): void
$this->form_gui->getInput('chat_broadcast_typing') ? 'y' : 'n'
);
}
if ($this->settings->get('session_reminder_enabled') === '1') {
$user_object->setPref(
'session_reminder_enabled',
$this->form_gui->getInput('session_reminder_enabled')
);
}
$user_object->writePrefs();

//set role entries
Expand Down Expand Up @@ -747,6 +744,11 @@ public function updateObject(): void
if ($this->isSettingChangeable('hits_per_page')) {
$this->object->setPref('hits_per_page', $this->form_gui->getInput('hits_per_page'));
}

if ($this->isSettingChangeable('session_reminder')) {
$this->object->setPref('session_reminder_lead_time', (string) $this->form_gui->getInput('session_reminder_lead_time'));
}

if ($this->isSettingChangeable('hide_own_online_status')) {
$this->object->setPref(
'hide_own_online_status',
Expand Down Expand Up @@ -776,13 +778,6 @@ public function updateObject(): void
// this ts is needed by ilSecuritySettings
$this->object->setLastPasswordChangeTS(time());

if ($this->settings->get('session_reminder_enabled') === '1') {
$this->object->setPref(
'session_reminder_enabled',
$this->form_gui->getInput('session_reminder_enabled')
);
}

// #10054 - profile may have been completed, check below is only for incomplete
$this->object->setProfileIncomplete(false);

Expand Down Expand Up @@ -900,11 +895,11 @@ public function getValues(): void
$data['language'] = $this->object->getLanguage();
$data['skin_style'] = $this->object->skin . ':' . $this->object->prefs['style'];
$data['hits_per_page'] = $this->object->prefs['hits_per_page'] ?? '';
$data['session_reminder_lead_time'] = $this->object->prefs['session_reminder_lead_time'] ?? ilSessionReminder::getGlobalSessionReminderLeadTime();
$data['hide_own_online_status'] = $this->object->prefs['hide_own_online_status'] ?? '';
$data['bs_allow_to_contact_me'] = ($this->object->prefs['bs_allow_to_contact_me'] ?? '') == 'y';
$data['chat_osc_accept_msg'] = ($this->object->prefs['chat_osc_accept_msg'] ?? '') == 'y';
$data['chat_broadcast_typing'] = ($this->object->prefs['chat_broadcast_typing'] ?? '') == 'y';
$data['session_reminder_enabled'] = (int) ($this->object->prefs['session_reminder_enabled'] ?? 0);

$data['send_mail'] = (($this->object->prefs['send_info_mails'] ?? '') == 'y');

Expand Down Expand Up @@ -1258,6 +1253,7 @@ public function initForm(string $a_mode): void
|| $this->isSettingChangeable('bs_allow_to_contact_me')
|| $this->isSettingChangeable('chat_osc_accept_msg')
|| $this->isSettingChangeable('chat_broadcast_typing')
|| ($this->isSettingChangeable('session_reminder'))
) {
$sec_st = new ilFormSectionHeaderGUI();
$sec_st->setTitle($this->lng->txt('settings'));
Expand Down Expand Up @@ -1379,10 +1375,25 @@ public function initForm(string $a_mode): void
$this->form_gui->addItem($chat_osc_acm);
}

if ((int) $this->settings->get('session_reminder_enabled')) {
$cb = new ilCheckboxInputGUI($this->lng->txt('session_reminder'), 'session_reminder_enabled');
$cb->setValue('1');
$this->form_gui->addItem($cb);
if ($this->isSettingChangeable('session_reminder')) {
$session_reminder = new ilNumberInputGUI(
$this->lng->txt('session_reminder'),
'session_reminder_lead_time'
);
$expires = ilSession::getSessionExpireValue();
$session_reminder->setInfo(
sprintf(
$this->lng->txt('session_reminder_lead_time_info'),
ilDatePresentation::secondsToString($expires, true)
)
);
$session_reminder->setValue(
(string) ilSessionReminder::getGlobalSessionReminderLeadTime()
);
$session_reminder->setSize(3);
$session_reminder->setMinValue(0);
$session_reminder->setMaxValue(ilSessionReminder::getMaxLeadTime());
$this->form_gui->addItem($session_reminder);
}

if ($this->isSettingChangeable('send_mail')) {
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/User/classes/class.ilUserDataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function readData(string $a_entity, string $a_version, array $a_ids): voi
"public_profile", "public_sel_country", "public_street", "public_title", "public_upload", "public_zipcode",
"screen_reader_optimization", "show_users_online",
"store_last_visited", "time_format", "user_tz", "weekstart",
"session_reminder_enabled", "session_reminder_lead_time", "usr_starting_point",
"session_reminder_lead_time", "usr_starting_point",
"chat_broadcast_typing"];

if (version_compare($a_version, '5.2.0', '>=')) {
Expand Down
Loading

0 comments on commit 44b26e4

Please sign in to comment.