ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilEventDetector Class Reference

@noinspection 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)
 
 trigger ($params)
 
 getDetectorState ()
 
 onActivate ()
 
 onDeactivate ()
 
 getContext ()
 This method returns the context of the element. More...
 
 setName ($name)
 
 getName ()
 
 setDbId ($a_id)
 
 getDbId ()
 
 hasDbId ()
 
 writeDetectorToDb ()
 
 deleteDetectorFromDb ()
 
 isListening ()
 
 getListeningTimeframe ()
 
 setListeningTimeframe ($listening_start, $listening_end)
 
 getEvent ()
 
 getEventSubject ()
 
 getEventContext ()
 

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

@noinspection PhpIncludeInspection

@noinspection 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.

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

References ilSimpleDetector\$context.

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 393 of file class.ilEventDetector.php.

394 {
395 require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
396 ilWorkflowDbHelper::deleteDetector($this);
397 }

Referenced by onDeactivate().

+ Here is the caller graph for this function:

◆ getActivated()

ilEventDetector::getActivated ( )
Returns
bool

Reimplemented from ilSimpleDetector.

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

416 {
418 }

References $was_activated.

◆ getDbId()

ilEventDetector::getDbId ( )

Returns the database id of the detector if set.

Returns
int
Exceptions

ilWorkflowObjectStateException

Implements ilExternalDetector.

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

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 }
@noinspection PhpIncludeInspection

References $db_id.

◆ 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.

141 {
142 return array('type' => $this->event_type, 'content' => $this->event_content);
143 }

◆ 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.

185 {
186 return array('type' => $this->event_context_type, 'identifier' => $this->event_context_identifier);
187 }

◆ 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.

163 {
164 return array('type' => $this->event_subject_type, 'identifier' => $this->event_subject_identifier);
165 }

◆ 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 404 of file class.ilEventDetector.php.

405 {
406 return array ('listening_start' => $this->listening_start, 'listening_end' => $this->listening_end);
407 }

◆ hasDbId()

ilEventDetector::hasDbId ( )

Returns, if the detector has a database id.

Returns
boolean If a database id is set.

Implements ilExternalDetector.

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

370 {
371 if ($this->db_id == null)
372 {
373 return false;
374 }
375
376 return true;
377 }

◆ isListening()

ilEventDetector::isListening ( )

Returns if the detector is currently listening.

Returns
boolean

Implements ilExternalDetector.

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

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 }

Referenced by trigger().

+ Here is the caller graph for this function:

◆ onActivate()

ilEventDetector::onActivate ( )

Method called on activation.

Reimplemented from ilSimpleDetector.

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

322 {
323 $this->setDetectorState(false);
324 $this->writeDetectorToDb();
325 }
writeDetectorToDb()
Passes this detector to the ilWorkflowDBHelper in order to write or update the detector data to the d...
setDetectorState($new_state)
Sets a new detector state.

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

+ Here is the call graph for this function:

◆ onDeactivate()

ilEventDetector::onDeactivate ( )

Method called on deactivation.

Reimplemented from ilSimpleDetector.

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

331 {
332 $this->setDetectorState(false);
333 $this->deleteDetectorFromDb();
334 }
deleteDetectorFromDb()
Passes this detector to the ilWorkflowDbHelper in order to remove the detector data from the database...

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

+ 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 341 of file class.ilEventDetector.php.

342 {
343 $this->db_id = $a_id;
344 }

◆ 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.

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

References $event_content, and $event_type.

◆ 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.

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

References $event_context_identifier, and $event_context_type.

◆ 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.

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

References $event_subject_identifier, and $event_subject_type.

◆ 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

ilWorkflowInvalidArgumentException

Implements ilExternalDetector.

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

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 }

References $listening_end, and $listening_start.

◆ 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

Reimplemented from ilSimpleDetector.

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

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 }
isListening()
Returns if the detector is currently listening.
getDetectorState()
Returns if the current detector state is satisfied or not.
getContext()
Returns the parent object.
$params
Definition: example_049.php:96

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

+ 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 383 of file class.ilEventDetector.php.

384 {
385 require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
386 ilWorkflowDbHelper::writeDetector($this);
387 }

Referenced by onActivate().

+ 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

bool ilEventDetector::$was_activated

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

Referenced by getActivated().


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