ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
51  global $DIC;
53  $ilSetting = $DIC['ilSetting'];
54 
55  if(0 == $ilSetting->get('wfe_activation', 0))
56  {
57  return;
58  }
59 
60  // Get listening event-detectors.
62  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
63  $workflows = ilWorkflowDbHelper::getDetectors(
64  $type,
65  $content,
66  $subject_type,
67  $subject_id,
68  $context_type,
69  $context_id
70  );
71 
72  if (count($workflows) != 0)
73  {
74  foreach ($workflows as $workflow_id)
75  {
76  $wf_instance = ilWorkflowDbHelper::wakeupWorkflow($workflow_id);
77  if($wf_instance == null)
78  {
79  continue;
80  }
81 
82  $wf_instance->handleEvent(
83  array(
84  $type,
85  $content,
86  $subject_type,
87  $subject_id,
88  $context_type,
89  $context_id
90  )
91  );
92  ilWorkflowDbHelper::writeWorkflow($wf_instance);
93  }
94  }
95  }
96 
102  public function handleEvent($component, $event, $parameter)
103  {
104  global $DIC;
106  $ilSetting = $DIC['ilSetting'];
107 
108  if(0 == $ilSetting->get('wfe_activation', 0))
109  {
110  return;
111  }
112 
113  // Event incoming, check ServiceDisco (TODO, for now we're using a non-disco factory), call appropriate extractors.
114 
116  require_once './Services/WorkflowEngine/classes/extractors/class.ilExtractorFactory.php';
118  require_once './Services/WorkflowEngine/interfaces/ilExtractor.php';
119 
120  $extractor = ilExtractorFactory::getExtractorByEventDescriptor($component);
121 
122  if($extractor instanceof ilExtractor)
123  {
124  $extracted_params = $extractor->extract($event, $parameter);
125 
126  $ilLocalSetting = new ilSetting('wfe');
127  $mappers = json_decode($ilLocalSetting->get('custom_mapper',json_encode(array())), true);
128  foreach((array)$mappers as $mapper)
129  {
130  if(!file_exists($mapper['location']))
131  {
132  continue;
133  }
134 
135  include_once $mapper['location'];
136  if(!class_exists($mapper['class']))
137  {
138  continue;
139  }
140 
141  $mapper_class = $mapper['class'];
142  $extracted_params = $mapper_class::mapParams($component, $event, $parameter, $extracted_params);
143  $component = $mapper_class::mapComponent($component, $event, $parameter, $extracted_params);
144  $event = $mapper_class::mapEvent($component, $event, $parameter, $extracted_params);
145  }
146 
147  $this->processEvent(
148  $component,
149  $event,
150  $extracted_params->getSubjectType(),
151  $extracted_params->getSubjectId(),
152  $extracted_params->getContextType(),
153  $extracted_params->getContextId()
154  );
155 
156  $this->launchArmedWorkflows($component, $event, $extracted_params);
157  }
158  }
159 
163  public function launchArmedWorkflows($component, $event, $extractedParams)
164  {
165 
166  global $DIC;
168  $ilSetting = $DIC['ilSetting'];
169 
170  if(0 == $ilSetting->get('wfe_activation', 0))
171  {
172  return;
173  }
174 
175  $workflows = ilWorkflowDbHelper::findApplicableWorkflows($component, $event, $extractedParams);
176 
177  foreach($workflows as $workflow)
178  {
179  $data = ilWorkflowDbHelper::getStaticInputDataForEvent($workflow['event']);
180 
182  require_once './Services/WorkflowEngine/classes/class.ilObjWorkflowEngine.php';
183 
184  require_once ilObjWorkflowEngine::getRepositoryDir() . $workflow['workflow'] . '.php';
185  $class = substr($workflow['workflow'],4);
187  $workflow_instance = new $class;
188 
189  $workflow_instance->setWorkflowClass('wfd.'.$class.'.php');
190  $workflow_instance->setWorkflowLocation(ilObjWorkflowEngine::getRepositoryDir());
191 
192  if(count($workflow_instance->getInputVars()))
193  {
194  foreach ($workflow_instance->getInputVars() as $input_var)
195  {
196  $workflow_instance->setInstanceVarById($input_var['name'], $data[ $input_var['name'] ]);
197  }
198  }
199 
200  $workflow_instance->setInstanceVarByRole($extractedParams->getContextType(), $extractedParams->getContextId());
201  $workflow_instance->setInstanceVarByRole($extractedParams->getSubjectType(), $extractedParams->getSubjectId());
202 
203  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowDbHelper.php';
204  ilWorkflowDbHelper::writeWorkflow( $workflow_instance );
205 
206  $workflow_instance->startWorkflow();
207  $workflow_instance->handleEvent(
208  array(
209  'time_passed',
210  'time_passed',
211  'none',
212  0,
213  'none',
214  0
215  )
216  );
217 
218  ilWorkflowDbHelper::writeWorkflow( $workflow_instance );
219  }
220  }
221 }
ILIAS Setting Class.
Interface ilExtractor.
Definition: ilExtractor.php:7
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
global $DIC
__construct($a_mass_action=false)
ilWorkflowEngine constructor.