ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSubscriberTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
28  protected static ?array $all_columns = null;
29  protected static bool $has_odf_definitions = false;
30  protected array $subscribers = array();
31  protected bool $show_subject = true;
32  protected ilObject $rep_object;
33 
34  public function __construct(
35  object $a_parent_obj,
36  ilObject $rep_object,
37  bool $show_content = true,
38  bool $show_subject = true
39  ) {
40  $this->rep_object = $rep_object;
41  $this->setId('crs_sub_' . $this->getRepositoryObject()->getId());
42  parent::__construct($a_parent_obj, 'participants');
43 
44  $this->lng->loadLanguageModule('grp');
45  $this->lng->loadLanguageModule('crs');
46  $this->setShowSubject($show_subject);
47  $this->setFormName('subscribers');
48  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, 'participants'));
49 
50  $this->addColumn('', 'f', "1%", true);
51  $this->addColumn($this->lng->txt('name'), 'lastname', '20%');
52 
53  $all_cols = $this->getSelectableColumns();
54  foreach ($this->getSelectedColumns() as $col) {
55  $this->addColumn(
56  $all_cols[$col]['txt'],
57  $col
58  );
59  }
60 
61  if ($this->getShowSubject()) {
62  $this->addColumn($this->lng->txt('application_date'), 'sub_time');
63  $this->addColumn($this->lng->txt('message'), 'subject', '40%');
64  } else {
65  $this->addColumn($this->lng->txt('application_date'), 'sub_time');
66  }
67  $this->addColumn('', 'mail');
68  if ($this->getRepositoryObject()->getType() === "sess") {
69  $this->addMultiCommand('confirmAssignSubscribers', $this->lng->txt('sess_accept_request'));
70  } else {
71  $this->addMultiCommand('confirmAssignSubscribers', $this->lng->txt('assign'));
72  }
73  $this->addMultiCommand('confirmRefuseSubscribers', $this->lng->txt('refuse'));
74  $this->addMultiCommand('sendMailToSelectedUsers', $this->lng->txt('crs_mem_send_mail'));
75 
76  // begin-patch clipboard
77  $this->lng->loadLanguageModule('user');
78  $this->addMultiCommand('addToClipboard', $this->lng->txt('clipboard_add_btn'));
79  // end-patch clipboard
80 
81  $this->setPrefix('subscribers');
82  $this->setSelectAllCheckbox('subscribers', true);
83  $this->setRowTemplate("tpl.show_subscribers_row.html", "Services/Membership");
84 
85  if ($show_content) {
86  $this->enable('sort');
87  $this->enable('header');
88  $this->enable('numinfo');
89  $this->enable('select_all');
90  } else {
91  $this->disable('content');
92  $this->disable('header');
93  $this->disable('footer');
94  $this->disable('numinfo');
95  $this->disable('select_all');
96  }
97 
98  $this->setExternalSegmentation(true);
99  self::$has_odf_definitions = (bool) ilCourseDefinedFieldDefinition::_hasFields($this->getRepositoryObject()->getId());
100  }
101 
102  protected function getRepositoryObject(): ilObject
103  {
104  return $this->rep_object;
105  }
106 
107  public function getSelectableColumns(): array
108  {
109  if (self::$all_columns) {
110  return self::$all_columns;
111  }
112 
113  if ($this->getRepositoryObject()->getType() === 'sess') {
114  self::$all_columns['login'] = [
115  'txt' => $this->lng->txt('login'),
116  'default' => 1
117  ];
118  return self::$all_columns;
119  }
121  self::$all_columns = $ef->getSelectableFieldsInfo($this->getRepositoryObject()->getId());
122 
123  // #25215
124  if (
125  is_array(self::$all_columns) &&
126  array_key_exists('consultation_hour', self::$all_columns)
127  ) {
128  unset(self::$all_columns['consultation_hour']);
129  }
130  return self::$all_columns;
131  }
132 
133  protected function fillRow(array $a_set): void
134  {
135  if (!ilObjCourseGrouping::_checkGroupingDependencies($this->getRepositoryObject(), (int) $a_set['usr_id']) and
137  $prefix = $this->getRepositoryObject()->getType();
138  $this->tpl->setVariable(
139  'ALERT_MSG',
140  sprintf(
141  $this->lng->txt($prefix . '_lim_assigned'),
142  ilObject::_lookupTitle(current($ids))
143  )
144  );
145  }
146  $this->tpl->setVariable('VAL_ID', $a_set['usr_id']);
147  $this->tpl->setVariable('VAL_NAME', $a_set['lastname'] . ', ' . $a_set['firstname']);
148 
149  foreach ($this->getSelectedColumns() as $field) {
150  switch ($field) {
151  case 'gender':
152  $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
153  $this->tpl->setCurrentBlock('custom_fields');
154  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
155  $this->tpl->parseCurrentBlock();
156  break;
157 
158  case 'birthday':
159  $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate(
160  $a_set['birthday'],
162  )) : $this->lng->txt('no_date');
163  $this->tpl->setCurrentBlock('custom_fields');
164  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
165  $this->tpl->parseCurrentBlock();
166  break;
167 
168  case 'odf_last_update':
169  $this->tpl->setVariable('VAL_CUST', (string) ($a_set['odf_info_txt'] ?? ''));
170  break;
171 
172  case 'org_units':
173  $this->tpl->setCurrentBlock('custom_fields');
174  $this->tpl->setVariable(
175  'VAL_CUST',
176  ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits((int)$a_set['usr_id'])
177  );
178  $this->tpl->parseCurrentBlock();
179  break;
180 
181  default:
182  $this->tpl->setCurrentBlock('custom_fields');
183  $this->tpl->setVariable('VAL_CUST', isset($a_set[$field]) ? (string) $a_set[$field] : '');
184  $this->tpl->parseCurrentBlock();
185  break;
186  }
187  }
188 
189  $this->tpl->setVariable(
190  'VAL_SUBTIME',
191  ilDatePresentation::formatDate(new ilDateTime($a_set['sub_time'], IL_CAL_UNIX))
192  );
193  $this->showActionLinks($a_set);
194  if ($this->getShowSubject()) {
195  if (strlen($a_set['subject'])) {
196  $this->tpl->setCurrentBlock('subject');
197  $this->tpl->setVariable('VAL_SUBJECT', '"' . $a_set['subject'] . '"');
198  $this->tpl->parseCurrentBlock();
199  } else {
200  $this->tpl->touchBlock('subject');
201  }
202  }
203  }
204 
208  public function showActionLinks(array $a_set): void
209  {
210  if (!self::$has_odf_definitions) {
211  $this->ctrl->setParameterByClass(get_class($this->getParentObject()), 'member_id', $a_set['usr_id']);
212  $link = $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'sendMailToSelectedUsers');
213  $this->tpl->setVariable('MAIL_LINK', $link);
214  $this->tpl->setVariable('MAIL_TITLE', $this->lng->txt('crs_mem_send_mail'));
215  return;
216  }
217 
218  // show action menu
219  $list = new ilAdvancedSelectionListGUI();
220  $list->setSelectionHeaderClass('small');
221  $list->setItemLinkClass('small');
222  $list->setId('actl_' . $a_set['usr_id'] . '_' . $this->getId());
223  $list->setListTitle($this->lng->txt('actions'));
224 
225  $this->ctrl->setParameterByClass(get_class($this->getParentObject()), 'member_id', $a_set['usr_id']);
226  $this->ctrl->setParameter($this->parent_obj, 'member_id', $a_set['usr_id']);
227  $trans = $this->lng->txt($this->getRepositoryObject()->getType() . '_mem_send_mail');
228  $link = $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'sendMailToSelectedUsers');
229  $list->addItem($trans, '', $link, 'sendMailToSelectedUsers');
230 
231  $this->ctrl->setParameterByClass('ilobjectcustomuserfieldsgui', 'member_id', $a_set['usr_id']);
232  $trans = $this->lng->txt($this->getRepositoryObject()->getType() . '_cdf_edit_member');
233  $list->addItem($trans, '', $this->ctrl->getLinkTargetByClass('ilobjectcustomuserfieldsgui', 'editMember'));
234 
235  $this->tpl->setVariable('ACTION_USER', $list->getHTML());
236  }
237 
244  public function readSubscriberData(array $a_subscriber_ids): void
245  {
246  $subscriber_data = ilParticipants::lookupSubscribersData($this->getRepositoryObject()->getId());
247  $sub_ids = $sub_data = [];
248  foreach ($a_subscriber_ids as $usr_id) {
249  $sub_ids[] = $usr_id;
250  $sub_data[$usr_id] = $subscriber_data[$usr_id];
251  }
252 
253  $this->determineOffsetAndOrder();
254 
255  $additional_fields = $this->getSelectedColumns();
256  unset(
257  $additional_fields["firstname"],
258  $additional_fields["lastname"],
259  $additional_fields["last_login"],
260  $additional_fields["access_until"],
261  $additional_fields['org_units']
262  );
263 
264  $udf_ids = $usr_data_fields = $odf_ids = array();
265  foreach ($additional_fields as $field) {
266  if (strpos($field, 'udf') === 0) {
267  $udf_ids[] = substr($field, 4);
268  continue;
269  }
270  if (strpos($field, 'odf') === 0) {
271  $odf_ids[] = substr($field, 4);
272  continue;
273  }
274 
275  $usr_data_fields[] = $field;
276  }
277 
278  $usr_data = ilUserQuery::getUserListData(
279  $this->getOrderField(),
280  $this->getOrderDirection(),
281  $this->getOffset(),
282  $this->getLimit(),
283  '',
284  '',
285  null,
286  false,
287  false,
288  0,
289  0,
290  null,
291  $usr_data_fields,
292  $sub_ids
293  );
294 
295  $usr_ids = [];
296  foreach ((array) $usr_data['set'] as $user) {
297  $usr_ids[] = $user['usr_id'];
298  }
299 
300  // merge course data
301  $course_user_data = $this->getParentObject()->readMemberData($usr_ids, array());
302  $a_user_data = array();
303  foreach ((array) $usr_data['set'] as $ud) {
304  $a_user_data[$ud['usr_id']] = array_merge($ud, (array) $course_user_data[$ud['usr_id']]);
305  }
306 
307  // Custom user data fields
308  if (is_array($udf_ids)) {
309  $data = ilUserDefinedData::lookupData($usr_ids, $udf_ids);
310  foreach ($data as $usr_id => $fields) {
311  if (!$this->checkAcceptance($usr_id)) {
312  continue;
313  }
314 
315  foreach ($fields as $field_id => $value) {
316  $a_user_data[$usr_id]['udf_' . $field_id] = $value;
317  }
318  }
319  }
320  // Object specific user data fields
321  if (is_array($odf_ids)) {
323  foreach ($data as $usr_id => $fields) {
324  // #7264: as we get data for all course members filter against user data
325  if (!$this->checkAcceptance($usr_id) || !in_array($usr_id, $usr_ids)) {
326  continue;
327  }
328 
329  foreach ($fields as $field_id => $value) {
330  $a_user_data[$usr_id]['odf_' . $field_id] = $value;
331  }
332  }
333 
334  // add last edit date
335  foreach (ilObjectCustomUserFieldHistory::lookupEntriesByObjectId($this->getRepositoryObject()->getId()) as $usr_id => $edit_info) {
336  if (!isset($a_user_data[$usr_id])) {
337  continue;
338  }
339 
340  if ($usr_id == $edit_info['update_user']) {
341  $a_user_data[$usr_id]['odf_last_update'] = '';
342  $a_user_data[$usr_id]['odf_info_txt'] = $GLOBALS['DIC']['lng']->txt('cdf_edited_by_self');
343  if (ilPrivacySettings::getInstance()->enabledAccessTimesByType($this->getRepositoryObject()->getType())) {
344  $a_user_data[$usr_id]['odf_last_update'] .= ('_' . $edit_info['editing_time']->get(IL_CAL_UNIX));
345  $a_user_data[$usr_id]['odf_info_txt'] .= (', ' . ilDatePresentation::formatDate($edit_info['editing_time']));
346  }
347  } else {
348  $a_user_data[$usr_id]['odf_last_update'] = $edit_info['update_user'];
349  $a_user_data[$usr_id]['odf_last_update'] .= ('_' . $edit_info['editing_time']->get(IL_CAL_UNIX));
350 
351  $name = ilObjUser::_lookupName($edit_info['update_user']);
352  $a_user_data[$usr_id]['odf_info_txt'] = ($name['firstname'] . ' ' . $name['lastname'] . ', ' . ilDatePresentation::formatDate($edit_info['editing_time']));
353  }
354  }
355  }
356 
357  foreach ($usr_data['set'] as $user) {
358  // Check acceptance
359  if (!$this->checkAcceptance((int) $user['usr_id'])) {
360  continue;
361  }
362  // DONE: accepted
363  foreach ($usr_data_fields as $field) {
364  $a_user_data[$user['usr_id']][$field] = $user[$field] ?: '';
365  }
366  }
367 
368  // Waiting list subscription
369  foreach ($sub_data as $usr_id => $usr_data) {
370  if (!in_array($usr_id, $usr_ids)) {
371  continue;
372  }
373  $a_user_data[$usr_id]['sub_time'] = $usr_data['time'];
374  $a_user_data[$usr_id]['subject'] = $usr_data['subject'];
375  }
376 
377  $this->setMaxCount(count($sub_ids));
378  $this->setData($a_user_data);
379  }
380 
381  protected function checkAcceptance(int $a_usr_id): bool
382  {
383  return true;
384  }
385 
386  public function setShowSubject(bool $a_value): void
387  {
388  $this->show_subject = $a_value;
389  }
390 
391  public function getShowSubject(): bool
392  {
393  return $this->show_subject;
394  }
395 }
static lookupData(array $a_user_ids, array $a_field_ids)
Lookup data.
setData(array $a_data)
enable(string $a_module_name)
setFormAction(string $a_form_action, bool $a_multipart=false)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static _getValuesByObjId(int $a_obj_id)
static _checkGroupingDependencies(ilObject $container_obj, ?int $a_user_id=null)
static _lookupName(int $a_user_id)
lookup user name
const IL_CAL_UNIX
setFormName(string $a_name="")
setId(string $a_val)
readSubscriberData(array $a_subscriber_ids)
read data protected
if($format !==null) $name
Definition: metadata.php:247
static lookupSubscribersData(int $a_obj_id)
__construct(object $a_parent_obj, ilObject $rep_object, bool $show_content=true, bool $show_subject=true)
static _lookupTitle(int $obj_id)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
GUI class for course/group subscriptions.
const IL_CAL_DATE
static _getInstanceByType(string $a_type)
Get Singleton Instance.
__construct(Container $dic, ilPlugin $plugin)
showActionLinks(array $a_set)
Show action links (mail ; edit crs|grp data)
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)
disable(string $a_module_name)
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.
addMultiCommand(string $a_cmd, string $a_text)
static _hasFields(int $a_container_id)
Check if there are any define fields.
determineOffsetAndOrder(bool $a_omit_offset=false)
setMaxCount(int $a_max_count)
set max.
setExternalSegmentation(bool $a_val)
setPrefix(string $a_prefix)