ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilSubscriberTableGUI.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 = false;
35 protected array $subscribers = array();
36 protected bool $show_subject = true;
38
39 private UIRenderer $renderer;
40 private UIFactory $uiFactory;
42
43 public function __construct(
44 object $a_parent_obj,
46 bool $show_content = true,
47 bool $show_subject = true
48 ) {
49 $this->rep_object = $rep_object;
50 $this->setId('crs_sub_' . $this->getRepositoryObject()->getId());
51 parent::__construct($a_parent_obj, 'participants');
52
53 global $DIC;
54 $this->renderer = $DIC->ui()->renderer();
55 $this->uiFactory = $DIC->ui()->factory();
56 $this->profile = $DIC['user']->getProfile();
57
58 $this->lng->loadLanguageModule('grp');
59 $this->lng->loadLanguageModule('crs');
60 $this->setShowSubject($show_subject);
61 $this->setFormName('subscribers');
62 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, 'participants'));
63
64 $this->addColumn('', 'f', "1%", true);
65 $this->addColumn($this->lng->txt('name'), 'lastname', '20%');
66
67 $all_cols = $this->getSelectableColumns();
68 foreach ($this->getSelectedColumns() as $col) {
69 $this->addColumn(
70 $all_cols[$col]['txt'],
71 $col
72 );
73 }
74
75 if ($this->getShowSubject()) {
76 $this->addColumn($this->lng->txt('application_date'), 'sub_time');
77 $this->addColumn($this->lng->txt('message'), 'subject', '40%');
78 } else {
79 $this->addColumn($this->lng->txt('application_date'), 'sub_time');
80 }
81 $this->addColumn('', 'mail');
82 if ($this->getRepositoryObject()->getType() === "sess") {
83 $this->addMultiCommand('confirmAssignSubscribers', $this->lng->txt('sess_accept_request'));
84 } else {
85 $this->addMultiCommand('confirmAssignSubscribers', $this->lng->txt('assign'));
86 }
87 $this->addMultiCommand('confirmRefuseSubscribers', $this->lng->txt('refuse'));
88 $this->addMultiCommand('sendMailToSelectedUsers', $this->lng->txt('crs_mem_send_mail'));
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->setSelectAllCheckbox('subscribers', true);
96 $this->setRowTemplate("tpl.show_subscribers_row.html", "components/ILIAS/Membership");
97
98 if ($show_content) {
99 $this->enable('sort');
100 $this->enable('header');
101 $this->enable('numinfo');
102 $this->enable('select_all');
103 } else {
104 $this->disable('content');
105 $this->disable('header');
106 $this->disable('footer');
107 $this->disable('numinfo');
108 $this->disable('select_all');
109 }
110
111 $this->setExternalSegmentation(true);
112 self::$has_odf_definitions = (bool) ilCourseDefinedFieldDefinition::_hasFields($this->getRepositoryObject()->getId());
113 }
114
115 protected function getRepositoryObject(): ilObject
116 {
117 return $this->rep_object;
118 }
119
120 public function getSelectableColumns(): array
121 {
122 if (self::$all_columns) {
123 return self::$all_columns;
124 }
125
126 if ($this->getRepositoryObject()->getType() === 'sess') {
127 self::$all_columns['login'] = [
128 'txt' => $this->lng->txt('login'),
129 'default' => 1
130 ];
131 return self::$all_columns;
132 }
134 self::$all_columns = $ef->getSelectableFieldsInfo($this->getRepositoryObject()->getId());
135
136 // #25215
137 if (
138 is_array(self::$all_columns) &&
139 array_key_exists('consultation_hour', self::$all_columns)
140 ) {
141 unset(self::$all_columns['consultation_hour']);
142 }
143 return self::$all_columns;
144 }
145
146 protected function fillRow(array $a_set): void
147 {
148 if (!ilObjCourseGrouping::_checkGroupingDependencies($this->getRepositoryObject(), (int) $a_set['usr_id']) and
150 $prefix = $this->getRepositoryObject()->getType();
151 $this->tpl->setVariable(
152 'ALERT_MSG',
153 sprintf(
154 $this->lng->txt($prefix . '_lim_assigned'),
155 ilObject::_lookupTitle(current($ids))
156 )
157 );
158 }
159 $this->tpl->setVariable('VAL_ID', $a_set['usr_id']);
160 $this->tpl->setVariable('VAL_NAME', $a_set['lastname'] . ', ' . $a_set['firstname']);
161
162 foreach ($this->getSelectedColumns() as $field) {
163 switch ($field) {
164 case 'gender':
165 $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
166 $this->tpl->setCurrentBlock('custom_fields');
167 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
168 $this->tpl->parseCurrentBlock();
169 break;
170
171 case 'birthday':
172 $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate(
173 $a_set['birthday'],
175 )) : $this->lng->txt('no_date');
176 $this->tpl->setCurrentBlock('custom_fields');
177 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
178 $this->tpl->parseCurrentBlock();
179 break;
180
181 case 'odf_last_update':
182 $this->tpl->setVariable('VAL_CUST', (string) ($a_set['odf_info_txt'] ?? ''));
183 break;
184
185 case 'org_units':
186 $this->tpl->setCurrentBlock('custom_fields');
187 $this->tpl->setVariable(
188 'VAL_CUST',
189 ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits((int) $a_set['usr_id'])
190 );
191 $this->tpl->parseCurrentBlock();
192 break;
193
194 default:
195 $this->tpl->setCurrentBlock('custom_fields');
196 $this->tpl->setVariable('VAL_CUST', isset($a_set[$field]) ? (string) $a_set[$field] : '');
197 $this->tpl->parseCurrentBlock();
198 break;
199 }
200 }
201
202 $this->tpl->setVariable(
203 'VAL_SUBTIME',
205 );
206 $this->showActionLinks($a_set);
207 if ($this->getShowSubject()) {
208 if (strlen($a_set['subject'])) {
209 $this->tpl->setCurrentBlock('subject');
210 $this->tpl->setVariable('VAL_SUBJECT', '"' . $a_set['subject'] . '"');
211 $this->tpl->parseCurrentBlock();
212 } else {
213 $this->tpl->touchBlock('subject');
214 }
215 }
216 }
217
221 public function showActionLinks(array $a_set): void
222 {
223 $this->ctrl->setParameterByClass(get_class($this->getParentObject()), 'member_id', $a_set['usr_id']);
224 $this->ctrl->setParameter($this->parent_obj, 'member_id', $a_set['usr_id']);
225
226 $dropDownItems = array();
227 $dropDownItems[] = $this->uiFactory->button()->shy(
228 $this->lng->txt($this->getRepositoryObject()->getType() . '_mem_send_mail'),
229 $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'sendMailToSelectedUsers')
230 );
231
232 if (self::$has_odf_definitions) {
233 $this->ctrl->setParameterByClass('ilobjectcustomuserfieldsgui', 'member_id', $a_set['usr_id']);
234 $dropDownItems[] = $this->uiFactory->button()->shy(
235 $this->lng->txt($this->getRepositoryObject()->getType() . '_cdf_edit_member'),
236 $this->ctrl->getLinkTargetByClass('ilobjectcustomuserfieldsgui', 'editMember')
237 );
238 }
239
240 $dropDown = $this->uiFactory->dropdown()->standard($dropDownItems)
241 ->withLabel($this->lng->txt('actions'));
242 $this->tpl->setVariable('ACTION_USER', $this->renderer->render($dropDown));
243 }
244
251 public function readSubscriberData(array $a_subscriber_ids): void
252 {
254 $sub_ids = $sub_data = [];
255 foreach ($a_subscriber_ids as $usr_id) {
256 $sub_ids[] = $usr_id;
257 $sub_data[$usr_id] = $subscriber_data[$usr_id];
258 }
259
261
262 $additional_fields = $this->getSelectedColumns();
263 unset(
264 $additional_fields["firstname"],
265 $additional_fields["lastname"],
266 $additional_fields["last_login"],
267 $additional_fields["access_until"],
268 $additional_fields['org_units']
269 );
270
271 $udf_ids = $usr_data_fields = $odf_ids = array();
272 foreach ($additional_fields as $field) {
273 if (strpos($field, 'udf') === 0) {
274 $udf_ids[] = substr($field, 4);
275 continue;
276 }
277 if (strpos($field, 'odf') === 0) {
278 $odf_ids[] = substr($field, 4);
279 continue;
280 }
281
282 $usr_data_fields[] = $field;
283 }
284
286 $this->getOrderField(),
287 $this->getOrderDirection(),
288 $this->getOffset(),
289 $this->getLimit(),
290 '',
291 '',
292 null,
293 false,
294 false,
295 0,
296 0,
297 null,
298 $usr_data_fields,
299 $sub_ids
300 );
301
302 $usr_ids = [];
303 foreach ((array) $usr_data['set'] as $user) {
304 $usr_ids[] = $user['usr_id'];
305 }
306
307 // merge course data
308 $course_user_data = $this->getParentObject()->readMemberData($usr_ids, array());
309 $a_user_data = array();
310 foreach ((array) $usr_data['set'] as $ud) {
311 $a_user_data[$ud['usr_id']] = array_merge($ud, (array) $course_user_data[$ud['usr_id']]);
312 }
313
314 // Custom user data fields
315 if (is_array($udf_ids)) {
316 $a_user_data = array_reduce(
317 iterator_to_array($this->profile->getDataForMultiple($usr_ids)),
318 function (array $c, ProfileData $v) use ($udf_ids): array {
319 if (!$this->checkAcceptance($v->getId())) {
320 return $c;
321 }
322
323 foreach ($udf_ids as $field_id) {
324 $c[$v->getId()]['udf_' . $field_id] = implode(', ', $v->getAdditionalFieldByIdentifier($field_id) ?? []);
325 }
326 return $c;
327 },
328 $a_user_data
329 );
330 }
331 // Object specific user data fields
332 if (is_array($odf_ids)) {
334 foreach ($data as $usr_id => $fields) {
335 // #7264: as we get data for all course members filter against user data
336 if (!$this->checkAcceptance($usr_id) || !in_array($usr_id, $usr_ids)) {
337 continue;
338 }
339
340 foreach ($fields as $field_id => $value) {
341 $a_user_data[$usr_id]['odf_' . $field_id] = $value;
342 }
343 }
344
345 // add last edit date
346 foreach (ilObjectCustomUserFieldHistory::lookupEntriesByObjectId($this->getRepositoryObject()->getId()) as $usr_id => $edit_info) {
347 if (!isset($a_user_data[$usr_id])) {
348 continue;
349 }
350
351 if ($usr_id == $edit_info['update_user']) {
352 $a_user_data[$usr_id]['odf_last_update'] = '';
353 $a_user_data[$usr_id]['odf_info_txt'] = $GLOBALS['DIC']['lng']->txt('cdf_edited_by_self');
354 if (ilPrivacySettings::getInstance()->enabledAccessTimesByType($this->getRepositoryObject()->getType())) {
355 $a_user_data[$usr_id]['odf_last_update'] .= ('_' . $edit_info['editing_time']->get(IL_CAL_UNIX));
356 $a_user_data[$usr_id]['odf_info_txt'] .= (', ' . ilDatePresentation::formatDate($edit_info['editing_time']));
357 }
358 } else {
359 $a_user_data[$usr_id]['odf_last_update'] = $edit_info['update_user'];
360 $a_user_data[$usr_id]['odf_last_update'] .= ('_' . $edit_info['editing_time']->get(IL_CAL_UNIX));
361
362 $name = ilObjUser::_lookupName($edit_info['update_user']);
363 $a_user_data[$usr_id]['odf_info_txt'] = ($name['firstname'] . ' ' . $name['lastname'] . ', ' . ilDatePresentation::formatDate($edit_info['editing_time']));
364 }
365 }
366 }
367
368 foreach ($usr_data['set'] as $user) {
369 // Check acceptance
370 if (!$this->checkAcceptance((int) $user['usr_id'])) {
371 continue;
372 }
373 // DONE: accepted
374 foreach ($usr_data_fields as $field) {
375 $a_user_data[$user['usr_id']][$field] = $user[$field] ?: '';
376 }
377 }
378
379 // Waiting list subscription
380 foreach ($sub_data as $usr_id => $usr_data) {
381 if (!in_array($usr_id, $usr_ids)) {
382 continue;
383 }
384 $a_user_data[$usr_id]['sub_time'] = $usr_data['time'];
385 $a_user_data[$usr_id]['subject'] = $usr_data['subject'];
386 }
387
388 $this->setMaxCount(count($sub_ids));
389 $this->setData($a_user_data);
390 }
391
392 protected function checkAcceptance(int $a_usr_id): bool
393 {
394 return true;
395 }
396
397 public function setShowSubject(bool $a_value): void
398 {
399 $this->show_subject = $a_value;
400 }
401
402 public function getShowSubject(): bool
403 {
404 return $this->show_subject;
405 }
406}
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)
static _lookupName(int $a_user_id)
Class ilObject Basic functions for all objects.
static _lookupTitle(int $obj_id)
static lookupSubscribersData(int $a_obj_id)
GUI class for course/group subscriptions.
__construct(object $a_parent_obj, ilObject $rep_object, bool $show_content=true, bool $show_subject=true)
getSelectableColumns()
Get selectable columns.
showActionLinks(array $a_set)
Show action links (mail ; edit crs|grp data)
readSubscriberData(array $a_subscriber_ids)
read data @access protected
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...
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)
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)
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)
setData(array $a_data)
Set table data.
enable(string $a_module_name)
disable(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.
$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