ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
MailFilterUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Mail\Folder;
22 
26 use ilLanguage;
28 use DateTimeZone;
29 
31 {
32  private readonly FilterComponent $filter;
33 
34  public function __construct(
35  private readonly string $target_url,
36  private readonly bool $lucene_enabled,
37  private readonly MailFolderData $folder,
38  private readonly Factory $ui_factory,
39  private readonly ilUIFilterService $filter_service,
40  private readonly ilLanguage $lng,
41  private readonly DateTimeZone $user_time_zone
42  ) {
43  $inputs = [];
44  if ($this->folder->hasIncomingMails()) {
45  $inputs['sender'] = $this->ui_factory->input()->field()->text($this->lng->txt('mail_filter_sender'));
46  } else {
47  $inputs['recipients'] = $this->ui_factory->input()->field()->text(
48  $this->lng->txt('mail_filter_recipients')
49  );
50  }
51 
52  $inputs['subject'] = $this->ui_factory->input()->field()->text($this->lng->txt('mail_filter_subject'));
53  $inputs['body'] = $this->ui_factory->input()->field()->text($this->lng->txt('mail_filter_body'));
54 
55  if ($this->lucene_enabled) {
56  $inputs['attachment'] = $this->ui_factory->input()->field()->text($this->lng->txt('mail_filter_attach'));
57  }
58 
59  $inputs['display'] = $this->ui_factory->input()->field()->multiSelect($this->lng->txt('mail_filter_display'), [
60  'read' => $this->lng->txt('mail_filter_show_read'),
61  'unread' => $this->lng->txt('mail_filter_show_unread'),
62  'user' => $this->lng->txt('mail_filter_show_user_mails'),
63  'system' => $this->lng->txt('mail_filter_show_system_mails'),
64  'with_attachment' => $this->lng->txt('mail_filter_show_with_attachments'),
65  'without_attachment' => $this->lng->txt('mail_filter_show_without_attachment')
66  ]);
67  $inputs['period'] = $this->ui_factory
68  ->input()->field()->duration($this->lng->txt('mail_filter_period'))
69  ->withTimezone($this->user_time_zone->getName());
70 
71  $this->filter = $this->filter_service->standard(
72  self::class,
73  $this->target_url,
74  //elements
75  $inputs,
76  // initially rendered
77  array_map(static fn($value): bool => true, $inputs),
78  false,
79  false
80  );
81  }
82 
86  public function getComponent(): FilterComponent
87  {
88  return $this->filter;
89  }
90 
94  public function getData(): MailFilterData
95  {
96  $data = $this->filter_service->getData($this->filter);
97 
98  $is_unread = null;
99  $is_system = null;
100  $has_attachment = null;
101 
102  // contrary filter options are only applied, if only one of them is set
103  if (\is_array($display = $data['display'] ?? null)) {
104  if (\in_array('read', $display, true) xor \in_array('unread', $display, true)) {
105  $is_unread = \in_array('unread', $display, true);
106  }
107  if (\in_array('system', $display, true) xor \in_array('user', $display, true)) {
108  $is_system = \in_array('system', $display, true);
109  }
110  if (\in_array('with_attachment', $display, true) xor \in_array('without_attachment', $display, true)) {
111  $has_attachment = \in_array('with_attachment', $display, true);
112  }
113  }
114 
115  $start = null;
116  if (($data['period'][0] ?? '') !== '') {
117  $start = new DateTimeImmutable($data['period'][0] . ' 00:00:00', $this->user_time_zone);
118  }
119  $end = null;
120  if (($data['period'][1] ?? '') !== '') {
121  $end = new DateTimeImmutable($data['period'][1] . ' 23:59:59', $this->user_time_zone);
122  }
123 
124  return new MailFilterData(
125  ($data['sender'] ?? '') === '' ? null : (string) $data['sender'],
126  ($data['recipients'] ?? '') === '' ? null : (string) $data['recipients'],
127  ($data['subject'] ?? '') === '' ? null : (string) $data['subject'],
128  ($data['body'] ?? '') === '' ? null : $data['body'],
129  ($data['attachment'] ?? '') === '' ? null : (string) $data['attachment'],
130  $start,
131  $end,
132  $is_unread,
133  $is_system,
134  $has_attachment
135  );
136  }
137 }
readonly FilterComponent $filter
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This is how the factory for UI elements looks.
Definition: Factory.php:37
getData()
Get the user entered filter data.
Filter data for display of mail records Properties with null value will not be applied as a filter...
getComponent()
Get the filter UI component.
global $lng
Definition: privfeed.php:31
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
__construct(private readonly string $target_url, private readonly bool $lucene_enabled, private readonly MailFolderData $folder, private readonly Factory $ui_factory, private readonly ilUIFilterService $filter_service, private readonly ilLanguage $lng, private readonly DateTimeZone $user_time_zone)