ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilEventDetector Class Reference

PhpIncludeInspection More...

+ Inheritance diagram for ilEventDetector:
+ Collaboration diagram for ilEventDetector:

Public Member Functions

 __construct ($context)
 Default constructor, passing the context to the parent constructor. More...
 
 setEvent ($event_type, $event_content)
 Sets the event type and content (/qualifier) for the detector. More...
 
 getEvent ()
 Returns the event type and content currently set to the detector. More...
 
 setEventSubject ($event_subject_type, $event_subject_identifier)
 Set the event subject type to the detector. More...
 
 getEventSubject ()
 Get the event subject set to the detector. More...
 
 setEventContext ($event_context_type, $event_context_identifier)
 Set the event context to the detector. More...
 
 getEventContext ()
 Get the event context set to the detector. More...
 
 trigger ($params)
 Triggers the detector. More...
 
 isListening ()
 Returns if the detector is currently listening. More...
 
 setListeningTimeframe ($listening_start, $listening_end)
 Sets the timeframe, in which the detector is listening. More...
 
 onActivate ()
 Method called on activation. More...
 
 onDeactivate ()
 Method called on deactivation. More...
 
 setDbId ($a_id)
 Sets the database id of the detector. More...
 
 getDbId ()
 Returns the database id of the detector if set. More...
 
 hasDbId ()
 Returns, if the detector has a database id. More...
 
 writeDetectorToDb ()
 Passes this detector to the ilWorkflowDBHelper in order to write or update the detector data to the database. More...
 
 deleteDetectorFromDb ()
 Passes this detector to the ilWorkflowDbHelper in order to remove the detector data from the database. More...
 
 getListeningTimeframe ()
 Returns the listening timefrage of the detector. More...
 
 getActivated ()
 
- Public Member Functions inherited from ilSimpleDetector
 __construct (ilNode $context)
 Default constructor. More...
 
 getContext ()
 Returns the parent object. More...
 
 trigger ($params)
 Trigger this detector. More...
 
 getDetectorState ()
 Returns if the current detector state is satisfied or not. More...
 
 setDetectorState ($new_state)
 Sets a new detector state. More...
 
 onActivate ()
 Method is called, when the parent node is activated. More...
 
 onDeactivate ()
 Method is called, when the parent node is deactivated. More...
 
 getActivated ()
 
 setName ($name)
 
 getName ()
 
 getSourceNode ()
 
 setSourceNode ($source_node)
 

Data Fields

 $was_activated
 

Private Attributes

 $event_type
 
 $event_content
 
 $event_subject_type
 
 $event_subject_identifier
 
 $event_context_type
 
 $event_context_identifier
 
 $listening_start = 0
 
 $listening_end = 0
 
 $db_id = null
 

Additional Inherited Members

- Protected Attributes inherited from ilSimpleDetector
 $name
 
 $source_node
 

Detailed Description

PhpIncludeInspection

PhpIncludeInspection ilEventDetector is part of the petri net based workflow engine.

The event detector listens to non-timer related outside events. Examples are events raised by Ilias, such as a new member joined a group/course, a test was finished, a learning progress was updated, etc. Please note here the differing handling of the params at the trigger method.

Author
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

/

Definition at line 22 of file class.ilEventDetector.php.

Constructor & Destructor Documentation

◆ __construct()

ilEventDetector::__construct (   $context)

Default constructor, passing the context to the parent constructor.

Parameters
ilNode$context

Definition at line 118 of file class.ilEventDetector.php.

References ilSimpleDetector\$context.

119  {
120  parent::__construct($context);
121  }

Member Function Documentation

◆ deleteDetectorFromDb()

ilEventDetector::deleteDetectorFromDb ( )

Passes this detector to the ilWorkflowDbHelper in order to remove the detector data from the database.

Implements ilExternalDetector.

Definition at line 376 of file class.ilEventDetector.php.

Referenced by onDeactivate().

377  {
378  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
379  ilWorkflowDbHelper::deleteDetector($this);
380  }
+ Here is the caller graph for this function:

