ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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
62 $this->lng->loadLanguageModule('grp');
63 $this->lng->loadLanguageModule('crs');
64 $this->lng->loadLanguageModule('sess');
65 $this->lng->loadLanguageModule('ps');
66
67 $this->setExternalSorting(false);
68 $this->setExternalSegmentation(true);
69
70 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, 'participants'));
71
72 $this->addColumn('', 'f', "1", true);
73 $this->addColumn($this->lng->txt('name'), 'lastname', '20%');
74
75 $all_cols = $this->getSelectableColumns();
76 foreach ($this->getSelectedColumns() as $col) {
77 $this->addColumn($all_cols[$col]['txt'], $col);
78 }
79
80 $this->addColumn($this->lng->txt('application_date'), 'sub_time', "10%");
81 $this->addColumn('', 'mail', '10%');
82
83 $this->addMultiCommand('confirmAssignFromWaitingList', $this->lng->txt('assign'));
84 $this->addMultiCommand('confirmRefuseFromList', $this->lng->txt('refuse'));
85 $this->addMultiCommand('sendMailToSelectedUsers', $this->lng->txt('crs_mem_send_mail'));
86
87 $this->setDefaultOrderField('sub_time');
88
89 // begin-patch clipboard
90 $this->lng->loadLanguageModule('user');
91 $this->addMultiCommand('addToClipboard', $this->lng->txt('clipboard_add_btn'));
92 // end-patch clipboard
93
94 $this->setSelectAllCheckbox('waiting', true);
95
96 $this->setRowTemplate("tpl.show_waiting_list_row.html", "components/ILIAS/Membership");
97
98 $this->enable('sort');
99 $this->enable('header');
100 $this->enable('numinfo');
101 $this->enable('select_all');
102
103 $this->waiting_list = $waiting_list;
104
105 self::$has_odf_definitions = (bool) ilCourseDefinedFieldDefinition::_hasFields($this->getRepositoryObject()->getId());
106 }
107
108 protected function getWaitingList(): ilWaitingList
109 {
110 return $this->waiting_list;
111 }
112
113 protected function getRepositoryObject(): ilObject
114 {
115 return $this->rep_object;
116 }
117
122 public function setUserIds(array $a_user_ids): void
123 {
124 $this->wait_user_ids = $this->wait = [];
125 foreach ($a_user_ids as $usr_id) {
126 $this->wait_user_ids[] = $usr_id;
127 $this->wait[$usr_id] = $this->getWaitingList()->getUser($usr_id);
128 }
129 }
130
131 public function numericOrdering(string $a_field): bool
132 {
133 switch ($a_field) {
134 case 'sub_time':
135 return true;
136 }
137 return parent::numericOrdering($a_field);
138 }
139
140 public function getSelectableColumns(): array
141 {
142 if (self::$all_columns) {
143 return self::$all_columns;
144 }
145
147 self::$all_columns = $ef->getSelectableFieldsInfo($this->getRepositoryObject()->getId());
148
149 // #25215
150 if (
151 is_array(self::$all_columns) &&
152 array_key_exists('consultation_hour', self::$all_columns)
153 ) {
154 unset(self::$all_columns['consultation_hour']);
155 }
156
157 if (
158 !is_array(self::$all_columns) ||
159 !array_key_exists('login', self::$all_columns)
160 ) {
161 self::$all_columns['login'] = [
162 'default' => 1,
163 'txt' => $this->lng->txt('login')
164 ];
165 }
166 return self::$all_columns;
167 }
168
169 protected function fillRow(array $a_set): void
170 {
171 if (
172 !ilObjCourseGrouping::_checkGroupingDependencies($this->getRepositoryObject(), (int) $a_set['usr_id']) &&
174 ) {
175 $prefix = $this->getRepositoryObject()->getType();
176 $this->tpl->setVariable(
177 'ALERT_MSG',
178 sprintf(
179 $this->lng->txt($prefix . '_lim_assigned'),
180 ilObject::_lookupTitle(current($ids))
181 )
182 );
183 }
184
185 $this->tpl->setVariable('VAL_ID', $a_set['usr_id']);
186 $this->tpl->setVariable('VAL_NAME', $a_set['lastname'] . ', ' . $a_set['firstname']);
187
188 foreach ($this->getSelectedColumns() as $field) {
189 switch ($field) {
190 case 'gender':
191 $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
192 $this->tpl->setCurrentBlock('custom_fields');
193 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
194 $this->tpl->parseCurrentBlock();
195 break;
196
197 case 'birthday':
198 $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate(
199 $a_set['birthday'],
201 )) : $this->lng->txt('no_date');
202 $this->tpl->setCurrentBlock('custom_fields');
203 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
204 $this->tpl->parseCurrentBlock();
205 break;
206
207 case 'odf_last_update':
208 $this->tpl->setVariable('VAL_CUST', (string) ($a_set['odf_info_txt'] ?? ''));
209 break;
210
211 case 'org_units':
212 $this->tpl->setCurrentBlock('custom_fields');
213 $this->tpl->setVariable(
214 'VAL_CUST',
215 ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits((int) $a_set['usr_id'])
216 );
217 $this->tpl->parseCurrentBlock();
218 break;
219
220 default:
221 $this->tpl->setCurrentBlock('custom_fields');
222 $this->tpl->setVariable('VAL_CUST', isset($a_set[$field]) ? (string) $a_set[$field] : '');
223 $this->tpl->parseCurrentBlock();
224 break;
225 }
226 }
227 $this->tpl->setVariable(
228 'VAL_SUBTIME',
230 );
231 $this->showActionLinks($a_set);
232 }
233
234 public function readUserData(): void
235 {
237
238 $additional_fields = $this->getSelectedColumns();
239 unset(
240 $additional_fields["firstname"],
241 $additional_fields["lastname"],
242 $additional_fields["last_login"],
243 $additional_fields["access_until"],
244 $additional_fields['org_units']
245 );
246
247 $udf_ids = $usr_data_fields = $odf_ids = array();
248 foreach ($additional_fields as $field) {
249 if (strpos($field, 'udf') === 0) {
250 $udf_ids[] = substr($field, 4);
251 continue;
252 }
253 if (strpos($field, 'odf') === 0) {
254 $odf_ids[] = substr($field, 4);
255 continue;
256 }
257
258 $usr_data_fields[] = $field;
259 }
260
262 $this->getOrderField(),
263 $this->getOrderDirection(),
264 $this->getOffset(),
265 $this->getLimit(),
266 '',
267 '',
268 null,
269 false,
270 false,
271 0,
272 0,
273 null,
274 $usr_data_fields,
275 $this->wait_user_ids
276 );
277 if (0 === count($usr_data['set']) && $this->getOffset() > 0 && $this->getExternalSegmentation()) {
278 $this->resetOffset();
279
281 $this->getOrderField(),
282 $this->getOrderDirection(),
283 $this->getOffset(),
284 $this->getLimit(),
285 '',
286 '',
287 null,
288 false,
289 false,
290 0,
291 0,
292 null,
293 $usr_data_fields,
294 $this->wait_user_ids
295 );
296 }
297 $usr_ids = [];
298 foreach ((array) $usr_data['set'] as $user) {
299 $usr_ids[] = (int) $user['usr_id'];
300 }
301
302 // merge course data
303 $course_user_data = $this->getParentObject()->readMemberData($usr_ids, array());
304 $a_user_data = array();
305 foreach ((array) $usr_data['set'] as $ud) {
306 $a_user_data[(int) $ud['usr_id']] = array_merge($ud, $course_user_data[(int) $ud['usr_id']]);
307 }
308
309 // Custom user data fields
310 if ($udf_ids) {
311 $a_user_data = array_reduce(
312 $this->profile->getDataForMultiple($usr_ids),
313 function (array $c, ProfileData $v) use ($udf_ids): array {
314 if (!$this->checkAcceptance($v->getId())) {
315 return $c;
316 }
317
318 foreach ($udf_ids as $field_id) {
319 $c[$v->getId()]['udf_' . $field_id] = $v->getAdditionalFieldByIdentifier($field_id);
320 }
321 },
322 $a_user_data
323 );
324 }
325 // Object specific user data fields
326 if ($odf_ids) {
328 foreach ($data as $usr_id => $fields) {
329 // #7264: as we get data for all course members filter against user data
330 if (!$this->checkAcceptance($usr_id) || !in_array($usr_id, $usr_ids)) {
331 continue;
332 }
333
334 foreach ($fields as $field_id => $value) {
335 $a_user_data[$usr_id]['odf_' . $field_id] = $value;
336 }
337 }
338
339 // add last edit date
340 foreach (ilObjectCustomUserFieldHistory::lookupEntriesByObjectId($this->getRepositoryObject()->getId()) as $usr_id => $edit_info) {
341 if (!isset($a_user_data[$usr_id])) {
342 continue;
343 }
344
345 if ($usr_id == $edit_info['update_user']) {
346 $a_user_data[$usr_id]['odf_last_update'] = '';
347 $a_user_data[$usr_id]['odf_info_txt'] = $GLOBALS['DIC']['lng']->txt('cdf_edited_by_self');
348 if (ilPrivacySettings::getInstance()->enabledAccessTimesByType($this->getRepositoryObject()->getType())) {
349 $a_user_data[$usr_id]['odf_last_update'] .= ('_' . $edit_info['editing_time']->get(IL_CAL_UNIX));
350 $a_user_data[$usr_id]['odf_info_txt'] .= (', ' . ilDatePresentation::formatDate($edit_info['editing_time']));
351 }
352 } else {
353 $a_user_data[$usr_id]['odf_last_update'] = $edit_info['update_user'];
354 $a_user_data[$usr_id]['odf_last_update'] .= ('_' . $edit_info['editing_time']->get(IL_CAL_UNIX));
355
356 $name = ilObjUser::_lookupName($edit_info['update_user']);
357 $a_user_data[$usr_id]['odf_info_txt'] = ($name['firstname'] . ' ' . $name['lastname'] . ', ' . ilDatePresentation::formatDate($edit_info['editing_time']));
358 }
359 }
360 }
361
362 foreach ($usr_data['set'] as $user) {
363 // Check acceptance
364 if (!$this->checkAcceptance((int) $user['usr_id'])) {
365 continue;
366 }
367 // DONE: accepted
368 foreach ($usr_data_fields as $field) {
369 $a_user_data[(int) $user['usr_id']][$field] = $user[$field] ?: '';
370 }
371 }
372
373 // Waiting list subscription
374 foreach ($this->wait as $usr_id => $wait_usr_data) {
375 if (isset($a_user_data[$usr_id])) {
376 $a_user_data[$usr_id]['sub_time'] = $wait_usr_data['time'];
377 }
378 }
379
380 $this->setMaxCount((int) ($usr_data['cnt'] ?? 0));
381 $this->setData($a_user_data);
382 }
383
384 public function showActionLinks(array $a_set): void
385 {
386 // tpl variables MAIL_LINK and MAIL_TITLE are unused but not removed
387 // from the template.
388 $this->ctrl->setParameterByClass(get_class($this->getParentObject()), 'member_id', $a_set['usr_id']);
389
390 $dropDownItems = array();
391 $dropDownItems[] = $this->uiFactory->button()->shy(
392 $this->lng->txt($this->getRepositoryObject()->getType() . '_mem_send_mail'),
393 $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'sendMailToSelectedUsers')
394 );
395
396 if (self::$has_odf_definitions) {
397 $dropDownItems[] = $this->uiFactory->button()->shy(
398 $this->lng->txt($this->getRepositoryObject()->getType() . '_cdf_edit_member'),
399 $this->ctrl->getLinkTargetByClass('ilobjectcustomuserfieldsgui', 'editMember')
400 );
401 }
402
403 $dropDown = $this->uiFactory->dropdown()->standard($dropDownItems)
404 ->withLabel($this->lng->txt('actions'));
405
406 $this->tpl->setVariable('ACTION_USER', $this->renderer->render($dropDown));
407 $this->ctrl->setParameterByClass(get_class($this->getParentObject()), 'member_id', null);
408 }
409
410 protected function checkAcceptance(int $a_usr_id): bool
411 {
412 return true;
413 }
414}
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)
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