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