◆ getActivated()

ilEventDetector::getActivated ( )
Returns
bool

Definition at line 398 of file class.ilEventDetector.php.

References $was_activated.

399  {
400  return $this->was_activated;
401  }

◆ getDbId()

ilEventDetector::getDbId ( )

Returns the database id of the detector if set.

Returns
int
Exceptions

Implements ilExternalDetector.

Definition at line 339 of file class.ilEventDetector.php.

References $db_id.

340  {
341  if ($this->db_id != null) {
342  return $this->db_id;
343  } else {
344  require_once './Services/WorkflowEngine/exceptions/ilWorkflowObjectStateException.php';
345  throw new ilWorkflowObjectStateException('No database ID set.');
346  }
347  }

◆ getEvent()

ilEventDetector::getEvent ( )

Returns the event type and content currently set to the detector.

Returns
array array('type' => $this->event_type, 'content' => $this->event_content)

Implements ilExternalDetector.

Definition at line 140 of file class.ilEventDetector.php.

References array.

141  {
142  return array('type' => $this->event_type, 'content' => $this->event_content);
143  }
Create styles array
The data for the language used.

◆ getEventContext()

ilEventDetector::getEventContext ( )

Get the event context set to the detector.

Returns
array array('type' => $this->event_context_type, 'identifier' => $this->event_context_identifier)

Implements ilExternalDetector.

Definition at line 184 of file class.ilEventDetector.php.

References array.

185  {
186  return array('type' => $this->event_context_type, 'identifier' => $this->event_context_identifier);
187  }
Create styles array
The data for the language used.

◆ getEventSubject()

ilEventDetector::getEventSubject ( )

Get the event subject set to the detector.

Returns
array array('type' => $this->event_subject_type, 'identifier' => $this->event_subject_identifier)

Implements ilExternalDetector.

Definition at line 162 of file class.ilEventDetector.php.

References array.

163  {
164  return array('type' => $this->event_subject_type, 'identifier' => $this->event_subject_identifier);
165  }
Create styles array
The data for the language used.

◆ getListeningTimeframe()

ilEventDetector::getListeningTimeframe ( )

Returns the listening timefrage of the detector.

Returns
array array ('listening_start' => $this->listening_start, 'listening_end' => $this->listening_end)

Implements ilExternalDetector.

Definition at line 387 of file class.ilEventDetector.php.

References array.

388  {
389  return array('listening_start' => $this->listening_start, 'listening_end' => $this->listening_end);
390  }
Create styles array
The data for the language used.

◆ hasDbId()

ilEventDetector::hasDbId ( )

Returns, if the detector has a database id.

Returns
boolean If a database id is set.

Implements ilExternalDetector.

Definition at line 353 of file class.ilEventDetector.php.

354  {
355  if ($this->db_id == null) {
356  return false;
357  }
358 
359  return true;
360  }

◆ isListening()

ilEventDetector::isListening ( )

Returns if the detector is currently listening.

Returns
boolean

Implements ilExternalDetector.

Definition at line 265 of file class.ilEventDetector.php.

References time.

Referenced by trigger().

266  {
267  // No listening phase = always listening.
268  if ($this->listening_start == 0 && $this->listening_end == 0) {
269  return true;
270  }
271 
272  // Listening started?
273  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowUtils.php';
274  if ($this->listening_start <= ilWorkflowUtils::time()) {
275  // Listening not ended or infinite?
276  if ($this->listening_end >= ilWorkflowUtils::time()
277  || $this->listening_end == 0) {
278  return true;
279  }
280  }
281 
282  return false;
283  }
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ Here is the caller graph for this function:

◆ onActivate()

ilEventDetector::onActivate ( )

Method called on activation.

Implements ilDetector.

Definition at line 308 of file class.ilEventDetector.php.

References ilSimpleDetector\setDetectorState(), and writeDetectorToDb().

