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