ILIAS  release_8 Revision v8.24
class.ilMStListCompetencesSkillsTableGUI.php
Go to the documentation of this file.
1<?php
20
21use Closure;
23use ilCSVWriter;
24use ilExcel;
33use ilTable2GUI;
36
42{
43 protected array $filter = [];
44 protected array $selectable_columns_cached = [];
45 protected array $usr_orgu_names = [];
47 protected Container $dic;
48
50 {
51 $this->dic = $dic;
53
54 $this->setPrefix('myst_cs');
55 $this->setFormName('myst_cs');
56 $this->setId('myst_cs');
57
58 parent::__construct($parent_obj, $parent_cmd, '');
59
60 $this->setRowTemplate('tpl.list_skills_row.html', "Services/MyStaff");
61 $this->setFormAction($this->dic->ctrl()->getFormAction($parent_obj));
62 $this->setDefaultOrderDirection('desc');
63
64 $this->setShowRowsSelector(true);
65
66 $this->setEnableTitle(true);
67 $this->setDisableFilterHiding(true);
68 $this->setEnableNumInfo(true);
69
70 $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
71
72 $this->setFilterCols(5);
73 $this->initFilter();
74
75 $this->addColumns();
76
77 $this->parseData();
78 }
79
80 protected function parseData(): void
81 {
82 $this->setExternalSorting(true);
83 $this->setExternalSegmentation(true);
84 $this->setDefaultOrderField('skill_title');
85
86 $this->determineLimit();
88
89 $options = array(
90 'filters' => $this->filter,
91 'limit' => array(
92 'start' => $this->getOffset(),
93 'end' => $this->getLimit(),
94 ),
95 'count' => true,
96 'sort' => array(
97 'field' => $this->getOrderField(),
98 'direction' => $this->getOrderDirection(),
99 ),
100 );
101
102 $skills_fetcher = new ilMStListCompetencesSkills($this->dic);
103 $result = $skills_fetcher->getData($options);
104
105 $this->setMaxCount($result->getTotalDatasetCount());
106 $data = $result->getDataset();
107
108 // Workaround because the fillRow Method only accepts arrays
109 $data = array_map(function (ilMStListCompetencesSkill $it): array {
110 return [$it];
111 }, $data);
112 $this->setData($data);
113 }
114
115 final public function initFilter(): void
116 {
117 // skill
118 $item = new ilTextInputGUI($this->dic->language()->txt("skmg_skill"), 'skill');
119 $this->addFilterItem($item);
120 $item->readFromSession();
121 $this->filter['skill'] = $item->getValue();
122
123 // skill level
124 $item = new ilTextInputGUI($this->dic->language()->txt("skmg_skill_level"), 'skill_level');
125 $this->addFilterItem($item);
126 $item->readFromSession();
127 $this->filter['skill_level'] = $item->getValue();
128
129 //user
130 $item = new ilTextInputGUI(
131 $this->dic->language()->txt("login") . "/" . $this->dic->language()->txt("email") . "/" . $this->dic->language()
132 ->txt("name"),
133 "user"
134 );
135
136 $this->addFilterItem($item);
137 $item->readFromSession();
138 $this->filter['user'] = $item->getValue();
139
140 // orgunits
141 if (ilUserSearchOptions::_isEnabled('org_units')) {
143 $options[0] = $this->dic->language()->txt('mst_opt_all');
144 foreach ($paths as $org_ref_id => $path) {
145 $options[$org_ref_id] = $path;
146 }
147 $item = new ilSelectInputGUI($this->dic->language()->txt('obj_orgu'), 'org_unit');
148 $item->setOptions($options);
149 $this->addFilterItem($item);
150 $item->readFromSession();
151 $this->filter['org_unit'] = $item->getValue();
152 }
153 }
154
155 final public function getSelectableColumns(): array
156 {
157 if ($this->selectable_columns_cached) {
159 }
160
161 return $this->selectable_columns_cached = $this->initSelectableColumns();
162 }
163
164 protected function initSelectableColumns(): array
165 {
166 $cols = array();
167
168 $arr_searchable_user_columns = ilUserSearchOptions::getSelectableColumnInfo();
169
170 $cols['skill_title'] = array(
171 'txt' => $this->dic->language()->txt('skmg_skill'),
172 'default' => true,
173 'width' => 'auto',
174 'sort_field' => 'skill_title',
175 );
176 $cols['skill_level'] = array(
177 'txt' => $this->dic->language()->txt('skmg_skill_level'),
178 'default' => true,
179 'width' => 'auto',
180 'sort_field' => 'skill_level',
181 );
182
183 if ($arr_searchable_user_columns['login'] ?? false) {
184 $cols['login'] = array(
185 'txt' => $this->dic->language()->txt('login'),
186 'default' => true,
187 'width' => 'auto',
188 'sort_field' => 'login',
189 );
190 }
191 if ($arr_searchable_user_columns['firstname'] ?? false) {
192 $cols['first_name'] = array(
193 'txt' => $this->dic->language()->txt('firstname'),
194 'default' => true,
195 'width' => 'auto',
196 'sort_field' => 'firstname',
197 );
198 }
199 if ($arr_searchable_user_columns['lastname'] ?? false) {
200 $cols['last_name'] = array(
201 'txt' => $this->dic->language()->txt('lastname'),
202 'default' => true,
203 'width' => 'auto',
204 'sort_field' => 'lastname',
205 );
206 }
207 if ($arr_searchable_user_columns['email'] ?? false) {
208 $cols['email'] = array(
209 'txt' => $this->dic->language()->txt('email'),
210 'default' => true,
211 'width' => 'auto',
212 'sort_field' => 'email',
213 );
214 }
215 if ($arr_searchable_user_columns['org_units'] ?? false) {
216 $cols['usr_assinged_orgus'] = array(
217 'txt' => $this->dic->language()->txt('objs_orgu'),
218 'default' => true,
219 'width' => 'auto',
220 );
221 }
222
223 return $cols;
224 }
225
226 private function addColumns(): void
227 {
228 foreach ($this->getSelectableColumns() as $k => $v) {
229 if ($this->isColumnSelected($k)) {
230 $sort = $v['sort_field'] ?? "";
231 $this->addColumn($v['txt'], $sort);
232 }
233 }
234
235 //Actions
236 if (!$this->getExportMode()) {
237 $this->addColumn($this->dic->language()->txt('actions'));
238 }
239 }
240
241 protected function getTextRepresentationOfUsersOrgUnits(int $user_id): string
242 {
243 if (isset($this->usr_orgu_names[$user_id])) {
244 return $this->usr_orgu_names[$user_id];
245 }
246
247 return $this->usr_orgu_names[$user_id] = \ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_id);
248 }
249
253 final protected function fillRow(array $a_set): void
254 {
255 $set = array_pop($a_set);
256
257 $propGetter = Closure::bind(function ($prop) {
258 return $this->$prop ?? null;
259 }, $set, $set);
260
261 foreach ($this->getSelectedColumns() as $k => $v) {
262 switch ($k) {
263 case 'usr_assinged_orgus':
264 $this->tpl->setCurrentBlock('td');
265 $this->tpl->setVariable(
266 'VALUE',
267 $this->getTextRepresentationOfUsersOrgUnits($set->getUserId())
268 );
269 $this->tpl->parseCurrentBlock();
270 break;
271 default:
272 if ($propGetter($k) !== null) {
273 $this->tpl->setCurrentBlock('td');
274 $this->tpl->setVariable(
275 'VALUE',
276 (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k))
277 );
278 $this->tpl->parseCurrentBlock();
279 } else {
280 $this->tpl->setCurrentBlock('td');
281 $this->tpl->setVariable('VALUE', '&nbsp;');
282 $this->tpl->parseCurrentBlock();
283 }
284 break;
285 }
286 }
287
288 $actions = new ilAdvancedSelectionListGUI();
289 $actions->setListTitle($this->dic->language()->txt("actions"));
290 $actions->setId($set->getUserId() . "-" . $set->getSkillNodeId());
291
292 $mst_lcom_usr_id = $set->getUserId();
293
294 $this->dic->ctrl()->setParameterByClass(get_class($this->parent_obj), 'mst_lcom_usr_id', $mst_lcom_usr_id);
295
296 $actions = \ilMyStaffGUI::extendActionMenuWithUserActions(
297 $actions,
298 $mst_lcom_usr_id,
299 rawurlencode($this->dic->ctrl()->getLinkTargetByClass(
300 "ilMStListCompetencesSkillsGUI",
302 ))
303 );
304
305 $this->tpl->setVariable('ACTIONS', $actions->getHTML());
306 $this->tpl->parseCurrentBlock();
307 }
308
309 protected function fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set): void
310 {
311 $set = array_pop($a_set);
312
313 $col = 0;
314 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
315 $a_excel->setCell($a_row, $col, $v);
316 $col++;
317 }
318 }
319
320 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
321 {
322 $set = array_pop($a_set);
323
324 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
325 $a_csv->addColumn($v);
326 }
327 $a_csv->addRow();
328 }
329
330 protected function getFieldValuesForExport(ilMStListCompetencesSkill $selected_skill): array
331 {
332 $propGetter = Closure::bind(function ($prop) {
333 return $this->$prop ?? null;
334 }, $selected_skill, $selected_skill);
335
336 $field_values = array();
337 foreach ($this->getSelectedColumns() as $k => $v) {
338 switch ($k) {
339 case 'usr_assinged_orgus':
340 $field_values[$k] = $this->getTextRepresentationOfUsersOrgUnits($selected_skill->getUserId());
341 break;
342 default:
343 $field_values[$k] = strip_tags($propGetter($k) ?? "");
344 break;
345 }
346 }
347
348 return $field_values;
349 }
350}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
Excel Version of Fill Row.
__construct(ilMStListCompetencesSkillsGUI $parent_obj, string $parent_cmd, Container $dic)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addColumn(string $a_col)
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
Class ilMStListCompetencesGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilMStListCompetencesSkills.
Class ilOrgUnitPathStorage.
static getTextRepresentationOfOrgUnits(bool $sort_by_title=true)
Get ref id path array.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isColumnSelected(string $col)
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
determineOffsetAndOrder(bool $a_omit_offset=false)
setEnableNumInfo(bool $a_val)
setExportFormats(array $formats)
Set available export formats.
setExternalSegmentation(bool $a_val)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setEnableTitle(bool $a_enabletitle)
setFormName(string $a_name="")
setPrefix(string $a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setDefaultOrderField(string $a_defaultorderfield)
setDisableFilterHiding(bool $a_val=true)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setFilterCols(int $a_val)
setData(array $a_data)
Set table data.
setMaxCount(int $a_max_count)
set max.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getSelectableColumnInfo(bool $a_admin=false)
Get info of searchable fields for selectable columns in table gui.
$path
Definition: ltiservices.php:32
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$cols
Definition: xhr_table.php:11