309  {
310  $this->setDetectorState(false);
311  $this->writeDetectorToDb();
312  }
setDetectorState($new_state)
Sets a new detector state.
writeDetectorToDb()
Passes this detector to the ilWorkflowDBHelper in order to write or update the detector data to the d...
+ Here is the call graph for this function:

◆ onDeactivate()

ilEventDetector::onDeactivate ( )

Method called on deactivation.

Implements ilDetector.

Definition at line 317 of file class.ilEventDetector.php.

References deleteDetectorFromDb(), and ilSimpleDetector\setDetectorState().

318  {
319  $this->setDetectorState(false);
320  $this->deleteDetectorFromDb();
321  }
setDetectorState($new_state)
Sets a new detector state.
deleteDetectorFromDb()
Passes this detector to the ilWorkflowDbHelper in order to remove the detector data from the database...
+ Here is the call graph for this function:

◆ setDbId()

ilEventDetector::setDbId (   $a_id)

Sets the database id of the detector.

Parameters
integer$a_id

Implements ilExternalDetector.

Definition at line 328 of file class.ilEventDetector.php.

329  {
330  $this->db_id = $a_id;
331  }

◆ setEvent()

ilEventDetector::setEvent (   $event_type,
  $event_content 
)

Sets the event type and content (/qualifier) for the detector.

'WHAT'

Parameters
string$event_type
string$event_content

Definition at line 129 of file class.ilEventDetector.php.

References $event_content, $event_type, and string.

130  {
131  $this->event_type = (string) $event_type;
132  $this->event_content = (string) $event_content;
133  }
Add rich text string

◆ setEventContext()

ilEventDetector::setEventContext (   $event_context_type,
  $event_context_identifier 
)

Set the event context to the detector.

'WHERE' / 'ON WHAT' / 'ON WHOM'

Parameters
string$event_context_type
integer$event_context_identifier

Definition at line 173 of file class.ilEventDetector.php.

References $event_context_identifier, $event_context_type, and string.

174  {
175  $this->event_context_type = (string) $event_context_type;
176  $this->event_context_identifier = $event_context_identifier;
177  }
Add rich text string

◆ setEventSubject()

ilEventDetector::setEventSubject (   $event_subject_type,
  $event_subject_identifier 
)

Set the event subject type to the detector.

'WHO'

Parameters
string$event_subject_type
integer$event_subject_identifier

Definition at line 151 of file class.ilEventDetector.php.

References $event_subject_identifier, $event_subject_type, and string.

152  {
153  $this->event_subject_type = (string) $event_subject_type;
154  $this->event_subject_identifier = $event_subject_identifier;
155  }
Add rich text string

◆ setListeningTimeframe()

ilEventDetector::setListeningTimeframe (   $listening_start,
  $listening_end 
)

Sets the timeframe, in which the detector is listening.

Parameters
integer$listening_startUnix timestamp start of listening period.
integer$listening_endUnix timestamp end of listening period.
Exceptions

Implements ilExternalDetector.

Definition at line 293 of file class.ilEventDetector.php.

References $listening_end, and $listening_start.

294  {
295  $this->listening_start = $listening_start;
296 
297  if ($this->listening_start > $listening_end && $listening_end != 0) {
298  require_once './Services/WorkflowEngine/exceptions/ilWorkflowInvalidArgumentException.php';
299  throw new ilWorkflowInvalidArgumentException('Listening timeframe is (start vs. end) is invalid.');
300  }
301 
302  $this->listening_end = $listening_end;
303  }

◆ trigger()

ilEventDetector::trigger (   $params)

Triggers the detector.

