ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilTimerDetector.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
5 require_once './Services/WorkflowEngine/classes/detectors/class.ilSimpleDetector.php';
7 require_once './Services/WorkflowEngine/interfaces/ilExternalDetector.php';
8 
21 {
30  private $event_type = 'time_passed';
31 
33  private $event_content = 'time_passed';
34 
36  private $event_subject_type = 'none';
37 
40 
42  private $event_context_type = 'none';
43 
46 
48  private $timer_relative;
49 
55  private $timer_start = 0;
56 
62  private $timer_limit = 0;
63 
68  private $listening_start = 0;
69 
74  private $listening_end = 0;
75 
81  private $db_id = null;
82 
88  public function __construct($context)
89  {
90  parent::__construct($context);
91  }
92 
98  public function setTimerStart($timer_start)
99  {
100  $this->timer_start = (int) $timer_start;
101  }
102 
108  public function getTimerStart()
109  {
110  return $this->timer_start;
111  }
112 
118  public function setTimerLimit($timer_limit)
119  {
120  $this->timer_limit = (int) $timer_limit;
121  }
122 
128  public function getTimerLimit()
129  {
130  return $this->timer_limit;
131  }
132 
143  public function trigger($params)
144  {
145  if ($this->getDetectorState() == true)
146  {
147  return false;
148  }
149 
150  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowUtils.php';
151  if ($this->timer_limit + $this->timer_start <= ilWorkflowUtils::time())
152  {
153  $this->setDetectorState(true);
154  }
155  return true;
156  }
157 
163  public function isListening()
164  {
165  // No listening phase = always listening.
166  if ($this->listening_start == 0 && $this->listening_end == 0)
167  {
168  return true;
169  }
170 
171  // Listening started?
172  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowUtils.php';
173  if ($this->listening_start < ilWorkflowUtils::time())
174  {
175  // Listening not ended or infinite?
176  if ($this->listening_end > ilWorkflowUtils::time()
177  || $this->listening_end == 0)
178  {
179  return true;
180  }
181  }
182 
183  return false;
184  }
185 
195  {
196  $this->listening_start = $listening_start;
197 
198  if ($this->listening_start > $listening_end && $listening_end != 0)
199  {
200  require_once './Services/WorkflowEngine/exceptions/ilWorkflowInvalidArgumentException.php';
201  throw new ilWorkflowInvalidArgumentException('Listening timeframe is (start vs. end) is invalid.');
202  }
203 
204  $this->listening_end = $listening_end;
205  }
206 
210  public function onActivate()
211  {
212  if($this->timer_relative)
213  {
214  if($this->timer_start == 0)
215  {
216  $this->listening_start = time();
217  }
218  else
219  {
220  $this->listening_start = $this->timer_start;
221  }
222  if($this->timer_limit != 0)
223  {
224  $this->listening_end = $this->listening_start + $this->timer_limit;
225  }
226  else
227  {
228  $this->listening_end = 0;
229  }
230  }
231  $this->setDetectorState(false);
232  $this->writeDetectorToDb();
233  }
234 
238  public function onDeactivate() {
239  $this->setDetectorState(false);
240  $this->deleteDetectorFromDb();
241  }
242 
248  public function setDbId($a_id)
249  {
250  $this->db_id = $a_id;
251  }
252 
258  public function getDbId()
259  {
260  if ($this->db_id != null)
261  {
262  return $this->db_id;
263  }
264  else
265  {
266  require_once './Services/WorkflowEngine/exceptions/ilWorkflowObjectStateException.php';
267  throw new ilWorkflowObjectStateException('No database ID set.');
268  }
269  }
270 
276  public function hasDbId()
277  {
278  if ($this->db_id == null)
279  {
280  return false;
281  }
282 
283  return true;
284  }
285 
290  public function writeDetectorToDb()
291  {
292  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
293  ilWorkflowDbHelper::writeDetector($this);
294  }
295 
300  public function deleteDetectorFromDb()
301  {
302  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
303  ilWorkflowDbHelper::deleteDetector($this);
304  }
305 
311  public function getEvent()
312  {
313  return array('type' => $this->event_type, 'content' => $this->event_content);
314  }
315 
321  public function getEventSubject()
322  {
323  return array('type' => $this->event_subject_type, 'identifier' => $this->event_subject_identifier);
324  }
325 
331  public function getEventContext()
332  {
333  return array('type' => $this->event_context_type, 'identifier' => $this->event_context_identifier);
334  }
335 
340  public function getListeningTimeframe()
341  {
342  return array ('listening_start' => $this->listening_start, 'listening_end' => $this->listening_end);
343  }
344 
348  public function isTimerRelative()
349  {
350  return $this->timer_relative;
351  }
352 
357  {
358  $this->timer_relative = $timer_relative;
359  }
360 }
writeDetectorToDb()
Passes this detector to the ilWorkflowDBHelper in order to write or update the detector data to the d...
getDetectorState()
Returns if the current detector state is satisfied or not.
getDbId()
Returns the database id of the detector if set.
getEventContext()
Get the event context set to the detector.
getEventSubject()
Get the event subject set to the detector.
setListeningTimeframe($listening_start, $listening_end)
Sets the timeframe, in which the detector is listening.
PhpIncludeInspection
PhpIncludeInspection
onActivate()
Method called on activation.
setTimerLimit($timer_limit)
Sets the timers limit.
deleteDetectorFromDb()
Passes this detector to the ilWorkflowDbHelper in order to remove the detector data from the database...
getTimerLimit()
Returns the currently set timers limit.
setDbId($a_id)
Sets the database id of the detector.
Create styles array
The data for the language used.
setDetectorState($new_state)
Sets a new detector state.
hasDbId()
Returns, if the detector has a database id.
__construct($context)
Default constructor, passing the context to the parent constructor.
trigger($params)
Trigger this detector.
PhpIncludeInspection
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
getListeningTimeframe()
Returns the listening timefrage of the detector.
getEvent()
Returns the event type and content currently set to the detector.
setTimerRelative($timer_relative)
onDeactivate()
Method called on deactivation.
setTimerStart($timer_start)
Sets the timers start datetime.
$params
Definition: example_049.php:96
isListening()
Returns if the detector is currently listening.
getTimerStart()
Returns the currently set timer start.