ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilSessionReminder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
26  public const int LEAD_TIME_DISABLED = 0;
27  public const int MIN_LEAD_TIME = 1;
28  public const int SUGGESTED_LEAD_TIME = 5;
29 
30  private int $lead_time = self::SUGGESTED_LEAD_TIME;
31  private int $expiration_time = 0;
32  private int $current_time = 0;
33  private int $seconds_until_expiration = 0;
34  private int $seconds_until_reminder = 0;
35 
36  public function __construct(
37  private ilObjUser $user,
38  private readonly ClockInterface $clock,
39  private readonly ilSetting $settings
40  ) {
41  $this->init();
42  }
43 
44  public static function byLoggedInUser(): self
45  {
46  global $DIC;
47 
48  if (isset($DIC['ilUser'])) {
49  $user = $DIC->user();
50  } else {
51  $user = new ilObjUser();
52  $user->setId(0);
53  }
54 
55  $reminder = new self(
56  $user,
57  (new DataFactory())->clock()->utc(),
58  $DIC->settings()
59  );
60 
61  return $reminder;
62  }
63 
65  {
66  return $this->buildValidLeadTime(
67  (int) $this->settings->get('session_reminder_lead_time')
68  );
69  }
70 
71  private function buildValidLeadTime(int $lead_time): int
72  {
73  $min_value = self::MIN_LEAD_TIME;
74  $max_value = $this->getMaxPossibleLeadTime();
75 
76  if ($lead_time !== self::LEAD_TIME_DISABLED &&
77  ($lead_time < $min_value || $lead_time > $max_value)) {
78  $lead_time = self::SUGGESTED_LEAD_TIME;
79  }
80 
81  return $lead_time !== self::LEAD_TIME_DISABLED ? min(
82  max(
83  $min_value,
84  $lead_time
85  ),
86  $max_value
87  ) : self::LEAD_TIME_DISABLED;
88  }
89 
90  public function getEffectiveLeadTime(): int
91  {
92  return $this->buildValidLeadTime(
94  $this->getUser()->getId(),
95  'session_reminder_lead_time'
97  );
98  }
99 
100  public function getMaxPossibleLeadTime(): int
101  {
103 
104  return max(self::MIN_LEAD_TIME, ($expires / 60) - 1);
105  }
106 
107  private function init(): void
108  {
109  $this->setLeadTime(
110  $this->getEffectiveLeadTime() * 60
111  );
112 
113  $this->setExpirationTime(ilSession::getIdleValue() + $this->clock->now()->getTimestamp());
114  $this->setCurrentTime($this->clock->now()->getTimestamp());
115 
118  }
119 
120  private function calculateSecondsUntilExpiration(): void
121  {
122  $this->setSecondsUntilExpiration($this->getExpirationTime() - $this->getCurrentTime());
123  }
124 
125  private function calculateSecondsUntilReminder(): void
126  {
128  }
129 
130  private function isEnoughTimeLeftForReminder(): bool
131  {
132  return $this->getLeadTime() < $this->getSecondsUntilExpiration();
133  }
134 
135  public function isActive(): bool
136  {
137  return
138  !$this->getUser()->isAnonymous() &&
139  $this->getUser()->getId() > 0 &&
140  $this->getEffectiveLeadTime() !== self::LEAD_TIME_DISABLED &&
142  }
143 
144  public function setUser(ilObjUser $user): self
145  {
146  $this->user = $user;
147 
148  return $this;
149  }
150 
151  public function getUser(): ilObjUser
152  {
153  return $this->user;
154  }
155 
156  public function setCurrentTime(int $current_time): self
157  {
158  $this->current_time = $current_time;
159 
160  return $this;
161  }
162 
163  public function getCurrentTime(): int
164  {
165  return $this->current_time;
166  }
167 
168  public function setExpirationTime(int $expiration_time): self
169  {
170  $this->expiration_time = $expiration_time;
171 
172  return $this;
173  }
174 
175  public function getExpirationTime(): int
176  {
177  return $this->expiration_time;
178  }
179 
180  public function setLeadTime(int $lead_time): self
181  {
182  $this->lead_time = $lead_time;
183 
184  return $this;
185  }
186 
187  public function getLeadTime(): int
188  {
189  return $this->lead_time;
190  }
191 
192  public function setSecondsUntilExpiration(int $seconds_until_expiration): self
193  {
194  $this->seconds_until_expiration = $seconds_until_expiration;
195 
196  return $this;
197  }
198 
199  public function getSecondsUntilExpiration(): int
200  {
202  }
203 
204  public function setSecondsUntilReminder(int $seconds_until_reminder): self
205  {
206  $this->seconds_until_reminder = $seconds_until_reminder;
207 
208  return $this;
209  }
210 
211  public function getSecondsUntilReminder(): int
212  {
214  }
215 }
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)
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:26
setExpirationTime(int $expiration_time)
static getSessionExpireValue()
Returns the session expiration value.
__construct(private ilObjUser $user, private readonly ClockInterface $clock, private readonly ilSetting $settings)
buildValidLeadTime(int $lead_time)