ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSessionReminder.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
10 {
14  const MIN_LEAD_TIME = 2;
15 
20 
21 
25  protected $user;
26 
30  protected $lead_time = 0;
31 
35  protected $expiration_time = 0;
36 
40  protected $current_time = 0;
41 
46 
50  protected $seconds_until_reminder = 0;
51 
55  protected function __construct()
56  {
57  }
58 
63  public static function createInstanceWithCurrentUserSession()
64  {
68  global $ilUser;
69 
70  $reminder = new self();
71  $reminder->setUser($ilUser);
72  $reminder->initWithUserContext();
73 
74  return $reminder;
75  }
76 
80  protected function initWithUserContext()
81  {
85  global $ilAuth;
86 
87  $this->setLeadTime(max(self::MIN_LEAD_TIME, (float)$this->getUser()->getPref('session_reminder_lead_time')) * 60);
88  $this->setExpirationTime($ilAuth->sessionValidThru());
89  $this->setCurrentTime(time());
90 
93  }
94 
99  {
100  $this->setSecondsUntilExpiration($this->getExpirationTime() - $this->getCurrentTime());
101  }
102 
107  {
109  }
110 
114  protected function isEnoughtTimeLeftForReminder()
115  {
116  return $this->getLeadTime() < $this->getSecondsUntilExpiration();
117  }
118 
122  public function isActive()
123  {
124  return
125  self::isGloballyActivated() &&
126  $this->getUser()->getId() != ANONYMOUS_USER_ID &&
127  (int)$this->getUser()->getPref('session_reminder_enabled') &&
129  }
130 
135  public static function isGloballyActivated()
136  {
140  global $ilSetting;
141 
142  return
143  $ilSetting->get('session_handling_type', ilSession::SESSION_HANDLING_FIXED) == ilSession::SESSION_HANDLING_FIXED &&
144  (int)$ilSetting->get('session_reminder_enabled', 0);
145  }
146 
151  public function setUser($user)
152  {
153  $this->user = $user;
154  return $this;
155  }
156 
160  public function getUser()
161  {
162  return $this->user;
163  }
164 
169  public function setCurrentTime($current_time)
170  {
171  $this->current_time = $current_time;
172  return $this;
173  }
174 
178  public function getCurrentTime()
179  {
180  return $this->current_time;
181  }
182 
188  {
189  $this->expiration_time = $expiration_time;
190  return $this;
191  }
192 
196  public function getExpirationTime()
197  {
198  return $this->expiration_time;
199  }
200 
205  public function setLeadTime($lead_time)
206  {
207  $this->lead_time = $lead_time;
208  return $this;
209  }
210 
214  public function getLeadTime()
215  {
216  return $this->lead_time;
217  }
218 
224  {
225  $this->seconds_until_expiration = $seconds_until_expiration;
226  return $this;
227  }
228 
232  public function getSecondsUntilExpiration()
233  {
235  }
236 
242  {
243  $this->seconds_until_reminder = $seconds_until_reminder;
244  return $this;
245  }
246 
250  public function getSecondsUntilReminder()
251  {
253  }
254 }