ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLearningSequenceParticipantsTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\User\Profile\Data as ProfileData;
23
25{
30 protected ilAccess $access;
33 protected Profile $profile;
34
35 public function __construct(
45 ) {
46 $this->parent_gui = $parent_gui;
47 $this->rep_object = $ls_object;
48
49 $this->obj_user_tracking = $obj_user_tracking;
50 $this->privacy_settings = $privacy_settings;
51 $this->lng = $lng;
52 $this->access = $access;
53 $this->rbac_review = $rbac_review;
54 $this->settings = $settings;
55 $this->profile = $profile;
56
57 $this->lng->loadLanguageModule('lso');
58 $this->lng->loadLanguageModule('trac');
59 $this->lng->loadLanguageModule('rbac');
60 $this->lng->loadLanguageModule('mmbr');
61 $this->lng->loadLanguageModule('user');
62 $this->lng->loadLanguageModule('ps');
63
64 $this->participants = $ls_object->getLSParticipants();
65
66 $this->setPrefix('participants');
67
68 $this->setId('lso_' . $this->getRepositoryObject()->getId());
69 parent::__construct($parent_gui, 'participants');
70
71 $this->initSettings();
72 $this->initForm();
73 }
74
75 protected function initForm(): void
76 {
77 $this->setFormName('participants');
78 $this->setDefaultOrderField('roles');
79 $this->setRowTemplate("tpl.show_participants_row.html", "components/ILIAS/LearningSequence");
80 $this->setShowRowsSelector(true);
81 $this->setSelectAllCheckbox('participants');
82
83 $this->addColumn('', 'f', "1");
84 $this->addColumn($this->lng->txt('name'), 'lastname', '20%');
85 $this->addColumn($this->lng->txt('login'), 'login');
86
87 $all_cols = $this->getSelectableColumns();
88 foreach ($this->getSelectedColumns() as $col) {
89 $this->addColumn($all_cols[$col]['txt'], $col);
90 }
91
92 if (
93 $this->obj_user_tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS) &&
95
96 ) {
97 $this->addColumn($this->lng->txt('first_access'), "first_access");
98 $this->addColumn($this->lng->txt('last_access'), "last_access");
99 }
100 $this->addColumn($this->lng->txt('completed_steps'), "completed_steps");
101 $this->addColumn($this->lng->txt('last_visited_step'), "last_visited_step");
102 $this->addColumn($this->lng->txt('lso_notification'), 'notification');
103 $this->addColumn($this->lng->txt(''), 'optional');
104
105 $this->enable('sort');
106 $this->enable('header');
107 $this->enable('numinfo');
108 $this->enable('select_all');
109
110 $this->initFilter();
111
112 $this->addMultiCommand('editParticipants', $this->lng->txt('edit'));
113 $this->addMultiCommand('confirmDeleteParticipants', $this->lng->txt('remove'));
114 $this->addMultiCommand('sendMailToSelectedUsers', $this->lng->txt('mmbr_btn_mail_selected_users'));
115 $this->addMultiCommand('addToClipboard', $this->lng->txt('clipboard_add_btn'));
116 $this->addCommandButton('updateParticipantsStatus', $this->lng->txt('save'));
117 }
118
119 protected function fillRow(array $a_set): void
120 {
121 $this->tpl->setVariable('VAL_ID', $a_set['usr_id']);
122 $this->tpl->setVariable('VAL_NAME', $a_set['lastname'] . ', ' . $a_set['firstname']);
123 $this->tpl->setVariable('VAL_LOGIN', $a_set['login']);
124
125 if (
126 !$this->access->checkAccessOfUser((int) $a_set['usr_id'], 'read', '', $this->getRepositoryObject()->getRefId()) &&
127 is_array($info = $this->access->getInfo())
128 ) {
129 $this->tpl->setCurrentBlock('access_warning');
130 $this->tpl->setVariable('PARENT_ACCESS', $info[0]['text']);
131 $this->tpl->parseCurrentBlock();
132 }
133
134 if (!ilObjUser::_lookupActive((int) $a_set['usr_id'])) {
135 $this->tpl->setCurrentBlock('access_warning');
136 $this->tpl->setVariable('PARENT_ACCESS', $this->lng->txt('usr_account_inactive'));
137 $this->tpl->parseCurrentBlock();
138 }
139
140 foreach ($this->getSelectedColumns() as $field) {
141 switch ($field) {
142 case 'prtf':
143 $tmp = array();
144 if (array_key_exists('prtf', $a_set) && is_array($a_set['prtf'])) {
145 foreach ($a_set['prtf'] as $prtf_url => $prtf_txt) {
146 $tmp[] = '<a href="' . $prtf_url . '">' . $prtf_txt . '</a>';
147 }
148 }
149 $this->tpl->setCurrentBlock('custom_fields');
150 $this->tpl->setVariable('VAL_CUST', implode('<br />', $tmp));
151 $this->tpl->parseCurrentBlock();
152 break;
153 case 'roles':
154 $this->tpl->setCurrentBlock('custom_fields');
155 $this->tpl->setVariable('VAL_CUST', (string) $a_set['roles_label']);
156 $this->tpl->parseCurrentBlock();
157 break;
158 case 'org_units':
159 $this->tpl->setCurrentBlock('custom_fields');
160 $this->tpl->setVariable('VAL_CUST', ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits((int) $a_set['usr_id']));
161 $this->tpl->parseCurrentBlock();
162 break;
163 default:
164 $this->tpl->setCurrentBlock('custom_fields');
165 $this->tpl->setVariable('VAL_CUST', isset($a_set[$field]) ? (string) $a_set[$field] : '');
166 $this->tpl->parseCurrentBlock();
167 break;
168 }
169 }
170
171 $this->tpl->setVariable('VAL_POSTNAME', 'participants');
172
173 if (
174 $this->obj_user_tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS) &&
176
177 ) {
178 $this->tpl->setVariable('FIRST_ACCESS', $this->getFirstAccess((int) $a_set['usr_id']));
179 $this->tpl->setVariable('LAST_ACCESS', $this->getLastAccess((int) $a_set['usr_id']));
180 }
181
182 $this->tpl->setVariable('COMPLETED_STEPS', $this->getCompletedSteps((int) $a_set['usr_id']));
183 $this->tpl->setVariable('LAST_VISITED_STEP', $this->getLastVisitedStep((int) $a_set['usr_id']));
184
185 if ($this->getParticipants()->isAdmin((int) $a_set['usr_id'])) {
186 $this->tpl->setVariable('VAL_NOTIFICATION_ID', (int) $a_set['usr_id']);
187 $this->tpl->setVariable(
188 'VAL_NOTIFICATION_CHECKED',
189 $a_set['notification'] ? 'checked="checked"' : ''
190 );
191 }
192
193 $this->showActionLinks($a_set);
194 $this->tpl->setVariable('VAL_LOGIN', $a_set['login']);
195 }
196
197 protected function getFirstAccess(int $user_id): string
198 {
199 $data = $this->getRepositoryObject()->getStateDB()->getFirstAccessFor(
200 $this->getRepositoryObject()->getRefId(),
201 [$user_id]
202 );
203
204 if ($data[$user_id] === '-1') {
205 return "-";
206 }
207
208 return $data[$user_id];
209 }
210
211 protected function getLastAccess(int $user_id): string
212 {
213 $data = $this->getRepositoryObject()->getStateDB()->getLastAccessFor(
214 $this->getRepositoryObject()->getRefId(),
215 [$user_id]
216 );
217
218 if ($data[$user_id] === '-1') {
219 return "-";
220 }
221
222 return $data[$user_id];
223 }
224
225 protected function getCompletedSteps(int $user_id): string
226 {
227 $passed = 0;
228
229 $learner_items = $this->getRepositoryObject()->getLSLearnerItems(
230 $user_id
231 );
232
233 $completion_states = $this->rep_object->getLPCompletionStates();
234
235 foreach ($learner_items as $learner_item) {
236 if (in_array($learner_item->getLearningProgressStatus(), $completion_states)) {
237 $passed++;
238 }
239 }
240
241 return $passed . " / " . count($learner_items);
242 }
243
249 protected function getLastVisitedStep(int $user_id): string
250 {
251 $data = $this->getRepositoryObject()->getStateDB()->getCurrentItemsFor(
252 $this->getRepositoryObject()->getRefId(),
253 [$user_id]
254 );
255
256 if ($data[$user_id] === -1) {
257 return "-";
258 }
259
260 return $this->getTitleFor((int) $data[$user_id]);
261 }
262
263 protected function getTitleFor(int $ref_id): string
264 {
266 }
267
268 public function parse(): void
269 {
270 $this->determineOffsetAndOrder(true);
271
272 $ls_participants = $this->participants->getParticipants();
273
274 $ls_participants = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
275 'manage_members',
276 'manage_members',
277 $this->getRepositoryObject()->getRefId(),
278 $ls_participants
279 );
280
281 if (!$ls_participants) {
282 $this->setData(array());
283 return;
284 }
285
286 $lso_user_data = $this->parent_gui->readMemberData(
287 $ls_participants,
288 $this->getSelectedColumns()
289 );
290
291 $additional_fields = $this->getSelectedColumns();
292 unset($additional_fields['prtf']);
293 unset($additional_fields['roles']);
294 unset($additional_fields['org_units']);
295
296 $udf_ids = $usr_data_fields = $odf_ids = array();
297 foreach ($additional_fields as $field) {
298 if (substr($field, 0, 3) == 'udf') {
299 $udf_ids[] = substr($field, 4);
300 continue;
301 }
302
303 if (substr($field, 0, 3) == 'odf') {
304 $odf_ids[] = substr($field, 4);
305 continue;
306 }
307
308 $usr_data_fields[] = $field;
309 }
310
312 $this->getOrderField(),
313 $this->getOrderDirection(),
314 0,
315 9999,
316 $this->current_filter['login'],
317 '',
318 null,
319 false,
320 false,
321 0,
322 0,
323 null,
324 $usr_data_fields,
325 $ls_participants
326 );
327
328 $user_data = array();
329 $filtered_user_ids = array();
330 $local_roles = $this->parent_gui->getLocalRoles();
331
332 foreach ($usr_data['set'] as $ud) {
333 $user_id = $ud['usr_id'];
334
335 if ($this->current_filter['roles']) {
336 if (!$this->rbac_review->isAssigned($user_id, $this->current_filter['roles'])) {
337 continue;
338 }
339 }
340
341 if (array_key_exists('org_units', $this->current_filter)
342 && $this->current_filter['org_units'] !== ''
343 ) {
344 $org_unit = $this->current_filter['org_units'];
345 $title = ilObjectFactory::getInstanceByRefId($org_unit)->getTitle();
346 $user_units = ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits((int) $user_id);
347 if (strpos($user_units, $title) === false) {
348 continue;
349 }
350 }
351
352 $filtered_user_ids[] = $user_id;
353 $user_data[$user_id] = array_merge($ud, $lso_user_data[$user_id]);
354
355 $roles = array();
356 foreach ($local_roles as $role_id => $role_name) {
357 if ($this->rbac_review->isAssigned((int) $user_id, $role_id)) {
358 $roles[] = $role_name;
359 }
360 }
361
362 $user_data[$user_id]['name'] = $user_data[$user_id]['lastname'] . ', ' . $user_data[$user_id]['firstname'];
363 $user_data[$user_id]['roles_label'] = implode('<br />', $roles);
364 $user_data[$user_id]['roles'] = $this->participants->setRoleOrderPosition((int) $user_id);
365 }
366
367 // Custom user data fields
368 if ($udf_ids !== []) {
369 $user_data = array_reduce(
370 $this->profile->getDataForMultiple($filtered_user_ids),
371 function (array $c, ProfileData $v) use ($udf_ids): array {
372 if (!$this->checkAcceptance($v->getId())) {
373 return $c;
374 }
375
376 foreach ($udf_ids as $field_id) {
377 $c[$v->getId()]['udf_' . $field_id] = $v->getAdditionalFieldByIdentifier($field_id);
378 }
379 },
380 $user_data
381 );
382 }
383
384 $user_data = ilArrayUtil::sortArray(
385 $user_data,
386 'name',
387 $this->getOrderDirection()
388 );
389
390 $this->setData($user_data);
391 }
392
393 public function getSelectableColumns(): array
394 {
395 $ef = $this->getExportFieldsInfo();
396 $columns = $ef->getSelectableFieldsInfo(
397 $this->getRepositoryObject()->getId()
398 );
399
400 if ($this->settings->get('user_portfolios')) {
401 $columns['prtf'] = array(
402 'txt' => $this->lng->txt('obj_prtf'),
403 'default' => false
404 );
405 }
406
407 return array_merge(
408 [
409 'roles' => [
410 'txt' => $this->lng->txt('objs_role'),
411 'default' => true
412 ]
413 ],
414 [
415 'org_units' => [
416 'txt' => $this->lng->txt("org_units"),
417 'default' => false
418 ]
419 ],
420 $columns
421 );
422 }
423
425 {
427 $this->getRepositoryObject()->getType()
428 );
429 }
430}
Class ilAccessHandler Checks access for ILIAS objects.
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static _getInstanceByType(string $a_type)
Get Singleton Instance.
language handling
GUI class for learning sequence membership features.
__construct(ilLearningSequenceMembershipGUI $parent_gui, ilObjLearningSequence $ls_object, ilObjUserTracking $obj_user_tracking, ilPrivacySettings $privacy_settings, ilLanguage $lng, ilAccess $access, ilRbacReview $rbac_review, ilSetting $settings, Profile $profile)
getLastVisitedStep(int $user_id)
Different to the concept we decide to use the title of the object instead of its actually number in t...
static _lookupActive(int $a_usr_id)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
Singleton class that stores all privacy settings.
class ilRbacReview Contains Review functions of core Rbac.
ILIAS Setting Class.
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
determineOffsetAndOrder(bool $a_omit_offset=false)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setFormName(string $a_name="")
addMultiCommand(string $a_cmd, string $a_text)
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...
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)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
ilLanguage $lng
enable(string $a_module_name)
static getUserListData(string $a_order_field, string $a_order_dir, int $a_offset, int $a_limit, string $a_string_filter="", string $a_activation_filter="", ?ilDateTime $a_last_login_filter=null, bool $a_limited_access_filter=false, bool $a_no_courses_filter=false, int $a_course_group_filter=0, int $a_role_filter=0, ?array $a_user_folder_filter=null, ?array $a_additional_fields=null, ?array $a_user_filter=null, string $a_first_letter="", string $a_authentication_filter="")
Get data for user administration list.
$c
Definition: deliver.php:25
$info
Definition: entry_point.php:21
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc