ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWaitingListTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\UI\Factory as UIFactory;
22use ILIAS\UI\Renderer as UIRenderer;
24use ILIAS\User\Profile\Data as ProfileData;
25
32{
33 protected static ?array $all_columns = null;
34 protected static bool $has_odf_definitions;
35 protected array $wait = [];
36 protected array $wait_user_ids = [];
38 protected ilObjUser $user;
40
41 private UIRenderer $renderer;
42 private UIFactory $uiFactory;
44
45 public function __construct(
46 object $a_parent_obj,
49 ) {
50 global $DIC;
51 $this->renderer = $DIC->ui()->renderer();
52 $this->uiFactory = $DIC->ui()->factory();
53
54 $this->rep_object = $rep_object;
55 $this->profile = $DIC['user']->getProfile();
56 $this->user = $DIC['user']->getLoggedInUser();
57
58 $this->setId('crs_wait_' . $this->getRepositoryObject()->getId());
59 parent::__construct($a_parent_obj, 'participants');
60 $this->setFormName('waiting');
61 $this->setPrefix('waiting');
62
63 $this->lng->loadLanguageModule('grp');
64 $this->lng->loadLanguageModule('crs');
65 $this->lng->loadLanguageModule('sess');
66 $this->lng->loadLanguageModule('ps');
67
68 $this->setExternalSorting(false);
69 $this->setExternalSegmentation(true);
70
71 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, 'participants'));
72
73 $this->addColumn('', 'f', "1", true);
74 $this->addColumn($this->lng->txt('name'), 'lastname', '20%');
75
76 $all_cols = $this->getSelectableColumns();
77 foreach ($this->getSelectedColumns() as $col) {
78 $this->addColumn($all_cols[$col]['txt'], $col);
79 }
80
81 $this->addColumn($this->lng->txt('application_date'), 'sub_time', "10%");
82 $this->addColumn('', 'mail', '10%');
83
84 $this->addMultiCommand('confirmAssignFromWaitingList', $this->lng->txt('assign'));
85 $this->addMultiCommand('confirmRefuseFromList', $this->lng->txt('refuse'));
86 $this->addMultiCommand('sendMailToSelectedUsers', $this->lng->txt('crs_mem_send_mail'));
87
88 $this->setDefaultOrderField('sub_time');
89
90 // begin-patch clipboard
91 $this->lng->loadLanguageModule('user');
92 $this->addMultiCommand('addToClipboard', $this->lng->txt('clipboard_add_btn'));
93 // end-patch clipboard
94
95 $this->setPrefix('waiting');
96 $this->setSelectAllCheckbox('waiting', true);
97
98 $this->setRowTemplate("tpl.show_waiting_list_row.html", "components/ILIAS/Membership");
99
100 $this->enable('sort');
101 $this->enable('header');
102 $this->enable('numinfo');
103 $this->enable('select_all');
104
105 $this->waiting_list = $waiting_list;
106
107 self::$has_odf_definitions = (bool) ilCourseDefinedFieldDefinition::_hasFields($this->getRepositoryObject()->getId());
108 }
109
110 protected function getWaitingList(): ilWaitingList
111 {
112 return $this->waiting_list;
113 }
114
115 protected function getRepositoryObject(): ilObject
116 {
117 return $this->rep_object;
118 }
119
124 public function setUserIds(array $a_user_ids): void
125 {
126 $this->wait_user_ids = $this->wait = [];
127 foreach ($a_user_ids as $usr_id) {
128 $this->wait_user_ids[] = $usr_id;
129 $this->wait[$usr_id] = $this->getWaitingList()->getUser($usr_id);
130 }
131 }
132
133 public function numericOrdering(string $a_field): bool
134 {
135 switch ($a_field) {
136 case 'sub_time':
137 return true;
138 }
139 return parent::numericOrdering($a_field);
140 }
141
142 public function getSelectableColumns(): array
143 {
144 if (self::$all_columns) {
145 return self::$all_columns;
146 }
147
149 self::$all_columns = $ef->getSelectableFieldsInfo($this->getRepositoryObject()->getId());
150
151 // #25215
152 if (
153 is_array(self::$all_columns) &&
154 array_key_exists('consultation_hour', self::$all_columns)
155 ) {
156 unset(self::$all_columns['consultation_hour']);
157 }
158
159 if (
160 !is_array(self::$all_columns) ||
161 !array_key_exists('login', self::$all_columns)
162 ) {
163 self::$all_columns['login'] = [
164 'default' => 1,
165 'txt' => $this->lng->txt('login')
166 ];
167 }
168 return self::$all_columns;
169 }
170
171 protected function fillRow(array $a_set): void
172 {
173 if (
174 !ilObjCourseGrouping::_checkGroupingDependencies($this->getRepositoryObject(), (int) $a_set['usr_id']) &&
176 ) {
177 $prefix = $this->getRepositoryObject()->getType();
178 $this->tpl->setVariable(
179 'ALERT_MSG',
180 sprintf(
181 $this->lng->txt($prefix . '_lim_assigned'),
182 ilObject::_lookupTitle(current($ids))
183 )
184 );
185 }
186
187 $this->tpl->setVariable('VAL_ID', $a_set['usr_id']);
188 $this->tpl->setVariable('VAL_NAME', $a_set['lastname'] . ', ' . $a_set['firstname']);
189
190 foreach ($this->getSelectedColumns() as $field) {
191 switch ($field) {
192 case 'gender':
193 $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
194 $this->tpl->setCurrentBlock('custom_fields');
195 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
196 $this->tpl->parseCurrentBlock();
197 break;
198
199 case 'birthday':
200 $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate(
201 $a_set['birthday'],
203 )) : $this->lng->txt('no_date');
204 $this->tpl->setCurrentBlock('custom_fields');
205 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
206 $this->tpl->parseCurrentBlock();
207 break;
208
209 case 'odf_last_update':
210 $this->tpl->setVariable('VAL_CUST', (string) ($a_set['odf_info_txt'] ?? ''));
211 break;
212
213 case 'org_units':
214 $this->tpl->setCurrentBlock('custom_fields');
215 $this->tpl->setVariable(
216 'VAL_CUST',
217 ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits((int) $a_set['usr_id'])
218 );
219 $this->tpl->parseCurrentBlock();
220 break;
221
222 default:
223 $this->tpl->setCurrentBlock('custom_fields');
224 $this->tpl->setVariable('VAL_CUST', isset($a_set[$field]) ? (string) $a_set[$field] : '');
225 $this->tpl->parseCurrentBlock();
226 break;
227 }
228 }
229 $this->tpl->setVariable(
230 'VAL_SUBTIME',
232 );
233 $this->showActionLinks($a_set);
234 }
235
236 public function readUserData(): void
237 {
239
240 $additional_fields = $this->getSelectedColumns();
241 unset(
242 $additional_fields["firstname"],
243 $additional_fields["lastname"],
244 $additional_fields["last_login"],
245 $additional_fields["access_until"],
246 $additional_fields['org_units']
247 );
248
249 $udf_ids = $usr_data_fields = $odf_ids = array();
250 foreach ($additional_fields as $field) {
251 if (strpos($field, 'udf') === 0) {
252 $udf_ids[] = substr($field, 4);
253 continue;
254 }
255 if (strpos($field, 'odf') === 0) {
256 $odf_ids[] = substr($field, 4);
257 continue;
258 }
259
260 $usr_data_fields[] = $field;
261 }
262
264 $this->getOrderField(),
265 $this->getOrderDirection(),
266 $this->getOffset(),
267 $this->getLimit(),
268 '',
269 '',
270 null,
271 false,
272 false,
273 0,
274 0,
275 null,
276 $usr_data_fields,
277 $this->wait_user_ids
278 );
279 if (0 === count($usr_data['set']) && $this->getOffset() > 0 && $this->getExternalSegmentation()) {
280 $this->resetOffset();
281
283 $this->getOrderField(),
284 $this->getOrderDirection(),
285 $this->getOffset(),
286 $this->getLimit(),
287 '',
288 '',
289 null,
290 false,
291 false,
292 0,
293 0,
294 null,
295 $usr_data_fields,
296 $this->wait_user_ids
297 );
298 }
299 $usr_ids = [];
300 foreach ((array) $usr_data['set'] as $user) {
301 $usr_ids[] = (int) $user['usr_id'];
302 }
303
304 // merge course data
305 $course_user_data = $this->getParentObject()->readMemberData($usr_ids, array());
306 $a_user_data = array();
307 foreach ((array) $usr_data['set'] as $ud) {
308 $a_user_data[(int) $ud['usr_id']] = array_merge($ud, $course_user_data[(int) $ud['usr_id']]);
309 }
310
311 // Custom user data fields
312 if ($udf_ids) {
313 $a_user_data = array_reduce(
314 $this->profile->getDataForMultiple($usr_ids),
315 function (array $c, ProfileData $v) use ($udf_ids): array {
316 if (!$this->checkAcceptance($v->getId())) {
317 return $c;
318 }
319
320 foreach ($udf_ids as $field_id) {
321 $c[$v->getId()]['udf_' . $field_id] = $v->getAdditionalFieldByIdentifier($field_id);
322 }
323 },
324 $a_user_data
325 );
326 }
327 // Object specific user data fields
328 if ($odf_ids) {
330 foreach ($data as $usr_id => $fields) {
331 // #7264: as we get data for all course members filter against user data
332 if (!$this->checkAcceptance($usr_id) || !in_array($usr_id, $usr_ids)) {
333 continue;
334 }
335
336 foreach ($fields as $field_id => $value) {
337 $a_user_data[$usr_id]['odf_' . $field_id] = $value;
338 }
339 }
340
341 // add last edit date
342 foreach (ilObjectCustomUserFieldHistory::lookupEntriesByObjectId($this->getRepositoryObject()->getId()) as $usr_id => $edit_info) {
343 if (!isset($a_user_data[$usr_id])) {
344 continue;
345 }
346
347 if ($usr_id == $edit_info['update_user']) {
348 $a_user_data[$usr_id]['odf_last_update'] = '';
349 $a_user_data[$usr_id]['odf_info_txt'] = $GLOBALS['DIC']['lng']->txt('cdf_edited_by_self');
350 if (ilPrivacySettings::getInstance()->enabledAccessTimesByType($this->getRepositoryObject()->getType())) {
351 $a_user_data[$usr_id]['odf_last_update'] .= ('_' . $edit_info['editing_time']->get(IL_CAL_UNIX));
352 $a_user_data[$usr_id]['odf_info_txt'] .= (', ' . ilDatePresentation::formatDate($edit_info['editing_time']));
353 }
354 } else {
355 $a_user_data[$usr_id]['odf_last_update'] = $edit_info['update_user'];
356 $a_user_data[$usr_id]['odf_last_update'] .= ('_' . $edit_info['editing_time']->get(IL_CAL_UNIX));
357
358 $name = ilObjUser::_lookupName($edit_info['update_user']);
359 $a_user_data[$usr_id]['odf_info_txt'] = ($name['firstname'] . ' ' . $name['lastname'] . ', ' . ilDatePresentation::formatDate($edit_info['editing_time']));
360 }
361 }
362 }
363
364 foreach ($usr_data['set'] as $user) {
365 // Check acceptance
366 if (!$this->checkAcceptance((int) $user['usr_id'])) {
367 continue;
368 }
369 // DONE: accepted
370 foreach ($usr_data_fields as $field) {
371 $a_user_data[(int) $user['usr_id']][$field] = $user[$field] ?: '';
372 }
373 }
374
375 // Waiting list subscription
376 foreach ($this->wait as $usr_id => $wait_usr_data) {
377 if (isset($a_user_data[$usr_id])) {
378 $a_user_data[$usr_id]['sub_time'] = $wait_usr_data['time'];
379 }
380 }
381
382 $this->setMaxCount((int) ($usr_data['cnt'] ?? 0));
383 $this->setData($a_user_data);
384 }
385
386 public function showActionLinks(array $a_set): void
387 {
388 // tpl variables MAIL_LINK and MAIL_TITLE are unused but not removed
389 // from the template.
390 $this->ctrl->setParameterByClass(get_class($this->getParentObject()), 'member_id', $a_set['usr_id']);
391
392 $dropDownItems = array();
393 $dropDownItems[] = $this->uiFactory->button()->shy(
394 $this->lng->txt($this->getRepositoryObject()->getType() . '_mem_send_mail'),
395 $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'sendMailToSelectedUsers')
396 );
397
398 if (self::$has_odf_definitions) {
399 $dropDownItems[] = $this->uiFactory->button()->shy(
400 $this->lng->txt($this->getRepositoryObject()->getType() . '_cdf_edit_member'),
401 $this->ctrl->getLinkTargetByClass('ilobjectcustomuserfieldsgui', 'editMember')
402 );
403 }
404
405 $dropDown = $this->uiFactory->dropdown()->standard($dropDownItems)
406 ->withLabel($this->lng->txt('actions'));
407
408 $this->tpl->setVariable('ACTION_USER', $this->renderer->render($dropDown));
409 $this->ctrl->setParameterByClass(get_class($this->getParentObject()), 'member_id', null);
410 }
411
412 protected function checkAcceptance(int $a_usr_id): bool
413 {
414 return true;
415 }
416}
renderer()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
const IL_CAL_DATE
const IL_CAL_UNIX
static _hasFields(int $a_container_id)
Check if there are any define fields.
static _getValuesByObjId(int $a_obj_id)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
Class for single dates.
static _getInstanceByType(string $a_type)
Get Singleton Instance.
static _checkGroupingDependencies(ilObject $container_obj, ?int $a_user_id=null)
User class.
static _lookupName(int $a_user_id)
Class ilObject Basic functions for all objects.
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
determineOffsetAndOrder(bool $a_omit_offset=false)
setExternalSegmentation(bool $a_val)
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...
setFormAction(string $a_form_action, bool $a_multipart=false)
resetOffset(bool $a_in_determination=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)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
enable(string $a_module_name)
setMaxCount(int $a_max_count)
set max.
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.
GUI class for course/group waiting list.
numericOrdering(string $a_field)
Should this field be sorted numeric?
setUserIds(array $a_user_ids)
Set user ids.
__construct(object $a_parent_obj, ilObject $rep_object, ilWaitingList $waiting_list)
fillRow(array $a_set)
Standard Version of Fill Row.
getSelectableColumns()
Get selectable columns.
Base class for course and group waiting lists.
$c
Definition: deliver.php:25
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54