29 public static function writeWorkflow(
ilWorkflow $workflow)
40 $mode = self::DB_MODE_UPDATE;
42 $wf_id =
$ilDB->nextId(
'wfe_workflows');
44 $mode = self::DB_MODE_CREATE;
51 $instance = serialize($workflow);
53 if ($mode == self::DB_MODE_UPDATE) {
57 'workflow_type' => array(
'text', $wf_data[
'type'] ),
58 'workflow_content' => array(
'text', $wf_data[
'content']),
61 'subject_type' => array(
'text', $wf_subject[
'type']),
62 'subject_id' => array(
'integer', $wf_subject[
'identifier']),
63 'context_type' => array(
'text', $wf_context[
'type']),
64 'context_id' => array(
'integer', $wf_context[
'identifier']),
65 'workflow_instance' => array(
'clob', $instance),
66 'active' => array(
'integer', (
int) $active)
69 'workflow_id' => array(
'integer', $wf_id)
74 if ($mode == self::DB_MODE_CREATE) {
78 'workflow_id' => array(
'integer', $wf_id),
79 'workflow_type' => array(
'text', $wf_data[
'type'] ),
82 'workflow_content' => array(
'text', $wf_data[
'content']),
83 'subject_type' => array(
'text', $wf_subject[
'type']),
84 'subject_id' => array(
'integer', $wf_subject[
'identifier']),
85 'context_type' => array(
'text', $wf_context[
'type']),
86 'context_id' => array(
'integer', $wf_context[
'identifier']),
87 'workflow_instance' => array(
'clob', $instance),
88 'active' => array(
'integer', (
int) $active)
93 if ($require_data_persistance) {
94 self::persistWorkflowIOData($workflow);
101 public static function persistWorkflowIOData(
ilWorkflow $workflow)
105 $ilDB = $DIC[
'ilDB'];
107 $workflow_id = $workflow->getId();
109 $input_data = $workflow->getInputVars();
110 foreach ($input_data as
$name => $value) {
113 array(
'workflow_id' => $workflow_id,
'name' =>
$name),
114 array(
'value' => $value)
118 $output_data = $workflow->getOutputVars();
119 foreach ($output_data as
$name => $value) {
122 array(
'workflow_id' => $workflow_id,
'name' =>
$name),
123 array(
'value' => $value)
136 public static function deleteWorkflow(
ilWorkflow $a_workflow)
140 $ilDB = $DIC[
'ilDB'];
146 WHERE workflow_id = ' .
$ilDB->quote($a_workflow->
getDbId(),
'integer')
153 FROM wfe_det_listening 154 WHERE workflow_id = ' .
$ilDB->quote($a_workflow->
getDbId(),
'integer')
160 WHERE workflow_id = ' .
$ilDB->quote($a_workflow->
getDbId(),
'integer')
166 WHERE workflow_id = ' .
$ilDB->quote($a_workflow->
getDbId(),
'integer')
180 public static function writeDetector(
ilDetector $a_detector)
184 $ilDB = $DIC[
'ilDB'];
186 if ($a_detector->hasDbId()) {
187 $det_id = $a_detector->getDbId();
188 $mode = self::DB_MODE_UPDATE;
190 $det_id =
$ilDB->nextId(
'wfe_det_listening');
191 $a_detector->setDbId($det_id);
192 $mode = self::DB_MODE_CREATE;
195 $node = $a_detector->getContext();
196 $workflow = $node->getContext();
203 $det_data = $a_detector->getEvent();
204 $det_subject = $a_detector->getEventSubject();
205 $det_context = $a_detector->getEventContext();
206 $det_listen = $a_detector->getListeningTimeframe();
208 if ($det_context[
'identifier'] ===
'{{THIS:WFID}}') {
209 $det_context[
'identifier'] = $wf_id;
212 if ($det_subject[
'identifier'] ===
'{{THIS:WFID}}') {
213 $det_subject[
'identifier'] = $wf_id;
216 if ($mode == self::DB_MODE_UPDATE) {
220 'workflow_id' => array(
'integer', $wf_id),
221 'type' => array(
'text', $det_data[
'type'] ),
222 'content' => array(
'text', $det_data[
'content']),
223 'subject_type' => array(
'text', $det_subject[
'type']),
224 'subject_id' => array(
'integer', $det_subject[
'identifier']),
225 'context_type' => array(
'text', $det_context[
'type']),
226 'context_id' => array(
'integer', $det_context[
'identifier']),
227 'listening_start' => array(
'integer', $det_listen[
'listening_start']),
228 'listening_end' => array(
'integer', $det_listen[
'listening_end'])
231 'detector_id' => array(
'integer', $det_id)
236 if ($mode == self::DB_MODE_CREATE) {
240 'detector_id' => array(
'integer', $det_id),
241 'workflow_id' => array(
'integer', $wf_id),
242 'type' => array(
'text', $det_data[
'type'] ),
243 'content' => array(
'text', $det_data[
'content']),
244 'subject_type' => array(
'text', $det_subject[
'type']),
245 'subject_id' => array(
'integer', $det_subject[
'identifier']),
246 'context_type' => array(
'text', $det_context[
'type']),
247 'context_id' => array(
'integer', $det_context[
'identifier']),
248 'listening_start' => array(
'integer', $det_listen[
'listening_start']),
249 'listening_end' => array(
'integer', $det_listen[
'listening_end'])
268 $ilDB = $DIC[
'ilDB'];
273 FROM wfe_det_listening 274 WHERE detector_id = ' .
$ilDB->quote($detector->
getDbId(),
'integer')
296 public static function getDetectors(
306 $ilDB = $DIC[
'ilDB'];
308 require_once
'./Services/WorkflowEngine/classes/utils/class.ilWorkflowUtils.php';
309 $now = ilWorkflowUtils::time();
310 $workflows = array();
314 FROM wfe_det_listening 315 WHERE type = ' .
$ilDB->quote(
$type,
'text') .
' 316 AND content = ' .
$ilDB->quote($content,
'text') .
' 317 AND subject_type = ' .
$ilDB->quote($subject_type,
'text') .
' 318 AND (subject_id = ' .
$ilDB->quote($subject_id,
'integer') .
' OR subject_id = ' .
$ilDB->quote(0,
'integer') .
') 319 AND context_type = ' .
$ilDB->quote($context_type,
'text') .
' 320 AND (context_id = ' .
$ilDB->quote($context_id,
'integer') .
' OR context_id = ' .
$ilDB->quote(0,
'integer') .
') 321 AND (listening_start = ' .
$ilDB->quote(0,
'integer') .
' 322 OR listening_start <= ' .
$ilDB->quote($now,
'integer') .
') AND (listening_end = ' .
$ilDB->quote(0,
'integer') .
' 323 OR listening_end >= ' .
$ilDB->quote($now,
'integer') .
')' 327 $workflows[] =
$row[
'workflow_id'];
343 public static function wakeupWorkflow(
$id)
347 $ilDB = $DIC[
'ilDB'];
350 'SELECT workflow_class, workflow_location, workflow_instance 352 WHERE workflow_id = ' .
$ilDB->quote(
$id,
'integer')
357 require_once
'./Services/WorkflowEngine/classes/workflows/class.ilBaseWorkflow.php';
358 $path = rtrim($workflow[
'workflow_location'],
'/') .
'/' . $workflow[
'workflow_class'];
362 $instance = unserialize($workflow[
'workflow_instance']);
376 public static function writeStartEventData($event, $process_id)
380 $ilDB = $DIC[
'ilDB'];
382 $event_id =
$ilDB->nextId(
'wfe_startup_events');
385 'wfe_startup_events',
387 'event_id' => array(
'integer', $event_id),
388 'workflow_id' => array(
'text', $process_id),
389 'type' => array(
'text', $event[
'type'] ),
390 'content' => array(
'text', $event[
'content']),
391 'subject_type' => array(
'text', $event[
'subject_type']),
392 'subject_id' => array(
'integer', $event[
'subject_id']),
393 'context_type' => array(
'text', $event[
'context_type']),
394 'context_id' => array(
'integer', $event[
'context_id'])
406 public static function writeStaticInput(
$key, $value, $start_event)
410 $ilDB = $DIC[
'ilDB'];
415 'input_id' => array(
'integer',
$ilDB->nextId(
'wfe_static_inputs')),
416 'event_id' => array(
'integer', $start_event),
417 'name' => array(
'text',
$key),
418 'value' => array(
'text', $value)
423 public static function findApplicableWorkflows($component, $event,
$params)
425 $query =
"SELECT event_id, workflow_id FROM wfe_startup_events WHERE 426 type = '" . $component .
"' AND content = '" . $event .
"' AND subject_type = '" .
$params->getSubjectType() .
"' 427 AND context_type = '" .
$params->getContextType() .
"' ";
429 $query .=
"AND ( subject_id = '" .
$params->getSubjectId() .
"' OR subject_id ='0' ) ";
430 $query .=
"AND ( context_id = '" .
$params->getContextId() .
"' OR context_id ='0' ) ";
434 $ilDB = $DIC[
'ilDB'];
436 $workflows = array();
439 $workflows[] = array(
'event' =>
$row[
'event_id'],
'workflow' =>
$row[
'workflow_id']);
444 public static function getStaticInputDataForEvent($event_id)
446 $query =
"SELECT name, value FROM wfe_static_inputs WHERE event_id = '" . $event_id .
"'";
450 $ilDB = $DIC[
'ilDB'];
457 $retval[
$row[
'name']] = $row[
'value'];
463 public static function deleteStartEventData($event_id)
467 $ilDB = $DIC[
'ilDB'];
470 'SELECT event_id FROM wfe_startup_events 471 WHERE workflow_id = ' .
$ilDB->quote($event_id,
'integer')
481 FROM wfe_startup_events 482 WHERE workflow_id = ' .
$ilDB->quote($event_id,
'integer')
488 FROM wfe_static_inputs 489 WHERE ' .
$ilDB->in(
'event_id',
$events,
false,
'integer')
if(!array_key_exists('StateId', $_REQUEST)) $id
isDataPersistenceRequired()
resetDataPersistenceRequirement()
ilWorkflowDbHelper is part of the petri net based workflow engine.
ilDetector Interface is part of the petri net based workflow engine.