ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMStListCompetencesSkillsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Closure;
7 use ilCSVWriter;
8 use ilExcel;
17 use ilTable2GUI;
18 use ilTextInputGUI;
20 
27 {
28 
32  protected $filter = array();
40  protected $usr_orgu_names = [];
44  protected $access;
48  protected $dic;
49 
50 
56  public function __construct($parent_obj, string $parent_cmd, Container $dic)
57  {
58  $this->dic = $dic;
59  $this->access = ilMyStaffAccess::getInstance();
60 
61  $this->setPrefix('myst_cs');
62  $this->setFormName('myst_cs');
63  $this->setId('myst_cs');
64 
65  parent::__construct($parent_obj, $parent_cmd, '');
66 
67  $this->setRowTemplate('tpl.list_skills_row.html', "Services/MyStaff");
68  $this->setFormAction($this->dic->ctrl()->getFormAction($parent_obj));
69  $this->setDefaultOrderDirection('desc');
70 
71  $this->setShowRowsSelector(true);
72 
73  $this->setEnableTitle(true);
74  $this->setDisableFilterHiding(true);
75  $this->setEnableNumInfo(true);
76 
77  $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
78 
79  $this->setFilterCols(5);
80  $this->initFilter();
81 
82  $this->addColumns();
83 
84  $this->parseData();
85  }
86 
87 
91  protected function parseData()
92  {
93  $this->setExternalSorting(true);
94  $this->setExternalSegmentation(true);
95  $this->setDefaultOrderField('skill_title');
96 
97  $this->determineLimit();
98  $this->determineOffsetAndOrder();
99 
100  $options = array(
101  'filters' => $this->filter,
102  'limit' => array(),
103  'count' => true,
104  'sort' => array(
105  'field' => $this->getOrderField(),
106  'direction' => $this->getOrderDirection(),
107  ),
108  );
109 
110 
111  $skills_fetcher = new ilMStListCompetencesSkills($this->dic);
112  $count = $skills_fetcher->getData($options);
113  $options['limit'] = array(
114  'start' => intval($this->getOffset()),
115  'end' => intval($this->getLimit()),
116  );
117  $options['count'] = false;
118  $data = $skills_fetcher->getData($options);
119  $this->setMaxCount($count);
120  $this->setData($data);
121  }
122 
123 
127  public function initFilter()
128  {
129  // skill
130  $item = new ilTextInputGUI($this->dic->language()->txt("skmg_skill"), 'skill');
131  $this->addFilterItem($item);
132  $item->readFromSession();
133  $this->filter['skill'] = $item->getValue();
134 
135  // skill level
136  $item = new ilTextInputGUI($this->dic->language()->txt("skmg_skill_level"), 'skill_level');
137  $this->addFilterItem($item);
138  $item->readFromSession();
139  $this->filter['skill_level'] = $item->getValue();
140 
141  //user
142  $item = new ilTextInputGUI($this->dic->language()->txt("login") . "/" . $this->dic->language()->txt("email") . "/" . $this->dic->language()
143  ->txt("name"), "user");
144 
145  $this->addFilterItem($item);
146  $item->readFromSession();
147  $this->filter['user'] = $item->getValue();
148 
149  // orgunits
150  if (ilUserSearchOptions::_isEnabled('org_units')) {
152  $options[0] = $this->dic->language()->txt('mst_opt_all');
153  foreach ($paths as $org_ref_id => $path) {
154  $options[$org_ref_id] = $path;
155  }
156  $item = new ilSelectInputGUI($this->dic->language()->txt('obj_orgu'), 'org_unit');
157  $item->setOptions($options);
158  $this->addFilterItem($item);
159  $item->readFromSession();
160  $this->filter['org_unit'] = $item->getValue();
161  }
162  }
163 
164  public function getSelectableColumns() : array
165  {
166  if ($this->selectable_columns_cached) {
168  }
169 
170  return $this->selectable_columns_cached = $this->initSelectableColumns();
171  }
172 
173  protected function initSelectableColumns() : array
174  {
175  $cols = array();
176 
177  $arr_searchable_user_columns = ilUserSearchOptions::getSelectableColumnInfo();
178 
179  $cols['skill_title'] = array(
180  'txt' => $this->dic->language()->txt('skmg_skill'),
181  'default' => true,
182  'width' => 'auto',
183  'sort_field' => 'skill_title',
184  );
185  $cols['skill_level'] = array(
186  'txt' => $this->dic->language()->txt('skmg_skill_level'),
187  'default' => true,
188  'width' => 'auto',
189  'sort_field' => 'skill_level',
190  );
191 
192  if ($arr_searchable_user_columns['login']) {
193  $cols['login'] = array(
194  'txt' => $this->dic->language()->txt('login'),
195  'default' => true,
196  'width' => 'auto',
197  'sort_field' => 'login',
198  );
199  }
200  if ($arr_searchable_user_columns['firstname']) {
201  $cols['first_name'] = array(
202  'txt' => $this->dic->language()->txt('firstname'),
203  'default' => true,
204  'width' => 'auto',
205  'sort_field' => 'firstname',
206  );
207  }
208  if ($arr_searchable_user_columns['lastname']) {
209  $cols['last_name'] = array(
210  'txt' => $this->dic->language()->txt('lastname'),
211  'default' => true,
212  'width' => 'auto',
213  'sort_field' => 'lastname',
214  );
215  }
216  if ($arr_searchable_user_columns['email']) {
217  $cols['email'] = array(
218  'txt' => $this->dic->language()->txt('email'),
219  'default' => true,
220  'width' => 'auto',
221  'sort_field' => 'email',
222  );
223  }
224  if ($arr_searchable_user_columns['org_units'] ?? false) {
225  $cols['usr_assinged_orgus'] = array(
226  'txt' => $this->dic->language()->txt('objs_orgu'),
227  'default' => true,
228  'width' => 'auto',
229  );
230  }
231 
232  return $cols;
233  }
234 
235 
239  private function addColumns()
240  {
241  foreach ($this->getSelectableColumns() as $k => $v) {
242  if ($this->isColumnSelected($k)) {
243  if (isset($v['sort_field'])) {
244  $sort = $v['sort_field'];
245  } else {
246  $sort = null;
247  }
248  $this->addColumn($v['txt'], $sort, $v['width']);
249  }
250  }
251 
252  //Actions
253  if (!$this->getExportMode()) {
254  $this->addColumn($this->dic->language()->txt('actions'));
255  }
256  }
257 
258  protected function getTextRepresentationOfUsersOrgUnits(int $user_id) : string
259  {
260  if (isset($this->usr_orgu_names[$user_id])) {
261  return $this->usr_orgu_names[$user_id];
262  }
263 
264  return $this->usr_orgu_names[$user_id] = \ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_id);
265  }
266 
270  public function fillRow($profile)
271  {
272  $propGetter = Closure::bind(function ($prop) {
273  return $this->$prop;
274  }, $profile, $profile);
275 
276  foreach ($this->getSelectedColumns() as $k => $v) {
277  switch ($k) {
278  case 'usr_assinged_orgus':
279  $this->tpl->setCurrentBlock('td');
280  $this->tpl->setVariable(
281  'VALUE',
282  $this->getTextRepresentationOfUsersOrgUnits($profile->getUserId())
283  );
284  $this->tpl->parseCurrentBlock();
285  break;
286  default:
287  if ($propGetter($k) !== null) {
288  $this->tpl->setCurrentBlock('td');
289  $this->tpl->setVariable(
290  'VALUE',
291  (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k))
292  );
293  $this->tpl->parseCurrentBlock();
294  } else {
295  $this->tpl->setCurrentBlock('td');
296  $this->tpl->setVariable('VALUE', '&nbsp;');
297  $this->tpl->parseCurrentBlock();
298  }
299  break;
300  }
301  }
302 
303  $actions = new ilAdvancedSelectionListGUI();
304  $actions->setListTitle($this->dic->language()->txt("actions"));
305  $actions->setId($profile->getUserId() . "-" . $profile->getSkillNodeId());
306 
307  $mst_lcom_usr_id = $profile->getUserId();
308 
309  $this->dic->ctrl()->setParameterByClass(get_class($this->parent_obj), 'mst_lcom_usr_id', $mst_lcom_usr_id);
310 
311  $actions = \ilMyStaffGUI::extendActionMenuWithUserActions(
312  $actions,
313  $mst_lcom_usr_id,
314  rawurlencode($this->dic->ctrl()->getLinkTargetByClass(
315  "ilMStListCompetencesSkillsGUI",
317  ))
318  );
319 
320  $this->tpl->setVariable('ACTIONS', $actions->getHTML());
321  $this->tpl->parseCurrentBlock();
322  }
323 
324 
330  protected function fillRowExcel(ilExcel $a_excel, &$a_row, $selected_skill)
331  {
332  $col = 0;
333  foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) {
334  $a_excel->setCell($a_row, $col, $v);
335  $col++;
336  }
337  }
338 
339 
344  protected function fillRowCSV($a_csv, $selected_skill)
345  {
346  foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) {
347  $a_csv->addColumn($v);
348  }
349  $a_csv->addRow();
350  }
351 
352 
358  protected function getFieldValuesForExport(ilMStListCompetencesSkill $selected_skill)
359  {
360  $propGetter = Closure::bind(function ($prop) {
361  return $this->$prop;
362  }, $selected_skill, $selected_skill);
363 
364  $field_values = array();
365  foreach ($this->getSelectedColumns() as $k => $v) {
366  switch ($k) {
367  case 'usr_assinged_orgus':
368  $field_values[$k] = $this->getTextRepresentationOfUsersOrgUnits($selected_skill->getUserId());
369  break;
370  default:
371  $field_values[$k] = strip_tags($propGetter($k));
372  break;
373  }
374  }
375 
376  return $field_values;
377  }
378 }
setExternalSorting($a_val)
Set external sorting.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setExportFormats(array $formats)
Set available export formats.
setEnableNumInfo($a_val)
Set enable num info.
setFilterCols($a_val)
Set filter columns.
setExternalSegmentation($a_val)
Set external segmentation.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
determineLimit()
Determine the limit.
getOrderDirection()
Get order direction.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:18
setId($a_val)
Set id.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
static getTextRepresentationOfOrgUnits($sort_by_title=true)
Get ref id path array.
static getSelectableColumnInfo($a_admin=false)
Get info of searchable fields for selectable columns in table gui.
getOffset()
Get offset.
setDisableFilterHiding($a_val=true)
Set disable filter hiding.
setPrefix($a_prefix)
getSelectedColumns()
Get selected columns.
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
isColumnSelected($a_col)
Is given column selected?
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setFormName($a_formname="")
Set Form name.
__construct(Container $dic, ilPlugin $plugin)
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.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
getLimit()
Get limit.
filter()
Definition: filter.php:2
setMaxCount($a_max_count)
set max.
getExportMode()
Was export activated?
setEnableTitle($a_enabletitle)
Set Enable Title.
$cols
Definition: xhr_table.php:11