ILIAS  release_8 Revision v8.24
class.ilSessionReminder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Data\Factory as DataFactory;
23
25{
26 public const MIN_LEAD_TIME = 2;
27 public const SUGGESTED_LEAD_TIME = 5;
28
32 private int $expiration_time = 0;
33 private int $current_time = 0;
35 private int $seconds_until_reminder = 0;
36
37 public static function byLoggedInUser(): self
38 {
39 global $DIC;
40
41 if (isset($DIC['ilUser'])) {
42 $user = $DIC->user();
43 } else {
44 $user = new ilObjUser();
45 $user->setId(0);
46 }
47
48 $reminder = new self(
49 $user,
50 (new DataFactory())->clock()->utc()
51 );
52
53 return $reminder;
54 }
55
56 public static function isGloballyActivated(): bool
57 {
59 global $DIC;
60
61 $ilSetting = $DIC['ilSetting'];
62
63 $isSessionReminderEnabled = (bool) $ilSetting->get('session_reminder_enabled', null);
64 $sessionHandlingMode = (int) $ilSetting->get(
65 'session_handling_type',
67 );
68
69 return (
70 $isSessionReminderEnabled &&
71 $sessionHandlingMode === ilSession::SESSION_HANDLING_FIXED
72 );
73 }
74
76 {
77 $this->user = $user;
78 $this->clock = $clock;
79
80 $this->init();
81 }
82
83 private function init(): void
84 {
85 $this->setLeadTime(
86 ((int) max(
87 self::MIN_LEAD_TIME,
88 (float) $this->getUser()->getPref('session_reminder_lead_time')
89 )) * 60
90 );
91
92 $this->setExpirationTime(ilSession::getIdleValue(true) + $this->clock->now()->getTimestamp());
93 $this->setCurrentTime($this->clock->now()->getTimestamp());
94
97 }
98
99 private function calculateSecondsUntilExpiration(): void
100 {
102 }
103
104 private function calculateSecondsUntilReminder(): void
105 {
107 }
108
109 private function isEnoughTimeLeftForReminder(): bool
110 {
111 return $this->getLeadTime() < $this->getSecondsUntilExpiration();
112 }
113
114 public function isActive(): bool
115 {
116 return (
117 self::isGloballyActivated() &&
118 !$this->getUser()->isAnonymous() &&
119 $this->getUser()->getId() > 0 &&
120 (int) $this->getUser()->getPref('session_reminder_enabled') &&
122 );
123 }
124
125 public function setUser(ilObjUser $user): self
126 {
127 $this->user = $user;
128
129 return $this;
130 }
131
132 public function getUser(): ilObjUser
133 {
134 return $this->user;
135 }
136
137 public function setCurrentTime(int $current_time): self
138 {
139 $this->current_time = $current_time;
140
141 return $this;
142 }
143
144 public function getCurrentTime(): int
145 {
146 return $this->current_time;
147 }
148
149 public function setExpirationTime(int $expiration_time): self
150 {
151 $this->expiration_time = $expiration_time;
152
153 return $this;
154 }
155
156 public function getExpirationTime(): int
157 {
159 }
160
161 public function setLeadTime(int $lead_time): self
162 {
163 $this->lead_time = $lead_time;
164
165 return $this;
166 }
167
168 public function getLeadTime(): int
169 {
170 return $this->lead_time;
171 }
172
174 {
175 $this->seconds_until_expiration = $seconds_until_expiration;
176
177 return $this;
178 }
179
181 {
183 }
184
186 {
187 $this->seconds_until_reminder = $seconds_until_reminder;
188
189 return $this;
190 }
191
192 public function getSecondsUntilReminder(): int
193 {
195 }
196}
Builds data types.
Definition: Factory.php:21
User class.
setId(int $id)
setSecondsUntilExpiration(int $seconds_until_expiration)
setCurrentTime(int $current_time)
setSecondsUntilReminder(int $seconds_until_reminder)
__construct(ilObjUser $user, ClockInterface $clock)
setExpirationTime(int $expiration_time)
const SESSION_HANDLING_FIXED
static getIdleValue(bool $fixedMode=false)
Returns the idle time in seconds.
global $DIC
Definition: feed.php:28
global $ilSetting
Definition: privfeed.php:17