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