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