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