ILIAS  release_8 Revision v8.24
class.ilWaitingListTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 protected static ?array $all_columns = null;
29 protected static bool $has_odf_definitions;
30 protected array $wait = [];
31 protected array $wait_user_ids = [];
33 protected ilObjUser $user;
35
36 public function __construct(
37 object $a_parent_obj,
40 ) {
41 global $DIC;
42
43 $this->rep_object = $rep_object;
44 $this->user = $DIC->user();
45
46 $this->setId('crs_wait_' . $this->getRepositoryObject()->getId());
47 parent::__construct($a_parent_obj, 'participants');
48 $this->setFormName('waiting');
49 $this->setPrefix('waiting');
50
51 $this->lng->loadLanguageModule('grp');
52 $this->lng->loadLanguageModule('crs');
53 $this->lng->loadLanguageModule('sess');
54 $this->lng->loadLanguageModule('ps');
55
56 $this->setExternalSorting(false);
57 $this->setExternalSegmentation(true);
58
59 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, 'participants'));
60
61 $this->addColumn('', 'f', "1", true);
62 $this->addColumn($this->lng->txt('name'), 'lastname', '20%');
63
64 $all_cols = $this->getSelectableColumns();
65 foreach ($this->getSelectedColumns() as $col) {
66 $this->addColumn($all_cols[$col]['txt'], $col);
67 }
68
69 $this->addColumn($this->lng->txt('application_date'), 'sub_time', "10%");
70 $this->addColumn('', 'mail', '10%');
71
72 $this->addMultiCommand('confirmAssignFromWaitingList', $this->lng->txt('assign'));
73 $this->addMultiCommand('confirmRefuseFromList', $this->lng->txt('refuse'));
74 $this->addMultiCommand('sendMailToSelectedUsers', $this->lng->txt('crs_mem_send_mail'));
75
76 $this->setDefaultOrderField('sub_time');
77
78 // begin-patch clipboard
79 $this->lng->loadLanguageModule('user');
80 $this->addMultiCommand('addToClipboard', $this->lng->txt('clipboard_add_btn'));
81 // end-patch clipboard
82
83 $this->setPrefix('waiting');
84 $this->setSelectAllCheckbox('waiting', true);
85
86 $this->setRowTemplate("tpl.show_waiting_list_row.html", "Services/Membership");
87
88 $this->enable('sort');
89 $this->enable('header');
90 $this->enable('numinfo');
91 $this->enable('select_all');
92
93 $this->waiting_list = $waiting_list;
94
95 self::$has_odf_definitions = (bool) ilCourseDefinedFieldDefinition::_hasFields($this->getRepositoryObject()->getId());
96 }
97
98 protected function getWaitingList(): ilWaitingList
99 {
100 return $this->waiting_list;
101 }
102
103 protected function getRepositoryObject(): ilObject
104 {
105 return $this->rep_object;
106 }
107
112 public function setUserIds(array $a_user_ids): void
113 {
114 $this->wait_user_ids = $this->wait = [];
115 foreach ($a_user_ids as $usr_id) {
116 $this->wait_user_ids[] = $usr_id;
117 $this->wait[$usr_id] = $this->getWaitingList()->getUser($usr_id);
118 }
119 }
120
121 public function numericOrdering(string $a_field): bool
122 {
123 switch ($a_field) {
124 case 'sub_time':
125 return true;
126 }
127 return parent::numericOrdering($a_field);
128 }
129
130 public function getSelectableColumns(): array
131 {
132 if (self::$all_columns) {
133 return self::$all_columns;
134 }
135
137 self::$all_columns = $ef->getSelectableFieldsInfo($this->getRepositoryObject()->getId());
138
139 // #25215
140 if (
141 is_array(self::$all_columns) &&
142 array_key_exists('consultation_hour', self::$all_columns)
143 ) {
144 unset(self::$all_columns['consultation_hour']);
145 }
146
147 if (
148 !is_array(self::$all_columns) ||
149 !array_key_exists('login', self::$all_columns)
150 ) {
151 self::$all_columns['login'] = [
152 'default' => 1,
153 'txt' => $this->lng->txt('login')
154 ];
155 }
156 return self::$all_columns;
157 }
158
159 protected function fillRow(array $a_set): void
160 {
161 if (
162 !ilObjCourseGrouping::_checkGroupingDependencies($this->getRepositoryObject(), (int) $a_set['usr_id']) &&
164 ) {
165 $prefix = $this->getRepositoryObject()->getType();
166 $this->tpl->setVariable(
167 'ALERT_MSG',
168 sprintf(
169 $this->lng->txt($prefix . '_lim_assigned'),
170 ilObject::_lookupTitle(current($ids))
171 )
172 );
173 }
174
175 $this->tpl->setVariable('VAL_ID', $a_set['usr_id']);
176 $this->tpl->setVariable('VAL_NAME', $a_set['lastname'] . ', ' . $a_set['firstname']);
177
178 foreach ($this->getSelectedColumns() as $field) {
179 switch ($field) {
180 case 'gender':
181 $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
182 $this->tpl->setCurrentBlock('custom_fields');
183 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
184 $this->tpl->parseCurrentBlock();
185 break;
186
187 case 'birthday':
188 $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate(
189 $a_set['birthday'],
191 )) : $this->lng->txt('no_date');
192 $this->tpl->setCurrentBlock('custom_fields');
193 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
194 $this->tpl->parseCurrentBlock();
195 break;
196
197 case 'odf_last_update':
198 $this->tpl->setVariable('VAL_CUST', (string) ($a_set['odf_info_txt'] ?? ''));
199 break;
200
201 case 'org_units':
202 $this->tpl->setCurrentBlock('custom_fields');
203 $this->tpl->setVariable(
204 'VAL_CUST',
205 ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits((int) $a_set['usr_id'])
206 );
207 $this->tpl->parseCurrentBlock();
208 break;
209
210 default:
211 $this->tpl->setCurrentBlock('custom_fields');
212 $this->tpl->setVariable('VAL_CUST', isset($a_set[$field]) ? (string) $a_set[$field] : '');
213 $this->tpl->parseCurrentBlock();
214 break;
215 }
216 }
217 $this->tpl->setVariable(
218 'VAL_SUBTIME',
220 );
221 $this->showActionLinks($a_set);
222 }
223
224 public function readUserData(): void
225 {
227
228 $additional_fields = $this->getSelectedColumns();
229 unset(
230 $additional_fields["firstname"],
231 $additional_fields["lastname"],
232 $additional_fields["last_login"],
233 $additional_fields["access_until"],
234 $additional_fields['org_units']
235 );
236
237 $udf_ids = $usr_data_fields = $odf_ids = array();
238 foreach ($additional_fields as $field) {
239 if (strpos($field, 'udf') === 0) {
240 $udf_ids[] = substr($field, 4);
241 continue;
242 }
243 if (strpos($field, 'odf') === 0) {
244 $odf_ids[] = substr($field, 4);
245 continue;
246 }
247
248 $usr_data_fields[] = $field;
249 }
250
252 $this->getOrderField(),
253 $this->getOrderDirection(),
254 $this->getOffset(),
255 $this->getLimit(),
256 '',
257 '',
258 null,
259 false,
260 false,
261 0,
262 0,
263 null,
264 $usr_data_fields,
265 $this->wait_user_ids
266 );
267 if (0 === count($usr_data['set']) && $this->getOffset() > 0 && $this->getExternalSegmentation()) {
268 $this->resetOffset();
269
271 $this->getOrderField(),
272 $this->getOrderDirection(),
273 $this->getOffset(),
274 $this->getLimit(),
275 '',
276 '',
277 null,
278 false,
279 false,
280 0,
281 0,
282 null,
283 $usr_data_fields,
284 $this->wait_user_ids
285 );
286 }
287 $usr_ids = [];
288 foreach ((array) $usr_data['set'] as $user) {
289 $usr_ids[] = (int) $user['usr_id'];
290 }
291
292 // merge course data
293 $course_user_data = $this->getParentObject()->readMemberData($usr_ids, array());
294 $a_user_data = array();
295 foreach ((array) $usr_data['set'] as $ud) {
296 $a_user_data[(int) $ud['usr_id']] = array_merge($ud, $course_user_data[(int) $ud['usr_id']]);
297 }
298
299 // Custom user data fields
300 if ($udf_ids) {
301 $data = ilUserDefinedData::lookupData($usr_ids, $udf_ids);
302 foreach ($data as $usr_id => $fields) {
303 if (!$this->checkAcceptance($usr_id)) {
304 continue;
305 }
306
307 foreach ($fields as $field_id => $value) {
308 $a_user_data[$usr_id]['udf_' . $field_id] = $value;
309 }
310 }
311 }
312 // Object specific user data fields
313 if ($odf_ids) {
315 foreach ($data as $usr_id => $fields) {
316 // #7264: as we get data for all course members filter against user data
317 if (!$this->checkAcceptance($usr_id) || !in_array($usr_id, $usr_ids)) {
318 continue;
319 }
320
321 foreach ($fields as $field_id => $value) {
322 $a_user_data[$usr_id]['odf_' . $field_id] = $value;
323 }
324 }
325
326 // add last edit date
327 foreach (ilObjectCustomUserFieldHistory::lookupEntriesByObjectId($this->getRepositoryObject()->getId()) as $usr_id => $edit_info) {
328 if (!isset($a_user_data[$usr_id])) {
329 continue;
330 }
331
332 if ($usr_id == $edit_info['update_user']) {
333 $a_user_data[$usr_id]['odf_last_update'] = '';
334 $a_user_data[$usr_id]['odf_info_txt'] = $GLOBALS['DIC']['lng']->txt('cdf_edited_by_self');
335 if (ilPrivacySettings::getInstance()->enabledAccessTimesByType($this->getRepositoryObject()->getType())) {
336 $a_user_data[$usr_id]['odf_last_update'] .= ('_' . $edit_info['editing_time']->get(IL_CAL_UNIX));
337 $a_user_data[$usr_id]['odf_info_txt'] .= (', ' . ilDatePresentation::formatDate($edit_info['editing_time']));
338 }
339 } else {
340 $a_user_data[$usr_id]['odf_last_update'] = $edit_info['update_user'];
341 $a_user_data[$usr_id]['odf_last_update'] .= ('_' . $edit_info['editing_time']->get(IL_CAL_UNIX));
342
343 $name = ilObjUser::_lookupName($edit_info['update_user']);
344 $a_user_data[$usr_id]['odf_info_txt'] = ($name['firstname'] . ' ' . $name['lastname'] . ', ' . ilDatePresentation::formatDate($edit_info['editing_time']));
345 }
346 }
347 }
348
349 foreach ($usr_data['set'] as $user) {
350 // Check acceptance
351 if (!$this->checkAcceptance((int) $user['usr_id'])) {
352 continue;
353 }
354 // DONE: accepted
355 foreach ($usr_data_fields as $field) {
356 $a_user_data[(int) $user['usr_id']][$field] = $user[$field] ?: '';
357 }
358 }
359
360 // Waiting list subscription
361 foreach ($this->wait as $usr_id => $wait_usr_data) {
362 if (isset($a_user_data[$usr_id])) {
363 $a_user_data[$usr_id]['sub_time'] = $wait_usr_data['time'];
364 }
365 }
366
367 $this->setMaxCount((int) ($usr_data['cnt'] ?? 0));
368 $this->setData($a_user_data);
369 }
370
371 public function showActionLinks(array $a_set): void
372 {
373 if (!self::$has_odf_definitions) {
374 $this->ctrl->setParameterByClass(get_class($this->getParentObject()), 'member_id', $a_set['usr_id']);
375 $link = $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'sendMailToSelectedUsers');
376 $this->tpl->setVariable('MAIL_LINK', $link);
377 $this->tpl->setVariable('MAIL_TITLE', $this->lng->txt('crs_mem_send_mail'));
378 $this->ctrl->setParameterByClass(get_class($this->getParentObject()), 'member_id', null);
379 return;
380 }
381
382 // show action menu
383 $list = new ilAdvancedSelectionListGUI();
384 $list->setSelectionHeaderClass('small');
385 $list->setItemLinkClass('small');
386 $list->setId('actl_' . $a_set['usr_id'] . '_' . $this->getId());
387 $list->setListTitle($this->lng->txt('actions'));
388
389 $this->ctrl->setParameterByClass(get_class($this->getParentObject()), 'member_id', $a_set['usr_id']);
390 $this->ctrl->setParameter($this->parent_obj, 'member_id', $a_set['usr_id']);
391 $trans = $this->lng->txt($this->getRepositoryObject()->getType() . '_mem_send_mail');
392 $link = $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'sendMailToSelectedUsers');
393 $list->addItem($trans, '', $link, 'sendMailToSelectedUsers');
394
395 $this->ctrl->setParameterByClass('ilobjectcustomuserfieldsgui', 'member_id', $a_set['usr_id']);
396 $trans = $this->lng->txt($this->getRepositoryObject()->getType() . '_cdf_edit_member');
397 $list->addItem($trans, '', $this->ctrl->getLinkTargetByClass('ilobjectcustomuserfieldsgui', 'editMember'));
398 $this->ctrl->setParameterByClass(get_class($this->getParentObject()), 'member_id', null);
399 $this->tpl->setVariable('ACTION_USER', $list->getHTML());
400 }
401
402 protected function checkAcceptance(int $a_usr_id): bool
403 {
404 return true;
405 }
406}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
const IL_CAL_DATE
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
@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)
lookup user name
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 lookupData(array $a_user_ids, array $a_field_ids)
Lookup data.
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc