ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilWorkflowEngineDefinitionsTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
5 require_once './Services/Table/classes/class.ilTable2GUI.php';
7 require_once './Services/Form/classes/class.ilTextInputGUI.php';
9 require_once './Services/Form/classes/class.ilCheckboxInputGUI.php';
11 require_once './Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
12 
23 {
25  protected $ilCtrl;
26 
28  protected $lng;
29 
37  public function __construct($parent_obj, $parent_cmd, $template_context ="")
38  {
39  $this->setId('wfedef');
40  parent::__construct($parent_obj, $parent_cmd, $template_context);
41 
42  global $DIC;
43  $this->ilCtrl = $DIC['ilCtrl'];
44  $this->lng = $DIC['lng'];
45 
46  $this->initColumns();
47  $this->setEnableHeader(true);
48 
49  $this->setFormAction($this->ilCtrl->getFormAction($parent_obj));
50 
51  $this->initFilter();
52 
53  $this->setRowTemplate("tpl.wfe_def_row.html", "Services/WorkflowEngine");
54  $this->getProcessesForDisplay();
55 
56  $this->setTitle($this->lng->txt("definitions"));
57  }
58 
62  public function initFilter()
63  {
64  $title_filter_input = new ilTextInputGUI($this->lng->txt("title"), "title");
65  $title_filter_input->setMaxLength(64);
66  $title_filter_input->setSize(20);
67  $this->addFilterItem($title_filter_input);
68  $title_filter_input->readFromSession();
69  $this->filter["title"] = $title_filter_input->getValue();
70 
71  $instances_filter_input = new ilCheckboxInputGUI($this->lng->txt('instances'), 'instances');
72  $this->addFilterItem($instances_filter_input);
73  $instances_filter_input->readFromSession();
74  $this->filter['instances'] = $instances_filter_input->getChecked();
75  }
76 
80  public function initColumns()
81  {
82  $this->addColumn($this->lng->txt("title"), "title", "20%");
83 
84  $selected_columns = $this->getSelectedColumns();
85 
86  if(in_array('file', $selected_columns))
87  {
88  $this->addColumn($this->lng->txt("file"), "file", "30%");
89  }
90 
91  if(in_array('version', $selected_columns))
92  {
93  $this->addColumn($this->lng->txt("version"), "version", "10%");
94  }
95 
96  if(in_array('status', $selected_columns))
97  {
98  $this->addColumn($this->lng->txt("status"), "status", "10%");
99  }
100 
101  if(in_array('instances', $selected_columns))
102  {
103  $this->addColumn($this->lng->txt("instances"), "instances", "15%");
104  }
105 
106  $this->addColumn($this->lng->txt("actions"), "", "10%");
107 
108  }
109 
113  public function getSelectableColumns()
114  {
115  $cols["file"] = array(
116  "txt" => $this->lng->txt("file"),
117  "default" => true);
118  $cols["version"] = array(
119  "txt" => $this->lng->txt("version"),
120  "default" => true);
121  $cols["status"] = array(
122  "txt" => $this->lng->txt("status"),
123  "default" => true);
124  $cols["instances"] = array(
125  "txt" => $this->lng->txt("instances"),
126  "default" => true);
127  return $cols;
128  }
129 
133  public function getProcessesForDisplay()
134  {
135  global $DIC;
136  $ilDB = $DIC['ilDB'];
137  $query = 'SELECT workflow_class, count(workflow_id) total, sum(active) active
138  FROM wfe_workflows
139  GROUP BY workflow_class';
140  $result = $ilDB->query($query);
141  $stats = array();
142  while($row = $ilDB->fetchAssoc($result))
143  {
144  $stats[$row['workflow_class']] = array( 'total' => $row['total'], 'active' => $row['active'] );
145  }
146 
147  $entries = array();
148 
149  if(is_dir(ilObjWorkflowEngine::getRepositoryDir().'/'))
150  {
151  $entries = scandir(ilObjWorkflowEngine::getRepositoryDir().'/');
152  }
153 
154  $base_list = array();
155  foreach($entries as $entry)
156  {
157  if( $entry == '.' || $entry == '..' )
158  {
159  continue;
160  }
161 
162  if(substr($entry, strlen($entry)-6) == '.bpmn2')
163  {
164  $file_entry = array();
165  $file_entry['file'] = $entry;
166  $file_entry['id'] = substr($entry, 0, strlen($entry)-6);
167  $parts = explode('_', substr($entry, 6, strlen($entry)-12));
168 
169  $file_entry['status'] = 'OK';
170  if(!file_exists(ilObjWorkflowEngine::getRepositoryDir() . '/' . $file_entry['id']. '.php'))
171  {
172  $file_entry['status'] = $this->lng->txt('missing_parsed_class');
173  }
174 
175  $file_entry['version'] = substr(array_pop($parts),1);
176  $file_entry['title'] = implode(' ', $parts);
177  $file_entry['instances'] = $stats[$file_entry['id'].'.php'];
178 
179  if(!$this->isFiltered($file_entry))
180  {
181  $base_list[] = $file_entry;
182  }
183  }
184  }
185 
186  $this->setDefaultOrderField("nr");
187  $this->setDefaultOrderDirection("asc");
188  $this->setData($base_list);
189  }
190 
196  public function isFiltered($row)
197  {
198  // Title filter
199  $title_filter = $this->getFilterItemByPostVar('title');
200  if($title_filter->getValue() != null)
201  {
202  if(strpos(strtolower($row['title']),strtolower($title_filter->getValue())) === false)
203  {
204  return true;
205  }
206  }
207 
208  // Instances filter
209  $instances_filter = $this->getFilterItemByPostVar('instances');
210  if($instances_filter->getChecked() && $row['instances']['active'] == 0)
211  {
212  return true;
213  }
214 
215  return false;
216  }
217 
221  protected function fillRow($set)
222  {
223 
224  $this->tpl->setVariable('VAL_TITLE', $set['title']);
225 
226  $selected_columns = $this->getSelectedColumns();
227 
228  if(in_array('file', $selected_columns))
229  {
230  $this->tpl->setVariable('VAL_FILE', $set['file']);
231  }
232 
233  if(in_array('version', $selected_columns))
234  {
235  $this->tpl->setVariable('VAL_VERSION', $set['version']);
236  }
237 
238  if(in_array('status', $selected_columns))
239  {
240  if($set['status'] != 'OK')
241  {
242  $this->tpl->setVariable('VAL_STATUS', $set['status']);
243  }
244  else
245  {
246  $this->tpl->setVariable('VAL_STATUS', $this->lng->txt('ok'));
247  }
248  }
249 
250  if(in_array('instances', $selected_columns))
251  {
252  $this->tpl->setVariable('TXT_INSTANCES_TOTAL', $this->lng->txt('total'));
253  $this->tpl->setVariable('VAL_INSTANCES_TOTAL', 0+$set['instances']['total']);
254  $this->tpl->setVariable('TXT_INSTANCES_ACTIVE', $this->lng->txt('active'));
255  $this->tpl->setVariable('VAL_INSTANCES_ACTIVE', 0+$set['instances']['active']);
256  }
257 
258  $action = new ilAdvancedSelectionListGUI();
259  $action->setId('asl_' . $set['id']);
260  $action->setListTitle($this->lng->txt('actions'));
261  $this->ilCtrl->setParameter($this->parent_obj, 'process_id', $set['id']);
262  $action->addItem(
263  $this->lng->txt('start_process'),
264  'start',
265  $this->ilCtrl->getLinkTarget($this->parent_obj ,'definitions.start')
266  );
267 
268  if(0+$set['instances']['active'] == 0)
269  {
270  $action->addItem(
271  $this->lng->txt('delete_definition'),
272  'delete',
273  $this->ilCtrl->getLinkTarget($this->parent_obj,'definitions.delete')
274  );
275  }
276 
277  require_once ilObjWorkflowEngine::getRepositoryDir() . '/' . $set['id']. '.php';
278  $class = substr($set['id'],4);
279  if($class::$startEventRequired == true)
280  {
281  $action->addItem(
282  $this->lng->txt('start_listening'),
283  'startlistening',
284  $this->ilCtrl->getLinkTarget($this->parent_obj, 'definitions.startlistening')
285  );
286 
287  $action->addItem(
288  $this->lng->txt('stop_listening'),
289  'stoplistening',
290  $this->ilCtrl->getLinkTarget($this->parent_obj, 'definitions.stoplistening')
291  );
292  }
293 
294  $this->tpl->setVariable('HTML_ASL', $action->getHTML());
295  }
296 }
setParameter($a_obj, $a_parameter, $a_value)
Set parameters that should be passed a form and link of a gui class.
This class provides processing control methods.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
$result
getFilterItemByPostVar($a_post_var)
This class represents a checkbox property in a property form.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
setId($a_val)
Set id.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
Class ilTable2GUI.
getFormAction($a_gui_obj, $a_fallback_cmd="", $a_anchor="", $a_asynch=false, $xml_style=true)
Get form action url for gui class object.
This class represents a text property in a property form.
getSelectedColumns()
Get selected columns.
setMaxLength($a_maxlength)
Set Max Length.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
Create styles array
The data for the language used.
User interface class for advanced drop-down selection lists.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
global $ilDB
getLinkTarget($a_gui_obj, $a_cmd="", $a_anchor="", $a_asynch=false, $xml_style=true)
Get link target for command using gui object.
__construct($parent_obj, $parent_cmd, $template_context="")
ilWorkflowEngineDefinitionsTableGUI constructor.
setEnableHeader($a_enableheader)
Set Enable Header.
global $DIC
addColumn($a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.