ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilSessionParticipantsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
26 {
27  protected static array $all_columns = [];
28 
29  private ilLogger $logger;
30  private ilTree $tree;
31  private \ILIAS\DI\RBACServices $rbac;
34  private int $parent_ref_id = 0;
35  private int $member_ref_id = 0;
36  private array $current_filter = [];
37 
38  public function __construct(object $a_parent_gui, ilObjSession $a_parent_obj, string $a_parent_cmd)
39  {
40  global $DIC;
41 
42  $this->logger = $DIC->logger()->sess();
43  $this->tree = $DIC->repositoryTree();
44  $this->rbac = $DIC->rbac();
45 
46  $this->rep_object = $a_parent_obj;
47 
48  $this->participants = ilParticipants::getInstance($this->getRepositoryObject()->getRefId());
49 
50  $this->setId('session_part_' . $this->getRepositoryObject()->getId());
51  parent::__construct($a_parent_gui, $a_parent_cmd);
52 
53  $this->parent_ref_id = $this->tree->getParentId(
54  $this->getRepositoryObject()->getRefId()
55  );
56 
57  /*
58  * TODO this exact logic is also in ilSessionMembershipGUI and ilMembershipGUI,
59  * should be centralized.
60  */
61  if ($member_ref = $this->tree->checkForParentType($this->parent_ref_id, 'grp')) {
62  $this->member_ref_id = $member_ref;
63  } elseif ($member_ref = $this->tree->checkForParentType($this->parent_ref_id, 'crs')) {
64  $this->member_ref_id = $member_ref;
65  } else {
66  throw new \InvalidArgumentException("Error in tree structure. Session has no parent course/group ref_id: " . $this->getRepositoryObject()->getRefId());
67  }
68  }
69 
70  protected function getRepositoryObject(): ilObjSession
71  {
72  return $this->rep_object;
73  }
74 
75  protected function isRegistrationEnabled(): bool
76  {
77  return $this->getRepositoryObject()->enabledRegistration();
78  }
79 
80  protected function getParticipants(): ilParticipants
81  {
82  return $this->participants;
83  }
84 
85  public function init(): void
86  {
87  $this->lng->loadLanguageModule('sess');
88  $this->lng->loadLanguageModule('crs');
89  $this->lng->loadLanguageModule('trac');
90  $this->lng->loadLanguageModule('mmbr');
91 
92  $this->setFormName('participants');
93 
94  $this->initFilter();
95 
96 
97  $this->setSelectAllCheckbox('participants', true);
98  $this->setShowRowsSelector(true);
99 
100  $this->enable('sort');
101  $this->enable('header');
102  $this->enable('numinfo');
103  $this->enable('select_all');
104 
105 
106  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $this->getParentCmd()));
107 
108  $this->setRowTemplate("tpl.sess_members_row.html", "Modules/Session");
109 
110  $this->addColumn('', 'f', '1', true);
111  $this->addColumn($this->lng->txt('name'), 'name', '20%');
112  $this->addColumn($this->lng->txt('login'), 'login', '10%');
113 
114  $all_cols = $this->getSelectableColumns();
115  foreach ($this->getSelectedColumns() as $col) {
116  $this->addColumn($all_cols[$col]['txt'], $col);
117  }
118 
119 
120  if ($this->isRegistrationEnabled()) {
121  $this->addColumn($this->lng->txt('event_tbl_registered'), 'registered');
122  $this->setDefaultOrderField('registered');
123  $this->setDefaultOrderDirection('desc');
124  } else {
125  $this->setDefaultOrderField('name');
126  }
127 
128  $this->addColumn($this->lng->txt('event_tbl_participated'), 'participated');
129 
130  if ($this->isRegistrationEnabled()) {
131  $this->addColumn($this->lng->txt('sess_part_table_excused'), 'excused');
132  }
133 
134  $this->addColumn($this->lng->txt('sess_contact'), 'contact');
135  if (true === $this->getRepositoryObject()->isRegistrationNotificationEnabled()) {
136  $this->addColumn($this->lng->txt('notification'), 'notification_checked');
137  }
138 
139  $this->addColumn($this->lng->txt('trac_mark'), 'mark');
140  $this->addColumn($this->lng->txt('trac_comment'), 'comment');
141 
142 
143  $this->addMultiCommand('sendMailToSelectedUsers', $this->lng->txt('mmbr_btn_mail_selected_users'));
144  $this->lng->loadLanguageModule('user');
145  $this->addMultiCommand('addToClipboard', $this->lng->txt('clipboard_add_btn'));
146 
147 
148  $this->addCommandButton('updateMembers', $this->lng->txt('save'));
149  }
150 
151  public function initFilter(): void
152  {
153  $login = $this->addFilterItemByMetaType(
154  'login',
156  false,
157  $this->lng->txt('name')
158  );
159  $this->current_filter['login'] = $login->getValue();
160 
161 
162  if ($this->isColumnSelected('roles')) {
163  $role = $this->addFilterItemByMetaType(
164  'roles',
166  false,
167  $this->lng->txt('objs_' . ilObject::_lookupType(ilObject::_lookupObjId($this->member_ref_id)) . '_role')
168  );
169 
170  $options = [];
171  $options[0] = $this->lng->txt('all_roles');
172  $role->setOptions($options + $this->getParentLocalRoles());
173  $this->current_filter['roles'] = $role->getValue();
174  }
175 
176  if ($this->getRepositoryObject()->enabledRegistration()) {
177  $reg = $this->addFilterItemByMetaType(
178  'filter_registration',
180  false,
181  $this->lng->txt('sess_part_filter_registered')
182  );
183  $this->current_filter['filter_registration'] = $reg->getChecked();
184  }
185  $participated = $this->addFilterItemByMetaType(
186  'filter_participated',
188  false,
189  $this->lng->txt('sess_part_filter_participated')
190  );
191  $this->current_filter['filter_participated'] = $participated->getChecked();
192  }
193 
194  public function getSelectableColumns(): array
195  {
196  self::$all_columns['roles'] = array(
197  'txt' => $this->lng->txt('objs_role'),
198  'default' => true
199  );
200 
201  return self::$all_columns;
202  }
203 
204  public function parse(): void
205  {
206  $all_participants = [];
207  $all_possible_participants = $this->collectParticipants();
208  if ($all_possible_participants !== []) {
209  // user filter
210  $user_query = new ilUserQuery();
211  $user_query->setLimit(50000);
212  $user_query->setUserFilter($all_possible_participants);
213  $user_query->setTextFilter((string) $this->current_filter['login']);
214  $res = $user_query->query();
215  $all_participants = $res['set'];
216  }
217 
218  $part = [];
219  foreach ($all_participants as $counter => $participant) {
220  $usr_data = $this->getParticipants()->getEventParticipants()->getUser((int) $participant['usr_id']);
221  $tmp_data = [];
222  $tmp_data['id'] = $participant['usr_id'];
223 
224  $tmp_data['name'] = $participant['lastname'];
225  $tmp_data['lastname'] = $participant['lastname'];
226  $tmp_data['firstname'] = $participant['firstname'];
227  $tmp_data['login'] = $participant['login'];
228  $tmp_data['mark'] = $usr_data['mark'] ?? null;
229  $tmp_data['comment'] = $usr_data['comment'] ?? null;
230  $tmp_data['participated'] = $this->getParticipants()->getEventParticipants()->hasParticipated((int) $participant['usr_id']);
231  $tmp_data['registered'] = $this->getParticipants()->getEventParticipants()->isRegistered((int) $participant['usr_id']);
232  $tmp_data['excused'] = $this->getParticipants()->getEventParticipants()->isExcused((int) $participant['usr_id']);
233  $tmp_data['contact'] = $this->getParticipants()->isContact((int) $participant['usr_id']);
234 
235  $notificationShown = false;
236  if (true === $this->getRepositoryObject()->isRegistrationNotificationEnabled()) {
237  $notificationShown = true;
238  $notificationCheckboxEnabled = true;
239  if (ilSessionConstants::NOTIFICATION_INHERIT_OPTION === $this->getRepositoryObject()->getRegistrationNotificationOption()) {
240  $notificationCheckboxEnabled = false;
241  }
242  $tmp_data['notification_checkbox_enabled'] = $notificationCheckboxEnabled;
243  $tmp_data['notification_checked'] = $usr_data['notification_enabled'] ?? false;
244  }
245  $tmp_data['show_notification'] = $notificationShown;
246 
247  $roles = [];
248  $local_roles = $this->getParentLocalRoles();
249  foreach ($local_roles as $role_id => $role_name) {
250  // @todo fix performance
251  if ($this->rbac->review()->isAssigned((int) $participant['usr_id'], $role_id)) {
252  $tmp_data['role_ids'][] = $role_id;
253  $roles[] = $role_name;
254  }
255  }
256  $tmp_data['roles'] = implode('<br />', $roles);
257 
258  if ($this->matchesFilterCriteria($tmp_data)) {
259  $part[] = $tmp_data;
260  }
261  }
262  $this->setData($part);
263  }
264 
268  protected function collectParticipants(): array
269  {
270  $direct_participants = $this->getParticipants()
271  ->getEventParticipants()
272  ->getParticipants();
273  $direct_participants = array_keys($direct_participants);
274 
275  $part = ilParticipants::getInstance($this->member_ref_id);
276  if (!$part instanceof ilParticipants) {
277  return $direct_participants;
278  }
279 
280  return array_unique(array_merge(
281  $direct_participants,
282  $part->getParticipants()
283  ));
284  }
285 
286  protected function matchesFilterCriteria(array $a_user_info): bool
287  {
288  foreach ($this->current_filter as $filter => $filter_value) {
289  if (!$filter_value) {
290  continue;
291  }
292  switch ($filter) {
293  case 'roles':
294  if (!in_array($filter_value, ($a_user_info['role_ids'] ?? []))) {
295  return false;
296  }
297  break;
298 
299  case 'filter_participated':
300  if (!($a_user_info['participated'] ?? false)) {
301  return false;
302  }
303  break;
304 
305  case 'filter_registration':
306  if (!($a_user_info['registered'] ?? false)) {
307  return false;
308  }
309  break;
310  }
311  }
312  return true;
313  }
314 
315  protected function fillRow(array $a_set): void
316  {
317  $this->tpl->setVariable('VAL_POSTNAME', 'participants');
318 
319  if ($this->isRegistrationEnabled()) {
320  $this->tpl->setCurrentBlock('registered_col');
321  $this->tpl->setVariable('VAL_ID', $a_set['id']);
322  $this->tpl->setVariable('REG_CHECKED', $a_set['registered'] ? 'checked="checked"' : '');
323  $this->tpl->parseCurrentBlock();
324  }
325 
326  foreach ($this->getSelectedColumns() as $field) {
327  if ($field == 'roles') {
328  $this->tpl->setCurrentBlock('custom_fields');
329  $this->tpl->setVariable('VAL_CUST', (string) $a_set['roles']);
330  $this->tpl->parseCurrentBlock();
331  }
332  }
333 
334  if (true === $a_set['show_notification']) {
335  $this->tpl->setCurrentBlock('notification_column');
336  $this->tpl->setVariable('VAL_ID', $a_set['id']);
337  $this->tpl->setVariable('NOTIFICATION_CHECKED', $a_set['notification_checked'] ? 'checked="checked"' : '');
338 
339  $enableCheckbox = $a_set['notification_checkbox_enabled'];
340 
341  $this->tpl->setVariable('NOTIFICATION_ENABLED', $enableCheckbox ? '' : 'disabled');
342  $this->tpl->parseCurrentBlock();
343  }
344 
345  $this->tpl->setVariable('VAL_ID', $a_set['id']);
346  $this->tpl->setVariable('LASTNAME', $a_set['lastname']);
347  $this->tpl->setVariable('FIRSTNAME', $a_set['firstname']);
348  $this->tpl->setVariable('LOGIN', $a_set['login']);
349  $this->tpl->setVariable('MARK', $a_set['mark']);
350  $this->tpl->setVariable('COMMENT', $a_set['comment']);
351  $this->tpl->setVariable('PART_CHECKED', $a_set['participated'] ? 'checked="checked"' : '');
352  $this->tpl->setVariable('CONTACT_CHECKED', $a_set['contact'] ? 'checked="checked"' : '');
353  $this->tpl->setVariable('PART_CHECKED', $a_set['participated'] ? 'checked="checked"' : '');
354  if ($this->isRegistrationEnabled()) {
355  $this->tpl->setVariable('EXCUSED_CHECKED', $a_set['excused'] ? 'checked="checked"' : '');
356  }
357  }
358 
359  protected function getParentLocalRoles(): array
360  {
361  $part = null;
362  $type = ilObject::_lookupType($this->member_ref_id, true);
363  switch ($type) {
364  case 'crs':
365  case 'grp':
366  $part = ilParticipants::getInstance($this->member_ref_id);
367  // no break
368  default:
369  }
370  if (!$part instanceof ilParticipants) {
371  return [];
372  }
373 
374  $review = $this->rbac->review();
375  $local_parent_roles = $review->getLocalRoles($this->member_ref_id);
376  $local_roles_info = [];
377  foreach ($local_parent_roles as $index => $role_id) {
378  $local_roles_info[$role_id] = ilObjRole::_getTranslation(
379  ilObject::_lookupTitle($role_id)
380  );
381  }
382  return $local_roles_info;
383  }
384 }
setData(array $a_data)
$res
Definition: ltiservices.php:69
enable(string $a_module_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFormAction(string $a_form_action, bool $a_multipart=false)
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)
static getInstance(int $a_ref_id)
setFormName(string $a_name="")
setId(string $a_val)
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
isColumnSelected(string $col)
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
__construct(VocabulariesInterface $vocabularies)
static _lookupTitle(int $obj_id)
setDefaultOrderField(string $a_defaultorderfield)
static _getTranslation(string $a_role_title)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
__construct(object $a_parent_gui, ilObjSession $a_parent_obj, string $a_parent_cmd)
Base class for course and group participants.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 _lookupType(int $id, bool $reference=false)
addMultiCommand(string $a_cmd, string $a_text)