ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilEventDetector.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 
23 {
39  private $event_type;
40 
52  private $event_content;
53 
63 
72 
84 
93 
98  private $listening_start = 0;
99 
104  private $listening_end = 0;
105 
111  private $db_id = null;
112 
118  public function __construct($context)
119  {
120  parent::__construct($context);
121  }
122 
130  {
131  $this->event_type = (string) $event_type;
132  $this->event_content = (string) $event_content;
133  }
134 
140  public function getEvent()
141  {
142  return array('type' => $this->event_type, 'content' => $this->event_content);
143  }
144 
152  {
153  $this->event_subject_type = (string) $event_subject_type;
154  $this->event_subject_identifier = $event_subject_identifier;
155  }
156 
162  public function getEventSubject()
163  {
164  return array('type' => $this->event_subject_type, 'identifier' => $this->event_subject_identifier);
165  }
166 
174  {
175  $this->event_context_type = (string) $event_context_type;
176  $this->event_context_identifier = $event_context_identifier;
177  }
178 
184  public function getEventContext()
185  {
186  return array('type' => $this->event_context_type, 'identifier' => $this->event_context_identifier);
187  }
188 
209  public function trigger($params)
210  {
211  if (!$this->isListening())
212  {
213  return;
214  }
215 
216  if ($this->event_type !== $params[0])
217  {
218  // Wrong event type -> no action here.
219  return;
220  }
221 
222  if ($this->event_content !== $params[1])
223  {
224  // Wrong event content -> no action here.
225  return;
226  }
227 
228  if ($this->event_subject_type !== $params[2])
229  {
230  // Wrong event subject type -> no action here.
231  return;
232  }
233 
234  if ($this->event_subject_identifier !== $params[3] && $this->event_subject_identifier != 0)
235  {
236  // Wrong event subject identifier and identifier here not 0 (not *all*) -> no action.
237  return;
238  }
239 
240  if ($this->event_context_type !== $params[4])
241  {
242  // Wrong event context type -> no action.
243  return;
244  }
245 
246  if ($this->event_context_identifier !== $params[5] && $this->event_context_identifier != 0)
247  {
248  // Wrong event context identifier and identifier here not 0 (not *all*) -> no action.
249  return;
250  }
251 
252  // We're through checks now, let's see if this detector is already satisfied.
253  if ($this->getDetectorState() == false)
254  {
255  // X -> ilNode -> ilWorkflow -> Method...
256  foreach($params as $key => $value)
257  {
258  $this->getContext()->setRuntimeVar($key, $value);
259  }
260  $this->getContext()->setRuntimeVar('current_event', $params);
261  $this->was_activated = true;
262  $this->setDetectorState(true);
263  return true;
264  }
265 
266  return false;
267  }
268 
274  public function isListening()
275  {
276  // No listening phase = always listening.
277  if ($this->listening_start == 0 && $this->listening_end == 0)
278  {
279  return true;
280  }
281 
282  // Listening started?
283  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowUtils.php';
284  if ($this->listening_start <= ilWorkflowUtils::time())
285  {
286  // Listening not ended or infinite?
287  if ($this->listening_end >= ilWorkflowUtils::time()
288  || $this->listening_end == 0)
289  {
290  return true;
291  }
292  }
293 
294  return false;
295  }
296 
306  {
307  $this->listening_start = $listening_start;
308 
309  if ($this->listening_start > $listening_end && $listening_end != 0)
310  {
311  require_once './Services/WorkflowEngine/exceptions/ilWorkflowInvalidArgumentException.php';
312  throw new ilWorkflowInvalidArgumentException('Listening timeframe is (start vs. end) is invalid.');
313  }
314 
315  $this->listening_end = $listening_end;
316  }
317 
321  public function onActivate()
322  {
323  $this->setDetectorState(false);
324  $this->writeDetectorToDb();
325  }
326 
330  public function onDeactivate()
331  {
332  $this->setDetectorState(false);
333  $this->deleteDetectorFromDb();
334  }
335 
341  public function setDbId($a_id)
342  {
343  $this->db_id = $a_id;
344  }
345 
352  public function getDbId()
353  {
354  if ($this->db_id != null)
355  {
356  return $this->db_id;
357  }
358  else
359  {
360  require_once './Services/WorkflowEngine/exceptions/ilWorkflowObjectStateException.php';
361  throw new ilWorkflowObjectStateException('No database ID set.');
362  }
363  }
364 
369  public function hasDbId()
370  {
371  if ($this->db_id == null)
372  {
373  return false;
374  }
375 
376  return true;
377  }
378 
383  public function writeDetectorToDb()
384  {
385  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
386  ilWorkflowDbHelper::writeDetector($this);
387  }
388 
393  public function deleteDetectorFromDb()
394  {
395  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
396  ilWorkflowDbHelper::deleteDetector($this);
397  }
398 
404  public function getListeningTimeframe()
405  {
406  return array ('listening_start' => $this->listening_start, 'listening_end' => $this->listening_end);
407  }
408 
411 
415  public function getActivated()
416  {
417  return $this->was_activated;
418  }
419 }
isListening()
Returns if the detector is currently listening.
getDetectorState()
Returns if the current detector state is satisfied or not.
getEvent()
Returns the event type and content currently set to the detector.
hasDbId()
Returns, if the detector has a database id.
setDbId($a_id)
Sets the database id of the detector.
Add rich text string
The name of the decorator.
getListeningTimeframe()
Returns the listening timefrage of the detector.
getEventSubject()
Get the event subject set to the detector.
setEventSubject($event_subject_type, $event_subject_identifier)
Set the event subject type to the detector.
getEventContext()
Get the event context set to the detector.
PhpIncludeInspection
trigger($params)
Triggers the detector.
setListeningTimeframe($listening_start, $listening_end)
Sets the timeframe, in which the detector is listening.
onActivate()
Method called on activation.
Create styles array
The data for the language used.
setDetectorState($new_state)
Sets a new detector state.
getDbId()
Returns the database id of the detector if set.
setEventContext($event_context_type, $event_context_identifier)
Set the event context to the detector.
__construct($context)
Default constructor, passing the context to the parent constructor.
deleteDetectorFromDb()
Passes this detector to the ilWorkflowDbHelper in order to remove the detector data from the database...
setEvent($event_type, $event_content)
Sets the event type and content (/qualifier) for the detector.
writeDetectorToDb()
Passes this detector to the ilWorkflowDBHelper in order to write or update the detector data to the d...
PhpIncludeInspection
PhpIncludeInspection
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
onDeactivate()
Method called on deactivation.
getContext()
Returns the parent object.
$params
Definition: example_049.php:96