ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilMailFolderTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
31 {
32  private readonly GlobalHttpState $http;
33  protected array $_folderNode = [];
34  protected int $_number_of_mails = 0;
35  protected array $_selectedItems = [];
36  protected ilObjUser $user;
37  protected array $filter = [];
38  protected array $sub_filter = [];
39  protected array $visibleOptionalColumns = [];
40  protected array $optionalColumns = [];
41  protected array $optional_filter = [];
42  private readonly Factory $uiFactory;
43  private readonly Renderer $uiRenderer;
44  private ?array $column_definition = null;
45 
46  public function __construct(
47  protected ilMailFolderGUI $_parentObject,
48  protected int $_currentFolderId,
49  string $a_parent_cmd,
50  protected bool $_isTrashFolder,
51  protected bool $_isSentFolder,
52  protected bool $_isDraftsFolder,
53  Factory $uiFactory = null,
54  Renderer $uiRenderer = null
55  ) {
56  global $DIC;
57  $this->user = $DIC->user();
58  $this->uiFactory = $uiFactory ?? $DIC->ui()->factory();
59  $this->uiRenderer = $uiRenderer ?? $DIC->ui()->renderer();
60  $this->http = $DIC->http();
61 
62  $this->setId('mail_folder_tbl_' . $_currentFolderId);
63  $this->setPrefix('mtable');
64 
65  $this->setExternalSorting(true);
66  $this->setExternalSegmentation(true);
67  $this->setDefaultOrderField('send_time');
68  $this->setDefaultOrderDirection('desc');
69 
70  parent::__construct($_parentObject, $a_parent_cmd);
71 
72  $this->ctrl->setParameter($this->getParentObject(), 'mobj_id', $this->_currentFolderId);
73  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'showFolder'));
74  $this->ctrl->clearParameters($this->getParentObject());
75 
76  $this->setEnableTitle(true);
77  $this->setSelectAllCheckbox('mail_id[]');
78  $this->setRowTemplate('tpl.mail_folder_row.html', 'Services/Mail');
79 
80  $this->setFilterCommand('applyFilter');
81  $this->setResetCommand('resetFilter');
82 
83  $this->initFilter();
84 
85  $columns = $this->getColumnDefinition(false);
86  $this->optionalColumns = $this->getSelectableColumns();
87  $this->visibleOptionalColumns = $this->getSelectedColumns();
88  foreach ($columns as $index => $column) {
89  if ($this->isColumnVisible($index)) {
90  $this->addColumn(
91  $column['txt'],
92  isset($column['sortable']) && $column['sortable'] ? $column['field'] : '',
93  $column['width'] ?? '',
94  isset($column['is_checkbox']) && $column['is_checkbox']
95  );
96  }
97  }
98  }
99 
100  public function getSelectableColumns(): array
101  {
102  $optionalColumns = array_filter($this->getColumnDefinition(), static function (array $column): bool {
103  return isset($column['optional']) && $column['optional'];
104  });
105 
106  $columns = [];
107  foreach ($optionalColumns as $column) {
108  $columns[$column['field']] = $column;
109  }
110 
111  return $columns;
112  }
113 
114  protected function isColumnVisible(int $index): bool
115  {
116  $columnDefinition = $this->getColumnDefinition();
117  if (array_key_exists($index, $columnDefinition)) {
118  $column = $columnDefinition[$index];
119  if (isset($column['optional']) && !$column['optional']) {
120  return true;
121  }
122  if (array_key_exists($column['field'], $this->visibleOptionalColumns)) {
123  return true;
124  }
125  }
126 
127  return false;
128  }
129 
130  final protected function fillRow(array $a_set): void
131  {
132  foreach ($this->removeInvisibleFields($a_set) as $key => $value) {
133  $this->tpl->setVariable(strtoupper($key), $value);
134  }
135  }
136 
137  protected function removeInvisibleFields(array $row): array
138  {
139  if (!array_key_exists('attachments', $this->visibleOptionalColumns)) {
140  unset($row['attachment_indicator']);
141  }
142 
143  if (!array_key_exists('personal_picture', $this->visibleOptionalColumns)) {
144  unset($row['img_sender'], $row['alt_sender']);
145  }
146 
147  return $row;
148  }
149 
150  protected function getColumnDefinition(bool $use_cached_result = true): array
151  {
152  if ($use_cached_result && $this->column_definition !== null) {
154  }
155 
156  $i = 0;
157 
158  $columns = [];
159 
160  $columns[++$i] = [
161  'field' => 'chb',
162  'txt' => '',
163  'default' => true,
164  'optional' => false,
165  'sortable' => false,
166  'is_checkbox' => true,
167  'width' => '1%'
168  ];
169 
170  $columns[++$i] = [
171  'field' => 'attachments',
172  'txt' => $this->lng->txt('mail_tbl_head_attachments'),
173  'default' => false,
174  'optional' => true,
175  'sortable' => false,
176  'width' => '5%'
177  ];
178 
179  if (!$this->isDraftFolder() && !$this->isSentFolder()) {
180  $columns[++$i] = [
181  'field' => 'personal_picture',
182  'txt' => $this->lng->txt('personal_picture'),
183  'default' => true,
184  'optional' => true,
185  'sortable' => false,
186  'width' => '5%'
187  ];
188  }
189 
190  if ($this->isDraftFolder() || $this->isSentFolder()) {
191  $columns[++$i] = [
192  'field' => 'rcp_to',
193  'txt' => $this->lng->txt('recipient'),
194  'default' => true,
195  'optional' => false,
196  'sortable' => true,
197  'width' => '35%'
198  ];
199  } else {
200  $columns[++$i] = [
201  'field' => 'from',
202  'txt' => $this->lng->txt('sender'),
203  'default' => true,
204  'optional' => false,
205  'sortable' => true,
206  'width' => '20%'
207  ];
208  }
209 
210  if ($this->shouldUseLuceneSearch()) {
211  $columns[++$i] = [
212  'field' => 'search_content',
213  'txt' => $this->lng->txt('search_content'),
214  'default' => true,
215  'optional' => false,
216  'sortable' => false,
217  'width' => '35%'
218  ];
219  } else {
220  $columns[++$i] = [
221  'field' => 'm_subject',
222  'txt' => $this->lng->txt('subject'),
223  'default' => true,
224  'optional' => false,
225  'sortable' => true,
226  'width' => '35%'
227  ];
228  }
229 
230  $columns[++$i] = [
231  'field' => 'send_time',
232  'txt' => $this->lng->txt('date'),
233  'default' => true,
234  'optional' => false,
235  'sortable' => true,
236  'width' => '20%'
237  ];
238 
239  $columns[++$i] = [
240  'field' => 'actions',
241  'txt' => $this->lng->txt('actions'),
242  'default' => true,
243  'optional' => false,
244  'sortable' => false,
245  'width' => '5%'
246  ];
247 
248  $this->column_definition = $columns;
250  }
251 
255  final public function prepareHTML(): self
256  {
257  $mtree = new ilTree($this->user->getId());
258  $mtree->setTableNames('mail_tree', 'mail_obj_data');
259  $this->_folderNode = $mtree->getNodeData($this->_currentFolderId);
260 
261  $this->fetchTableData();
262 
263  $this->initCommandButtons();
264  $this->initMultiCommands($this->_parentObject->mbox->getActions($this->_currentFolderId));
265 
266  return $this;
267  }
268 
269  public function isDraftFolder(): bool
270  {
271  return $this->_isDraftsFolder;
272  }
273 
274  public function isSentFolder(): bool
275  {
276  return $this->_isSentFolder;
277  }
278 
279  public function isTrashFolder(): bool
280  {
281  return $this->_isTrashFolder;
282  }
283 
284  private function initCommandButtons(): self
285  {
286  if ($this->_folderNode['m_type'] === 'trash' && $this->getNumberOfMails() > 0) {
287  $this->addCommandButton('confirmEmptyTrash', $this->lng->txt('mail_empty_trash'));
288  }
289 
290  return $this;
291  }
292 
293  private function initMultiCommands(array $actions): self
294  {
295  foreach ($actions as $key => $action) {
296  if ($key === 'moveMails') {
297  $folders = $this->_parentObject->mbox->getSubFolders();
298  foreach ($folders as $folder) {
299  if ($folder['type'] !== 'trash' || !$this->isTrashFolder()) {
300  if ($folder['type'] !== 'user_folder') {
301  $label = $action . ' ' . $this->lng->txt('mail_' . $folder['title']) .
302  ($folder['type'] === 'trash' ? ' (' . $this->lng->txt('delete') . ')' : '');
303  $this->addMultiCommand($key . '_' . $folder['obj_id'], $label);
304  } else {
305  $this->addMultiCommand(
306  $key . '_' . $folder['obj_id'],
307  $action . ' ' . $folder['title']
308  );
309  }
310  }
311  }
312  } elseif ($key !== 'deleteMails' || $this->isTrashFolder()) {
313  $this->addMultiCommand($key, $action);
314  }
315  }
316 
317  return $this;
318  }
319 
320  public function setSelectedItems(array $a_selected_items): self
321  {
322  $this->_selectedItems = $a_selected_items;
323 
324  return $this;
325  }
326 
327  public function getSelectedItems(): array
328  {
329  return $this->_selectedItems;
330  }
331 
332  protected function shouldUseLuceneSearch(): bool
333  {
334  return isset($this->filter['mail_filter']) &&
335  is_string($this->filter['mail_filter']) &&
336  $this->filter['mail_filter'] !== '' &&
337  $this->isLuceneEnabled();
338  }
339 
340  private function isLuceneEnabled(): bool
341  {
342  return ilSearchSettings::getInstance()->enabledLucene();
343  }
344 
348  protected function fetchTableData(): self
349  {
350  $data = [];
351  if ($this->_folderNode['m_type'] === 'user_folder') {
352  $txt_folder = $this->_folderNode['title'];
353  $img_folder = 'icon_user_folder.png';
354  } else {
355  $txt_folder = $this->lng->txt('mail_' . $this->_folderNode['title']);
356  $img_folder = 'icon' . substr($this->_folderNode['title'], 1) . '.png';
357  }
358 
359  $result = null;
360 
361  try {
362  if ($this->shouldUseLuceneSearch()) {
363  $query_parser = new ilMailLuceneQueryParser($this->filter['mail_filter'] ?? '');
364  $query_parser->setFields([
365  'title' => (bool) ($this->filter['mail_filter_subject'] ?? false),
366  'content' => (bool) ($this->filter['mail_filter_body'] ?? false),
367  'mattachment' => (bool) ($this->filter['mail_filter_attach'] ?? false),
368  'msender' => (bool) ($this->filter['mail_filter_sender'] ?? false),
369  'mrcp' => (bool) ($this->filter['mail_filter_recipients'] ?? false)
370  ]);
371  $query_parser->parse();
372 
373  $result = new ilMailSearchResult();
374  $searcher = new ilMailLuceneSearcher($query_parser, $result);
375  $searcher->search($this->user->getId(), $this->_currentFolderId);
376 
377  if (!$result->getIds()) {
378  throw new ilMailException('mail_search_empty_result');
379  }
380 
381  ilMailBoxQuery::$filtered_ids = $result->getIds();
383  'mail_filter_only_unread' => $this->filter['mail_filter_only_unread'] ?? false,
384  'mail_filter_only_with_attachments' => $this->filter['mail_filter_only_with_attachments'] ?? false,
385  ];
386  } else {
388  }
389 
390  if (
391  isset(ilMailBoxQuery::$filter['mail_filter_only_unread']) &&
392  ($this->isDraftFolder() || $this->isSentFolder())
393  ) {
394  unset(ilMailBoxQuery::$filter['mail_filter_only_unread']);
395  }
396 
397  if (isset(ilMailBoxQuery::$filter['mail_filter_only_with_attachments']) && $this->isDraftFolder()) {
398  unset(ilMailBoxQuery::$filter['mail_filter_only_with_attachments']);
399  }
400 
401  $this->determineOffsetAndOrder();
402 
403  ilMailBoxQuery::$folderId = $this->_currentFolderId;
404  ilMailBoxQuery::$userId = $this->user->getId();
405  ilMailBoxQuery::$limit = $this->getLimit();
410 
411  if ($data['set'] === [] && $this->getOffset() > 0) {
412  $this->resetOffset();
413 
414  ilMailBoxQuery::$limit = $this->getLimit();
417  }
418  } catch (Exception $e) {
419  if ('mail_search_empty_result' === $e->getMessage()) {
420  $data['set'] = [];
421  $data['cnt'] = 0;
422  $data['cnt_unread'] = 0;
423  } else {
424  throw $e;
425  }
426  }
427 
428  if (!$this->isDraftFolder() && !$this->isSentFolder()) {
429  $user_ids = [];
430  foreach ($data['set'] as $mail) {
431  if ($mail['sender_id'] && $mail['sender_id'] !== ANONYMOUS_USER_ID) {
432  $user_ids[$mail['sender_id']] = $mail['sender_id'];
433  }
434  }
435 
437  }
438 
439 
440  foreach ($data['set'] as $key => $mail) {
441  if (is_array($this->getSelectedItems()) &&
442  in_array($mail['mail_id'], $this->getSelectedItems(), false)
443  ) {
444  $mail['checked'] = ' checked="checked" ';
445  }
446 
447  $mail['txt_select_mail_with_subject'] = sprintf(
448  $this->lng->txt('select_mail_with_subject_x'),
449  htmlspecialchars($mail['m_subject'] ?? '')
450  );
451 
452  if ($this->isDraftFolder() || $this->isSentFolder()) {
453  $mail['rcp_to'] = $mail['mail_login'] = ilUtil::htmlencodePlainString(
454  $this->_parentObject->umail->formatNamesForOutput((string) $mail['rcp_to']),
455  false
456  );
457  } elseif ($mail['sender_id'] === ANONYMOUS_USER_ID) {
458  $mail['img_sender'] = ilUtil::getImagePath('logo/HeaderIconAvatar.svg');
459  $mail['from'] =
460  $mail['mail_login'] =
461  $mail['alt_sender'] =
462  htmlspecialchars(ilMail::_getIliasMailerName());
463  } else {
464  $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
465 
466  if ($user !== null) {
467  $mail['img_sender'] = $user->getPersonalPicturePath('xxsmall');
468  $mail['from'] = $mail['mail_login'] = $mail['alt_sender'] = htmlspecialchars(
469  $user->getPublicName()
470  );
471  } else {
472  $mail['img_sender'] = '';
473  $mail['from'] = $mail['mail_login'] = trim(($mail['import_name'] ?? '') . ' ('
474  . $this->lng->txt('user_deleted') . ')');
475  }
476  }
477 
478  if ($this->isDraftFolder()) {
479  $this->ctrl->setParameterByClass(
480  ilMailFormGUI::class,
481  'mail_id',
482  $mail['mail_id']
483  );
484  $this->ctrl->setParameterByClass(
485  ilMailFormGUI::class,
486  'mobj_id',
487  $this->_currentFolderId
488  );
489  $this->ctrl->setParameterByClass(
490  ilMailFormGUI::class,
491  'type',
493  );
494  $link_mark_as_read = $this->ctrl->getLinkTargetByClass(ilMailFormGUI::class);
495  $this->ctrl->clearParametersByClass(ilMailFormGUI::class);
496  } else {
497  $this->ctrl->setParameter($this->getParentObject(), 'mail_id', $mail['mail_id']);
498  $this->ctrl->setParameter($this->getParentObject(), 'mobj_id', $this->_currentFolderId);
499  $link_mark_as_read = $this->ctrl->getLinkTarget($this->getParentObject(), 'showMail');
500  $this->ctrl->clearParameters($this->getParentObject());
501  }
502  $css_class = $mail['m_status'] === 'read' ? 'mailread' : 'mailunread';
503 
504  if ($result instanceof ilMailSearchResult) {
505  $search_result = [];
506  foreach ($result->getFields($mail['mail_id']) as $content) {
507  if ('title' === $content[0]) {
508  $mail['msr_subject_link_read'] = $link_mark_as_read;
509  $mail['msr_subject_mailclass'] = $css_class;
510  $mail['msr_subject'] = $content[1];
511  } else {
512  $search_result[] = $content[1];
513  }
514  }
515  $mail['msr_data'] = implode('', array_map(static function ($value): string {
516  return '<p>' . $value . '</p>';
517  }, $search_result));
518 
519  if (!isset($mail['msr_subject']) || !$mail['msr_subject']) {
520  $mail['msr_subject_link_read'] = $link_mark_as_read;
521  $mail['msr_subject_mailclass'] = $css_class;
522  $mail['msr_subject'] = htmlspecialchars($mail['m_subject'] ?? '');
523  }
524  $mail['msr_subject_read_unread'] = $mail['m_status'] === 'read' ? $this->lng->txt('mail_is_read') : $this->lng->txt('mail_is_unread');
525  } else {
526  $mail['mail_link_read'] = $link_mark_as_read;
527  $mail['mailclass'] = $css_class;
528  if ($mail['m_subject']) {
529  $mail['mail_subject'] = htmlspecialchars($mail['m_subject']);
530  } else {
531  $mail['mail_subject'] = $this->lng->txt('mail_no_subject');
532  }
533  $mail['mail_subject_read_unread'] = $mail['m_status'] === 'read' ? $this->lng->txt('mail_is_read') : $this->lng->txt('mail_is_unread');
534  }
535 
536  $mail['mail_date'] = ilDatePresentation::formatDate(
537  new ilDateTime($mail['send_time'], IL_CAL_DATETIME)
538  );
539 
540  $mail['attachment_indicator'] = '';
541  if (is_array($mail['attachments']) && $mail['attachments'] !== []) {
542  $this->ctrl->setParameter($this->getParentObject(), 'mail_id', (int) $mail['mail_id']);
543  if ($this->isDraftFolder()) {
544  $this->ctrl->setParameter($this->getParentObject(), 'type', ilMailFormGUI::MAIL_FORM_TYPE_DRAFT);
545  }
546  $this->ctrl->setParameter($this->getParentObject(), 'mobj_id', $this->_currentFolderId);
547  $mail['attachment_indicator'] = $this->uiRenderer->render(
548  $this->uiFactory->symbol()->glyph()->attachment(
549  $this->ctrl->getLinkTarget($this->getParentObject(), 'deliverAttachments')
550  )
551  );
552  $this->ctrl->clearParameters($this->getParentObject());
553  }
554 
555  $mail['actions'] = $this->formatActionsDropDown($mail);
556 
557  $data['set'][$key] = $mail;
558  }
559 
560  $this->setData($data['set']);
561  $this->setMaxCount((int) $data['cnt']);
562  $this->setNumberOfMails((int) $data['cnt']);
563 
564  $this->setTitleData($txt_folder, (int) $data['cnt'], (int) $data['cnt_unread'], $img_folder);
565 
566  return $this;
567  }
568 
572  protected function setTitleData(string $folderLabel, int $mailCount, int $unreadCount, string $imgFolder): self
573  {
574  $titleTemplate = new ilTemplate(
575  'tpl.mail_folder_title.html',
576  true,
577  true,
578  'Services/Mail'
579  );
580  $titleTemplate->setVariable('TXT_FOLDER', $folderLabel);
581  $titleTemplate->setVariable('MAIL_COUNT', $mailCount);
582  $titleTemplate->setVariable('TXT_MAIL_S', $this->lng->txt('mail_s'));
583  $titleTemplate->setVariable('MAIL_COUNT_UNREAD', $unreadCount);
584  $titleTemplate->setVariable('TXT_UNREAD', $this->lng->txt('unread'));
585 
586  $this->setTitle($titleTemplate->get(), $imgFolder);
587 
588  return $this;
589  }
590 
591  public function setNumberOfMails(int $a_number_of_mails): self
592  {
593  $this->_number_of_mails = $a_number_of_mails;
594 
595  return $this;
596  }
597 
598  public function getNumberOfMails(): int
599  {
601  }
602 
603  public function initFilter(): void
604  {
605  $this->filter = [];
606 
607  $quickFilter = new ilMailQuickFilterInputGUI($this->lng->txt('mail_filter'), 'mail_filter');
608  $quickFilter->setSubmitFormOnEnter(false);
609  $this->addFilterItem($quickFilter);
610  $quickFilter->readFromSession();
611  $this->filter['mail_filter'] = $quickFilter->getValue();
612 
613  if ($this->isDraftFolder() || $this->isSentFolder()) {
614  $this->sub_filter[] = $subFilterInRecipients = new ilCheckboxInputGUI(
615  $this->lng->txt('mail_filter_recipients'),
616  'mail_filter_recipients'
617  );
618  $subFilterInRecipients->setOptionTitle($this->lng->txt('mail_filter_recipients'));
619  $subFilterInRecipients->setValue('1');
620  $quickFilter->addSubItem($subFilterInRecipients);
621  $subFilterInRecipients->setParentTable($this);
622  $subFilterInRecipients->readFromSession();
623  $this->filter['mail_filter_recipients'] = (int) $subFilterInRecipients->getChecked();
624  } else {
625  $this->sub_filter[] = $subFilterInSender = new ilCheckboxInputGUI(
626  $this->lng->txt('mail_filter_sender'),
627  'mail_filter_sender'
628  );
629  $subFilterInSender->setOptionTitle($this->lng->txt('mail_filter_sender'));
630  $subFilterInSender->setValue('1');
631  $quickFilter->addSubItem($subFilterInSender);
632  $subFilterInSender->setParentTable($this);
633  $subFilterInSender->readFromSession();
634  $this->filter['mail_filter_sender'] = (int) $subFilterInSender->getChecked();
635  }
636 
637  $this->sub_filter[] = $subFilterInSubject = new ilCheckboxInputGUI(
638  $this->lng->txt('mail_filter_subject'),
639  'mail_filter_subject'
640  );
641  $subFilterInSubject->setOptionTitle($this->lng->txt('mail_filter_subject'));
642  $subFilterInSubject->setValue('1');
643  $quickFilter->addSubItem($subFilterInSubject);
644  $subFilterInSubject->setParentTable($this);
645  $subFilterInSubject->readFromSession();
646  $this->filter['mail_filter_subject'] = (int) $subFilterInSubject->getChecked();
647 
648  $this->sub_filter[] = $subFilterInBody = new ilCheckboxInputGUI(
649  $this->lng->txt('mail_filter_body'),
650  'mail_filter_body'
651  );
652  $subFilterInBody->setOptionTitle($this->lng->txt('mail_filter_body'));
653  $subFilterInBody->setValue('1');
654  $quickFilter->addSubItem($subFilterInBody);
655  $subFilterInBody->setParentTable($this);
656  $subFilterInBody->readFromSession();
657  $this->filter['mail_filter_body'] = (int) $subFilterInBody->getChecked();
658 
659  if ($this->isLuceneEnabled()) {
660  $this->sub_filter[] = $subFilterInAttachments = new ilCheckboxInputGUI(
661  $this->lng->txt('mail_filter_attach'),
662  'mail_filter_attach'
663  );
664  $subFilterInAttachments->setOptionTitle($this->lng->txt('mail_filter_attach'));
665  $subFilterInAttachments->setValue('1');
666  $quickFilter->addSubItem($subFilterInAttachments);
667  $subFilterInAttachments->setParentTable($this);
668  $subFilterInAttachments->readFromSession();
669  $this->filter['mail_filter_attach'] = (int) $subFilterInAttachments->getChecked();
670  }
671 
672  if (!$this->isDraftFolder() && !$this->isSentFolder()) {
673  $onlyUnread = new ilCheckboxInputGUI(
674  $this->lng->txt('mail_filter_only_unread'),
675  'mail_filter_only_unread'
676  );
677  $onlyUnread->setValue('1');
678  $this->addFilterItem($onlyUnread);
679  $onlyUnread->readFromSession();
680  $this->filter['mail_filter_only_unread'] = (int) $onlyUnread->getChecked();
681 
682  $onlyUserMails = new ilCheckboxInputGUI(
683  $this->lng->txt('mail_filter_only_user_mails'),
684  'mail_filter_only_user_mails'
685  );
686  $onlyUserMails->setValue('1');
687  $this->addFilterItem($onlyUserMails);
688  $onlyUserMails->readFromSession();
689  $this->filter['mail_filter_only_user_mails'] = (int) $onlyUserMails->getChecked();
690  }
691 
692  if (!$this->isDraftFolder()) {
693  $onlyWithAttachments = new ilCheckboxInputGUI(
694  $this->lng->txt('mail_filter_only_with_attachments'),
695  'mail_filter_only_with_attachments'
696  );
697  $onlyWithAttachments->setValue('1');
698  $this->addFilterItem($onlyWithAttachments);
699  $onlyWithAttachments->readFromSession();
700  $this->filter['mail_filter_only_with_attachments'] = (int) $onlyWithAttachments->getChecked();
701  }
702 
703  $duration = new ilDateDurationInputGUI($this->lng->txt('mail_filter_period'), 'period');
704  $duration->setAllowOpenIntervals(true);
705  $duration->setStartText($this->lng->txt('mail_filter_period_from'));
706  $duration->setEndText($this->lng->txt('mail_filter_period_until'));
707  $duration->setStart(new ilDateTime(null, IL_CAL_UNIX));
708  $duration->setEnd(new ilDateTime(null, IL_CAL_UNIX));
709  $duration->setShowTime(false);
710  $this->addFilterItem($duration);
711  $duration->readFromSession();
712  $this->filter['period'] = $duration->getValue();
713  }
714 
715  public function writeFilterToSession(): void
716  {
717  parent::writeFilterToSession();
718 
719  foreach ($this->sub_filter as $item) {
720  if ($item->checkInput()) {
721  $item->setValueByArray($this->http->request()->getParsedBody());
722  $item->writeToSession();
723  }
724  }
725  }
726 
727  public function resetFilter(): void
728  {
729  parent::resetFilter();
730 
731  foreach ($this->sub_filter as $item) {
732  if ($item->checkInput()) {
733  $item->setValueByArray($this->http->request()->getParsedBody());
734  $item->clearFromSession();
735  }
736  }
737  }
738 
739  protected function formatActionsDropDown(array $mail): string
740  {
741  $buttons = [];
742 
743  $this->addViewRowAction($mail, $buttons);
744  $this->addReplyRowAction($mail, $buttons);
745  $this->addForwardRowAction($mail, $buttons);
746  $this->addPrintRowAction($mail, $buttons);
747 
748  $dropDown = $this->uiFactory
749  ->dropdown()
750  ->standard($buttons)
751  ->withLabel($this->lng->txt('actions'));
752 
753  return $this->uiRenderer->render([$dropDown]);
754  }
755 
756  protected function addViewRowAction(array $mail, array &$buttons): void
757  {
758  if ($this->isDraftFolder()) {
759  $this->ctrl->setParameterByClass(
760  ilMailFormGUI::class,
761  'mail_id',
762  (int) $mail['mail_id']
763  );
764  $this->ctrl->setParameterByClass(
765  ilMailFormGUI::class,
766  'mobj_id',
767  $this->_currentFolderId
768  );
769  $this->ctrl->setParameterByClass(
770  ilMailFormGUI::class,
771  'type',
773  );
774  $viewButton = $this->uiFactory
775  ->link()
776  ->standard(
777  $this->lng->txt('view'),
778  $this->ctrl->getLinkTargetByClass(ilMailFormGUI::class)
779  );
780  $this->ctrl->clearParametersByClass(ilMailFormGUI::class);
781  } else {
782  $this->ctrl->setParameter($this->getParentObject(), 'mail_id', (int) $mail['mail_id']);
783  $this->ctrl->setParameter($this->getParentObject(), 'mobj_id', $this->_currentFolderId);
784  $viewButton = $this->uiFactory
785  ->link()
786  ->standard(
787  $this->lng->txt('view'),
788  $this->ctrl->getLinkTarget($this->getParentObject(), 'showMail')
789  );
790  $this->ctrl->clearParameters($this->getParentObject());
791  }
792 
793  $buttons[] = $viewButton;
794  }
795 
796  protected function addReplyRowAction(array $mail, array &$buttons): void
797  {
798  if (
799  isset($mail['sender_id']) && $mail['sender_id'] > 0 && $mail['sender_id'] !== ANONYMOUS_USER_ID &&
800  !$this->isDraftFolder()
801  ) {
802  $this->ctrl->setParameterByClass(
803  ilMailFormGUI::class,
804  'mobj_id',
805  $this->_currentFolderId
806  );
807  $this->ctrl->setParameterByClass(
808  ilMailFormGUI::class,
809  'mail_id',
810  (int) $mail['mail_id']
811  );
812  $this->ctrl->setParameterByClass(
813  ilMailFormGUI::class,
814  'type',
816  );
817  $replyButton = $this->uiFactory
818  ->link()
819  ->standard(
820  $this->lng->txt('reply'),
821  $this->ctrl->getLinkTargetByClass(ilMailFormGUI::class)
822  );
823  $this->ctrl->clearParametersByClass(ilMailFormGUI::class);
824 
825  $buttons[] = $replyButton;
826  }
827  }
828 
829  protected function addForwardRowAction(array $mail, array &$buttons): void
830  {
831  if (!$this->isDraftFolder()) {
832  $this->ctrl->setParameterByClass(
833  ilMailFormGUI::class,
834  'mobj_id',
835  $this->_currentFolderId
836  );
837  $this->ctrl->setParameterByClass(
838  ilMailFormGUI::class,
839  'mail_id',
840  (int) $mail['mail_id']
841  );
842  $this->ctrl->setParameterByClass(
843  ilMailFormGUI::class,
844  'type',
846  );
847  $forwardButton = $this->uiFactory
848  ->link()
849  ->standard(
850  $this->lng->txt('forward'),
851  $this->ctrl->getLinkTargetByClass(ilMailFormGUI::class)
852  );
853  $this->ctrl->clearParametersByClass(ilMailFormGUI::class);
854 
855  $buttons[] = $forwardButton;
856  }
857  }
858 
859  protected function addPrintRowAction(array $mail, array &$buttons): void
860  {
861  if (!$this->isDraftFolder()) {
862  $this->ctrl->setParameter($this->getParentObject(), 'mobj_id', $this->_currentFolderId);
863  $this->ctrl->setParameter($this->getParentObject(), 'mail_id', (int) $mail['mail_id']);
864  $printButton = $this->uiFactory
865  ->link()
866  ->standard(
867  $this->lng->txt('print'),
868  $this->ctrl->getLinkTarget($this->getParentObject(), 'printMail')
869  )->withOpenInNewViewport(true);
870  $this->ctrl->clearParameters($this->getParentObject());
871 
872  $buttons[] = $printButton;
873  }
874  }
875 
876  public function getHTML(): string
877  {
878  $this->ctrl->setParameter($this->getParentObject(), 'mobj_id', $this->_currentFolderId);
879  $html = parent::getHTML();
880  $this->ctrl->clearParameters($this->getParentObject());
881 
882  return $html;
883  }
884 }
setData(array $a_data)
Interface GlobalHttpState.
addForwardRowAction(array $mail, array &$buttons)
readonly GlobalHttpState $http
An entity that renders components to a string output.
Definition: Renderer.php:30
const IL_CAL_DATETIME
const ANONYMOUS_USER_ID
Definition: constants.php:27
static getUserObjectById(int $usr_id)
setFormAction(string $a_form_action, bool $a_multipart=false)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
addReplyRowAction(array $mail, array &$buttons)
final const MAIL_FORM_TYPE_DRAFT
setEnableTitle(bool $a_enabletitle)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setTitleData(string $folderLabel, int $mailCount, int $unreadCount, string $imgFolder)
setResetCommand(string $a_val, string $a_caption="")
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static string $orderDirection
static _getIliasMailerName()
const IL_CAL_UNIX
$duration
final const MAIL_FORM_TYPE_REPLY
getPublicName()
returns firstname lastname and login if profile is public, login otherwise
setId(string $a_val)
static string $orderColumn
static htmlencodePlainString(string $a_str, bool $a_make_links_clickable, bool $a_detect_goto_links=false)
Encodes a plain text string into HTML for display in a browser.
global $DIC
Definition: feed.php:28
addViewRowAction(array $mail, array &$buttons)
resetOffset(bool $a_in_determination=false)
setExternalSorting(bool $a_val)
static http()
Fetches the global http state from ILIAS.
__construct(VocabulariesInterface $vocabularies)
setDefaultOrderField(string $a_defaultorderfield)
__construct(protected ilMailFolderGUI $_parentObject, protected int $_currentFolderId, string $a_parent_cmd, protected bool $_isTrashFolder, protected bool $_isSentFolder, protected bool $_isDraftsFolder, Factory $uiFactory=null, Renderer $uiRenderer=null)
setSelectedItems(array $a_selected_items)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setFilterCommand(string $a_val, string $a_caption="")
static preloadUserObjects(array $usr_ids)
string $key
Consumer key/client ID value.
Definition: System.php:193
setDefaultOrderDirection(string $a_defaultorderdirection)
setNumberOfMails(int $a_number_of_mails)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
getPersonalPicturePath(string $a_size="small", bool $a_force_pic=false)
setSubmitFormOnEnter(bool $a_val)
final const MAIL_FORM_TYPE_FORWARD
addPrintRowAction(array $mail, array &$buttons)
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)
static array $filtered_ids
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
addMultiCommand(string $a_cmd, string $a_text)
determineOffsetAndOrder(bool $a_omit_offset=false)
setMaxCount(int $a_max_count)
set max.
setExternalSegmentation(bool $a_val)
getColumnDefinition(bool $use_cached_result=true)
setPrefix(string $a_prefix)