ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSessionReminder.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
10 {
12  const MIN_LEAD_TIME = 2;
13 
16 
18  protected $user;
19 
21  protected $lead_time = 0;
22 
24  protected $expiration_time = 0;
25 
27  protected $current_time = 0;
28 
31 
33  protected $seconds_until_reminder = 0;
34 
38  protected function __construct()
39  {
40  }
41 
45  public static function createInstanceWithCurrentUserSession() : self
46  {
47  global $DIC;
48 
49  if (isset($DIC['ilUser'])) {
50  $user = $DIC['ilUser'];
51  } else {
52  $user = new ilObjUser();
53  $user->setId(0);
54  }
55 
56  $reminder = new self();
57  $reminder->setUser($user);
58  $reminder->initWithUserContext();
59 
60  return $reminder;
61  }
62 
66  protected function initWithUserContext() : void
67  {
68  $this->setLeadTime(
69  ((int) max(
70  self::MIN_LEAD_TIME,
71  (float) $this->getUser()->getPref('session_reminder_lead_time')
72  )) * 60
73  );
74 
75  $this->setExpirationTime(ilSession::getIdleValue(true) + time());
76  $this->setCurrentTime(time());
77 
80  }
81 
85  public function calculateSecondsUntilExpiration() : void
86  {
88  }
89 
93  public function calculateSecondsUntilReminder() : void
94  {
96  }
97 
101  protected function isEnoughTimeLeftForReminder() : bool
102  {
103  return $this->getLeadTime() < $this->getSecondsUntilExpiration();
104  }
105 
109  public function isActive() : bool
110  {
111  return (
112  self::isGloballyActivated() &&
113  !$this->getUser()->isAnonymous() &&
114  (int) $this->getUser()->getId() > 0 &&
115  (int) $this->getUser()->getPref('session_reminder_enabled') &&
117  );
118  }
119 
123  public static function isGloballyActivated() : bool
124  {
128  global $DIC;
129 
130  $ilSetting = $DIC['ilSetting'];
131 
132  $isSessionReminderEnabled = (bool) $ilSetting->get('session_reminder_enabled', false);
133  $sessionHandlingMode = $ilSetting->get('session_handling_type', ilSession::SESSION_HANDLING_FIXED);
134 
135  return (
136  $isSessionReminderEnabled &&
137  $sessionHandlingMode == ilSession::SESSION_HANDLING_FIXED
138  );
139  }
140 
145  public function setUser(ilObjUser $user) : self
146  {
147  $this->user = $user;
148 
149  return $this;
150  }
151 
155  public function getUser() : ilObjUser
156  {
157  return $this->user;
158  }
159 
164  public function setCurrentTime(int $current_time) : self
165  {
166  $this->current_time = $current_time;
167 
168  return $this;
169  }
170 
174  public function getCurrentTime() : int
175  {
176  return $this->current_time;
177  }
178 
183  public function setExpirationTime(int $expiration_time) : self
184  {
185  $this->expiration_time = $expiration_time;
186 
187  return $this;
188  }
189 
193  public function getExpirationTime() : int
194  {
195  return $this->expiration_time;
196  }
197 
202  public function setLeadTime(int $lead_time) : self
203  {
204  $this->lead_time = $lead_time;
205 
206  return $this;
207  }
208 
212  public function getLeadTime() : int
213  {
214  return $this->lead_time;
215  }
216 
222  {
223  $this->seconds_until_expiration = $seconds_until_expiration;
224 
225  return $this;
226  }
227 
231  public function getSecondsUntilExpiration() : int
232  {
234  }
235 
241  {
242  $this->seconds_until_reminder = $seconds_until_reminder;
243 
244  return $this;
245  }
246 
250  public function getSecondsUntilReminder() : int
251  {
253  }
254 }
static createInstanceWithCurrentUserSession()
setSecondsUntilExpiration(int $seconds_until_expiration)
setCurrentTime(int $current_time)
__construct()
ilSessionReminder constructor.
const SESSION_HANDLING_FIXED
user()
Definition: user.php:4
setSecondsUntilReminder(int $seconds_until_reminder)
global $DIC
Definition: goto.php:24
static getIdleValue($fixedMode=false)
Returns the idle time in seconds.
global $ilSetting
Definition: privfeed.php:17
setExpirationTime(int $expiration_time)