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