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