ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilWorkflowEngine.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
17 {
22  private $mass_action;
23 
29  public function __construct($a_mass_action = false)
30  {
31  $this->mass_action = (bool) $a_mass_action;
32  }
33 
42  public function processEvent(
43  $type,
44  $content,
45  $subject_type,
46  $subject_id,
47  $context_type,
48  $context_id
49  ) {
50  global $DIC;
52  $ilSetting = $DIC['ilSetting'];
53 
54  if (0 == $ilSetting->get('wfe_activation', 0)) {
55  return;
56  }
57 
58  // Get listening event-detectors.
60  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
61  $workflows = ilWorkflowDbHelper::getDetectors(
62  $type,
63  $content,
64  $subject_type,
65  $subject_id,
66  $context_type,
67  $context_id
68  );
69 
70  if (count($workflows) != 0) {
71  foreach ($workflows as $workflow_id) {
72  $wf_instance = ilWorkflowDbHelper::wakeupWorkflow($workflow_id);
73  if ($wf_instance == null) {
74  continue;
75  }
76 
77  $wf_instance->handleEvent(
78  array(
79  $type,
80  $content,
81  $subject_type,
82  $subject_id,
83  $context_type,
84  $context_id
85  )
86  );
87  ilWorkflowDbHelper::writeWorkflow($wf_instance);
88  }
89  }
90  }
91 
97  public function handleEvent($component, $event, $parameter)
98  {
99  global $DIC;
101  $ilSetting = $DIC['ilSetting'];
102 
103  if (0 == $ilSetting->get('wfe_activation', 0)) {
104  return;
105  }
106 
107  // Event incoming, check ServiceDisco (TODO, for now we're using a non-disco factory), call appropriate extractors.
108 
110  require_once './Services/WorkflowEngine/classes/extractors/class.ilExtractorFactory.php';
112  require_once './Services/WorkflowEngine/interfaces/ilExtractor.php';
113 
114  $extractor = ilExtractorFactory::getExtractorByEventDescriptor($component);
115 
116  if ($extractor instanceof ilExtractor) {
117  $extracted_params = $extractor->extract($event, $parameter);
118 
119  $ilLocalSetting = new ilSetting('wfe');
120  $mappers = json_decode($ilLocalSetting->get('custom_mapper', json_encode(array())), true);
121  foreach ((array) $mappers as $mapper) {
122  if (!file_exists($mapper['location'])) {
123  continue;
124  }
125 
126  include_once $mapper['location'];
127  if (!class_exists($mapper['class'])) {
128  continue;
129  }
130 
131  $mapper_class = $mapper['class'];
132  $extracted_params = $mapper_class::mapParams($component, $event, $parameter, $extracted_params);
133  $component = $mapper_class::mapComponent($component, $event, $parameter, $extracted_params);
134  $event = $mapper_class::mapEvent($component, $event, $parameter, $extracted_params);
135  }
136 
137  $this->processEvent(
138  $component,
139  $event,
140  $extracted_params->getSubjectType(),
141  $extracted_params->getSubjectId(),
142  $extracted_params->getContextType(),
143  $extracted_params->getContextId()
144  );
145 
146  $this->launchArmedWorkflows($component, $event, $extracted_params);
147  }
148  }
149 
153  public function launchArmedWorkflows($component, $event, $extractedParams)
154  {
155  global $DIC;
157  $ilSetting = $DIC['ilSetting'];
158 
159  if (0 == $ilSetting->get('wfe_activation', 0)) {
160  return;
161  }
162 
163  $workflows = ilWorkflowDbHelper::findApplicableWorkflows($component, $event, $extractedParams);
164 
165  foreach ($workflows as $workflow) {
166  $data = ilWorkflowDbHelper::getStaticInputDataForEvent($workflow['event']);
167 
169  require_once './Services/WorkflowEngine/classes/class.ilObjWorkflowEngine.php';
170 
171  if (!file_exists(ilObjWorkflowEngine::getRepositoryDir() . $workflow['workflow'] . '.php')) {
172  continue;
173  }
174 
175  require_once ilObjWorkflowEngine::getRepositoryDir() . $workflow['workflow'] . '.php';
176  $class = substr($workflow['workflow'], 4);
178  $workflow_instance = new $class;
179 
180  $workflow_instance->setWorkflowClass('wfd.' . $class . '.php');
181  $workflow_instance->setWorkflowLocation(ilObjWorkflowEngine::getRepositoryDir());
182 
183  if (count($workflow_instance->getInputVars())) {
184  foreach ($workflow_instance->getInputVars() as $input_var) {
185  $workflow_instance->setInstanceVarById($input_var['name'], $data[ $input_var['name'] ]);
186  }
187  }
188 
189  $workflow_instance->setInstanceVarByRole($extractedParams->getContextType(), $extractedParams->getContextId());
190  $workflow_instance->setInstanceVarByRole($extractedParams->getSubjectType(), $extractedParams->getSubjectId());
191 
192  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
193  ilWorkflowDbHelper::writeWorkflow($workflow_instance);
194 
195  $workflow_instance->startWorkflow();
196  $workflow_instance->handleEvent(
197  array(
198  'time_passed',
199  'time_passed',
200  'none',
201  0,
202  'none',
203  0
204  )
205  );
206 
207  ilWorkflowDbHelper::writeWorkflow($workflow_instance);
208  }
209  }
210 }
$type
global $DIC
Definition: saml.php:7
Interface ilExtractor.
Definition: ilExtractor.php:7
static getRepositoryDir($relative=false)
ilWorkflowEngine is part of the petri net based workflow engine.
static getExtractorByEventDescriptor($component)
Create styles array
The data for the language used.
global $ilSetting
Definition: privfeed.php:17
__construct($a_mass_action=false)
ilWorkflowEngine constructor.