The params for this trigger have to be assembled like this: array ( 'event_type' => 'course_join', 'event_content' => 'member_join', 'event_subject_type => 'usr', 'event_subject_identifier' => '6', 'event_context_type' => 'crs', 'event_context_identifier' => '48' )

This would describe an event, in which a user joined a course as member. If an identifier is '0', they are meant as 'for all'.

Parameters
array$paramsAssociative array with params, see docs for details.
Returns
bool|void

Implements ilDetector.

Definition at line 209 of file class.ilEventDetector.php.

References $key, $params, ilSimpleDetector\getContext(), ilSimpleDetector\getDetectorState(), isListening(), and ilSimpleDetector\setDetectorState().

210  {
211  if (!$this->isListening()) {
212  return;
213  }
214 
215  if ($this->event_type !== $params[0]) {
216  // Wrong event type -> no action here.
217  return;
218  }
219 
220  if ($this->event_content !== $params[1]) {
221  // Wrong event content -> no action here.
222  return;
223  }
224 
225  if ($this->event_subject_type !== $params[2]) {
226  // Wrong event subject type -> no action here.
227  return;
228  }
229 
230  if ($this->event_subject_identifier !== $params[3] && $this->event_subject_identifier != 0) {
231  // Wrong event subject identifier and identifier here not 0 (not *all*) -> no action.
232  return;
233  }
234 
235  if ($this->event_context_type !== $params[4]) {
236  // Wrong event context type -> no action.
237  return;
238  }
239 
240  if ($this->event_context_identifier !== $params[5] && $this->event_context_identifier != 0) {
241  // Wrong event context identifier and identifier here not 0 (not *all*) -> no action.
242  return;
243  }
244 
245  // We're through checks now, let's see if this detector is already satisfied.
246  if ($this->getDetectorState() == false) {
247  // X -> ilNode -> ilWorkflow -> Method...
248  foreach ($params as $key => $value) {
249  $this->getContext()->setRuntimeVar($key, $value);
250  }
251  $this->getContext()->setRuntimeVar('current_event', $params);
252  $this->was_activated = true;
253  $this->setDetectorState(true);
254  return true;
255  }
256 
257  return false;
258  }
$params
Definition: disable.php:11
isListening()
Returns if the detector is currently listening.
getDetectorState()
Returns if the current detector state is satisfied or not.
setDetectorState($new_state)
Sets a new detector state.
$key
Definition: croninfo.php:18
getContext()
Returns the parent object.
+ Here is the call graph for this function:

◆ writeDetectorToDb()

ilEventDetector::writeDetectorToDb ( )

Passes this detector to the ilWorkflowDBHelper in order to write or update the detector data to the database.

Implements ilExternalDetector.

Definition at line 366 of file class.ilEventDetector.php.

Referenced by onActivate().

367  {
368  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
369  ilWorkflowDbHelper::writeDetector($this);
370  }
+ Here is the caller graph for this function:

Field Documentation

◆ $db_id

ilEventDetector::$db_id = null
private

Definition at line 111 of file class.ilEventDetector.php.

Referenced by getDbId().

◆ $event_content

ilEventDetector::$event_content
private

Definition at line 52 of file class.ilEventDetector.php.

Referenced by setEvent().

◆ $event_context_identifier

ilEventDetector::$event_context_identifier
private

Definition at line 92 of file class.ilEventDetector.php.

Referenced by setEventContext().

◆ $event_context_type

ilEventDetector::$event_context_type
private

Definition at line 83 of file class.ilEventDetector.php.

Referenced by setEventContext().

◆ $event_subject_identifier

ilEventDetector::$event_subject_identifier
private

Definition at line 71 of file class.ilEventDetector.php.

Referenced by setEventSubject().

◆ $event_subject_type

ilEventDetector::$event_subject_type
private

Definition at line 62 of file class.ilEventDetector.php.

Referenced by setEventSubject().

◆ $event_type

ilEventDetector::$event_type
private

Definition at line 39 of file class.ilEventDetector.php.

Referenced by setEvent().

◆ $listening_end

ilEventDetector::$listening_end = 0
private

Definition at line 104 of file class.ilEventDetector.php.

Referenced by setListeningTimeframe().

◆ $listening_start

ilEventDetector::$listening_start = 0
private

Definition at line 98 of file class.ilEventDetector.php.

Referenced by setListeningTimeframe().

◆ $was_activated

ilEventDetector::$was_activated

Definition at line 393 of file class.ilEventDetector.php.

Referenced by getActivated().


The documentation for this class was generated from the following file: