ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilSessionReminder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
26  public const LEAD_TIME_DISABLED = 0;
27  public const MIN_LEAD_TIME = 1;
28  public const SUGGESTED_LEAD_TIME = 5;
30  private ilObjUser $user;
32  private int $lead_time = self::SUGGESTED_LEAD_TIME;
33  private int $expiration_time = 0;
34  private int $current_time = 0;
35  private int $seconds_until_expiration = 0;
36  private int $seconds_until_reminder = 0;
37 
38  public function __construct(
39  ilObjUser $user,
40  ClockInterface $clock,
41  ilSetting $settings
42  ) {
43  $this->user = $user;
44  $this->clock = $clock;
45  $this->settings = $settings;
46 
47  $this->init();
48  }
49 
50  public static function byLoggedInUser(): self
51  {
52  global $DIC;
53 
54  if (isset($DIC['ilUser'])) {
55  $user = $DIC->user();
56  } else {
57  $user = new ilObjUser();
58  $user->setId(0);
59  }
60 
61  $reminder = new self(
62  $user,
63  (new DataFactory())->clock()->utc(),
64  $DIC->settings()
65  );
66 
67  return $reminder;
68  }
69 
71  {
72  return $this->buildValidLeadTime(
73  (int) $this->settings->get('session_reminder_lead_time')
74  );
75  }
76 
77  private function buildValidLeadTime(int $lead_time): int
78  {
79  $min_value = self::MIN_LEAD_TIME;
80  $max_value = $this->getMaxPossibleLeadTime();
81 
82  if (
83  $lead_time !== self::LEAD_TIME_DISABLED &&
84  ($lead_time < $min_value || $lead_time > $max_value)
85  ) {
86  $lead_time = self::SUGGESTED_LEAD_TIME;
87  }
88 
89  return $lead_time !== self::LEAD_TIME_DISABLED ? min(
90  max(
91  $min_value,
92  $lead_time
93  ),
94  $max_value
95  ) : self::LEAD_TIME_DISABLED;
96  }
97 
98  public function getEffectiveLeadTime(): int
99  {
100  return $this->buildValidLeadTime(
102  $this->getUser()->getId(),
103  'session_reminder_lead_time'
105  );
106  }
107 
108  public function getMaxPossibleLeadTime(): int
109  {
111 
112  return max(self::MIN_LEAD_TIME, ($expires / 60) - 1);
113  }
114 
115  private function init(): void
116  {
117  $this->setLeadTime(
118  $this->getEffectiveLeadTime() * 60
119  );
120 
121  $this->setExpirationTime(ilSession::getIdleValue() + $this->clock->now()->getTimestamp());
122  $this->setCurrentTime($this->clock->now()->getTimestamp());
123 
126  }
127 
128  private function calculateSecondsUntilExpiration(): void
129  {
130  $this->setSecondsUntilExpiration($this->getExpirationTime() - $this->getCurrentTime());
131  }
132 
133  private function calculateSecondsUntilReminder(): void
134  {
136  }
137 
138  private function isEnoughTimeLeftForReminder(): bool
139  {
140  return $this->getLeadTime() < $this->getSecondsUntilExpiration();
141  }
142 
143  public function isActive(): bool
144  {
145  return
146  !$this->getUser()->isAnonymous() &&
147  $this->getUser()->getId() > 0 &&
148  $this->getEffectiveLeadTime() !== self::LEAD_TIME_DISABLED &&
150  }
151 
152  public function setUser(ilObjUser $user): self
153  {
154  $this->user = $user;
155 
156  return $this;
157  }
158 
159  public function getUser(): ilObjUser
160  {
161  return $this->user;
162  }
163 
164  public function setCurrentTime(int $current_time): self
165  {
166  $this->current_time = $current_time;
167 
168  return $this;
169  }
170 
171  public function getCurrentTime(): int
172  {
173  return $this->current_time;
174  }
175 
176  public function setExpirationTime(int $expiration_time): self
177  {
178  $this->expiration_time = $expiration_time;
179 
180  return $this;
181  }
182 
183  public function getExpirationTime(): int
184  {
185  return $this->expiration_time;
186  }
187 
188  public function setLeadTime(int $lead_time): self
189  {
190  $this->lead_time = $lead_time;
191 
192  return $this;
193  }
194 
195  public function getLeadTime(): int
196  {
197  return $this->lead_time;
198  }
199 
200  public function setSecondsUntilExpiration(int $seconds_until_expiration): self
201  {
202  $this->seconds_until_expiration = $seconds_until_expiration;
203 
204  return $this;
205  }
206 
207  public function getSecondsUntilExpiration(): int
208  {
210  }
211 
212  public function setSecondsUntilReminder(int $seconds_until_reminder): self
213  {
214  $this->seconds_until_reminder = $seconds_until_reminder;
215 
216  return $this;
217  }
218 
219  public function getSecondsUntilReminder(): int
220  {
222  }
223 }
setSecondsUntilExpiration(int $seconds_until_expiration)
setCurrentTime(int $current_time)
static getIdleValue()
Returns the idle time in seconds.
static _lookupPref(int $a_usr_id, string $a_keyword)
__construct(ilObjUser $user, ClockInterface $clock, ilSetting $settings)
setId(int $id)
setSecondsUntilReminder(int $seconds_until_reminder)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:22
setExpirationTime(int $expiration_time)
static getSessionExpireValue()
Returns the session expiration value.
buildValidLeadTime(int $lead_time)