ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ILIAS\Mail\Message\MailBoxQuery Class Reference
+ Collaboration diagram for ILIAS\Mail\Message\MailBoxQuery:

Public Member Functions

 __construct (private readonly int $user_id,)
 
 withFolderId (?int $folder_id)
 
 withSender (?string $sender)
 
 withRecipients (?string $recipients)
 
 withSubject (?string $subject)
 
 withBody (?string $body)
 
 withIsUnread (?bool $is_unread)
 
 withIsSystem (?bool $is_system)
 
 withHasAttachment (?bool $has_attachment)
 
 withPeriodStart (?DateTimeImmutable $period_start)
 
 withPeriodEnd (?DateTimeImmutable $period_end)
 
 withFilteredIds (?array $filtered_ids)
 
 withLimit (int $limit)
 
 withOffset (int $offset)
 
 withOrderColumn (?MailBoxOrderColumn $order_column)
 
 withOrderDirection (?string $order_direction)
 
 countUnread ()
 Count the number of unread mails with applied filter. More...
 
 count ()
 Count the number of all mails with applied filter. More...
 
 queryMailIds ()
 Get a list of mail ids. More...
 
 query ($short)
 Query for mail data with applied filter. More...
 

Private Member Functions

 getFrom ()
 
 getWhere ()
 

Private Attributes

const MailBoxOrderColumn DEFAULT_ORDER_COLUMN = MailBoxOrderColumn::SEND_TIME
 
const string DEFAULT_ORDER_DIRECTION = Order::ASC
 
ilDBInterface $db
 
int $folder_id = null
 
string $sender = null
 
string $recipients = null
 
string $subject = null
 
string $body = null
 
bool $is_unread = null
 
bool $is_system = null
 
bool $has_attachment = null
 
DateTimeImmutable $period_start = null
 
DateTimeImmutable $period_end = null
 
array $filtered_ids = null
 
int $limit = 999999
 
int $offset = 0
 
MailBoxOrderColumn $order_column = self::DEFAULT_ORDER_COLUMN
 
string $order_direction = self::DEFAULT_ORDER_DIRECTION
 

Detailed Description

Definition at line 31 of file MailBoxQuery.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Mail\Message\MailBoxQuery::__construct ( private readonly int  $user_id)

Definition at line 54 of file MailBoxQuery.php.

56 {
57 global $DIC;
58 $this->db = $DIC->database();
59 }
global $DIC
Definition: shib_login.php:26

References $DIC.

Member Function Documentation

◆ count()

ILIAS\Mail\Message\MailBoxQuery::count ( )

Count the number of all mails with applied filter.

Definition at line 203 of file MailBoxQuery.php.

203 : int
204 {
205 if ($this->filtered_ids === []) {
206 return 0;
207 }
208
209 $query = 'SELECT COUNT(m.mail_id) cnt '
210 . $this->getFrom()
211 . $this->getWhere();
212
213 $res = $this->db->query($query);
214 if ($row = $this->db->fetchAssoc($res)) {
215 return (int) $row['cnt'];
216 }
217
218 return 0;
219 }
$res
Definition: ltiservices.php:69

References $res, ILIAS\Mail\Message\MailBoxQuery\getFrom(), and ILIAS\Mail\Message\MailBoxQuery\getWhere().

+ Here is the call graph for this function:

◆ countUnread()

ILIAS\Mail\Message\MailBoxQuery::countUnread ( )

Count the number of unread mails with applied filter.

Definition at line 195 of file MailBoxQuery.php.

195 : int
196 {
197 return $this->withIsUnread(true)->count();
198 }

References ILIAS\Mail\Message\MailBoxQuery\withIsUnread().

+ Here is the call graph for this function:

◆ getFrom()

ILIAS\Mail\Message\MailBoxQuery::getFrom ( )
private

Definition at line 313 of file MailBoxQuery.php.

314 {
315 return " FROM mail m
316 LEFT JOIN usr_data u ON u.usr_id = m.sender_id
317 LEFT JOIN usr_pref p ON p.usr_id = m.sender_id AND p.keyword = 'public_profile'";
318 }

Referenced by ILIAS\Mail\Message\MailBoxQuery\count(), ILIAS\Mail\Message\MailBoxQuery\query(), and ILIAS\Mail\Message\MailBoxQuery\queryMailIds().

+ Here is the caller graph for this function:

◆ getWhere()

ILIAS\Mail\Message\MailBoxQuery::getWhere ( )
private

Definition at line 320 of file MailBoxQuery.php.

320 : string
321 {
322 $parts = [];
323
324 // minimum condition: only mailbox of the given user
325 $parts[] = 'm.user_id = ' . $this->db->quote($this->user_id, ilDBConstants::T_INTEGER);
326
327 // sender conditions have to respect searchability and visibility of profile fields
328 $sender_conditions = [];
329 if (($this->sender ?? '') !== '') {
330 $sender_conditions[] = $this->db->like('u.login', ilDBConstants::T_TEXT, '%%' . $this->sender . '%%');
331
332 if (ilUserSearchOptions::_isEnabled('firstname')) {
333 $sender_conditions[] = '(' .
334 $this->db->like('u.firstname', ilDBConstants::T_TEXT, '%%' . $this->sender . '%%')
335 . " AND p.value = 'y')";
336 }
337
338 if (ilUserSearchOptions::_isEnabled('lastname')) {
339 $sender_conditions[] = '(' .
340 $this->db->like('u.lastname', ilDBConstants::T_TEXT, '%%' . $this->sender . '%%')
341 . " AND p.value = 'y')";
342 }
343 }
344 if (!empty($sender_conditions)) {
345 $parts[] = '(' . implode(' OR ', $sender_conditions) . ')';
346 }
347
348 // other text conditions
349 $text_conditions = [
350 [$this->recipients, 'CONCAT(CONCAT(m.rcp_to, m.rcp_cc), m.rcp_bcc)'],
351 [$this->subject, 'm.m_subject'],
352 [$this->body, 'm.m_message'],
353 ];
354
355 foreach ($text_conditions as $cond) {
356 if (($cond[0] ?? '') !== '') {
357 $parts[] = $this->db->like(
358 $cond[1],
360 '%%' . $cond[0] . '%%',
361 false
362 );
363 }
364 }
365
366 if ($this->folder_id !== null) {
367 $parts[] = 'm.folder_id = ' . $this->db->quote($this->folder_id, ilDBConstants::T_INTEGER);
368 }
369
370 if ($this->is_unread === true) {
371 $parts[] = 'm.m_status = ' . $this->db->quote('unread', 'text');
372 } elseif ($this->is_unread === false) {
373 $parts[] = 'm.m_status != ' . $this->db->quote('unread', 'text');
374 }
375
376 if ($this->is_system === true) {
377 $parts[] = 'm.sender_id = ' . $this->db->quote(ANONYMOUS_USER_ID, ilDBConstants::T_INTEGER);
378 } elseif ($this->is_system === false) {
379 $parts[] = 'm.sender_id != ' . $this->db->quote(ANONYMOUS_USER_ID, ilDBConstants::T_INTEGER);
380 }
381
382 if ($this->has_attachment === true) {
383 $parts[] = '(m.attachments != ' . $this->db->quote(serialize(null), ilDBConstants::T_TEXT)
384 . ' AND m.attachments != ' . $this->db->quote(serialize([]), ilDBConstants::T_TEXT) . ')';
385 } elseif ($this->has_attachment === false) {
386 $parts[] = '(m.attachments = ' . $this->db->quote(serialize(null), ilDBConstants::T_TEXT)
387 . ' OR m.attachments = ' . $this->db->quote(serialize([]), ilDBConstants::T_TEXT) . ')';
388 }
389
390 if ($this->period_start !== null) {
391 $parts[] = 'm.send_time >= ' . $this->db->quote(
392 // convert to server time zone (set by ilias initialisation)
393 $this->period_start
394 ->setTimezone(new DateTimeZone(date_default_timezone_get()))
395 ->format('Y-m-d H:i:s'),
397 );
398 }
399
400 if ($this->period_end !== null) {
401 $parts[] = 'm.send_time <= ' . $this->db->quote(
402 // convert to server time zone (set by ilias initialisation)
403 $this->period_end
404 ->setTimezone(new DateTimeZone(date_default_timezone_get()))
405 ->format('Y-m-d H:i:s'),
407 );
408 }
409
410 if (!empty($this->filtered_ids)) {
411 $parts[] = $this->db->in(
412 'm.mail_id',
413 $this->filtered_ids,
414 false,
416 ) . ' ';
417 }
418
419 if ($parts !== []) {
420 return ' WHERE ' . implode(' AND ', $parts);
421 }
422
423 return '';
424 }
const ANONYMOUS_USER_ID
Definition: constants.php:27
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61

References ILIAS\Mail\Message\MailBoxQuery\$body, $parts, ILIAS\Mail\Message\MailBoxQuery\$recipients, ILIAS\Mail\Message\MailBoxQuery\$subject, ANONYMOUS_USER_ID, ilDBConstants\T_INTEGER, ilDBConstants\T_TEXT, and ilDBConstants\T_TIMESTAMP.

Referenced by ILIAS\Mail\Message\MailBoxQuery\count(), ILIAS\Mail\Message\MailBoxQuery\query(), and ILIAS\Mail\Message\MailBoxQuery\queryMailIds().

+ Here is the caller graph for this function:

◆ query()

ILIAS\Mail\Message\MailBoxQuery::query (   $short)

Query for mail data with applied filter.

Parameters
bool$shortget only data that is needed for a listing
Returns
list<MailRecordData>

Definition at line 249 of file MailBoxQuery.php.

249 : array
250 {
251 if ($this->filtered_ids === []) {
252 return [];
253 }
254
255 if ($short) {
256 $query = 'SELECT m.mail_id, m.user_id, m.folder_id, m.sender_id, m.send_time, '
257 . 'm.m_status, m.m_subject, m.import_name, m.rcp_to, m.attachments'
258 . $this->getFrom()
259 . $this->getWhere();
260 } else {
261 $query = 'SELECT m.*'
262 . $this->getFrom()
263 . $this->getWhere();
264 }
265
266 if ($this->order_column === MailBoxOrderColumn::FROM) {
267 $query .= ' ORDER BY '
268 . ' u.firstname ' . $this->order_direction . ', '
269 . ' u.lastname ' . $this->order_direction . ', '
270 . ' u.login ' . $this->order_direction . ', '
271 . ' m.import_name ' . $this->order_direction;
272 } else {
273 $query .= ' ORDER BY ' . $this->order_column->value . ' ' . $this->order_direction;
274 }
275
276 $this->db->setLimit($this->limit, $this->offset);
277 $res = $this->db->query($query);
278
279 $set = [];
280 while ($row = $this->db->fetchAssoc($res)) {
281 if (isset($row['attachments']) && \is_string($row['attachments']) && str_contains($row['attachments'], '{')) {
282 $unserialized_attachments = unserialize($row['attachments'], ['allowed_classes' => false]);
283 $row['attachments'] = \is_array($unserialized_attachments) ? $unserialized_attachments : null;
284 } elseif (isset($row['attachments']) && \is_string($row['attachments']) && $row['attachments'] !== '') {
285 $row['attachments'] = new ResourceCollectionIdentification($row['attachments']);
286 } else {
287 $row['attachments'] = null;
288 }
289
290 $set[] = new MailRecordData(
291 isset($row['mail_id']) ? (int) $row['mail_id'] : 0,
292 isset($row['user_id']) ? (int) $row['user_id'] : 0,
293 isset($row['folder_id']) ? (int) $row['folder_id'] : 0,
294 isset($row['sender_id']) ? (int) $row['sender_id'] : null,
295 isset($row['send_time']) ? new DateTimeImmutable($row['send_time']) : null,
296 isset($row['m_status']) ? (string) $row['m_status'] : null,
297 isset($row['m_subject']) ? (string) $row['m_subject'] : null,
298 isset($row['import_name']) ? (string) $row['import_name'] : null,
299 isset($row['use_placeholders']) ? (bool) $row['use_placeholders'] : false,
300 isset($row['m_message']) ? (string) $row['m_message'] : null,
301 isset($row['rcp_to']) ? (string) $row['rcp_to'] : null,
302 isset($row['rcp_cc']) ? (string) $row['rcp_cc'] : null,
303 isset($row['rcp_bcc']) ? (string) $row['rcp_bcc'] : null,
304 $row['attachments'],
305 isset($row['tpl_ctx_id']) ? (string) $row['tpl_ctx_id'] : null,
306 isset($row['tpl_ctx_params']) ? (string) $row['tpl_ctx_params'] : null
307 );
308 }
309
310 return $set;
311 }

References ILIAS\Mail\Message\MailBoxQuery\$order_direction, $res, ILIAS\Mail\Message\MailBoxQuery\getFrom(), and ILIAS\Mail\Message\MailBoxQuery\getWhere().

+ Here is the call graph for this function:

◆ queryMailIds()

ILIAS\Mail\Message\MailBoxQuery::queryMailIds ( )

Get a list of mail ids.

Returns
int[]

Definition at line 225 of file MailBoxQuery.php.

225 : array
226 {
227 if ($this->filtered_ids === []) {
228 return [];
229 }
230
231 $query = 'SELECT m.mail_id '
232 . $this->getFrom()
233 . $this->getWhere();
234
235 $ids = [];
236 $res = $this->db->query($query);
237 while ($row = $this->db->fetchAssoc($res)) {
238 $ids[] = (int) $row['mail_id'];
239 }
240
241 return $ids;
242 }

References $res, ILIAS\Mail\Message\MailBoxQuery\getFrom(), ILIAS\Mail\Message\MailBoxQuery\getWhere(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ withBody()

ILIAS\Mail\Message\MailBoxQuery::withBody ( ?string  $body)

Definition at line 93 of file MailBoxQuery.php.

93 : MailBoxQuery
94 {
95 $clone = clone $this;
96 $clone->body = $body;
97
98 return $clone;
99 }

References ILIAS\Mail\Message\MailBoxQuery\$body.

◆ withFilteredIds()

ILIAS\Mail\Message\MailBoxQuery::withFilteredIds ( ?array  $filtered_ids)
Parameters
int[] | null$filtered_ids

Definition at line 144 of file MailBoxQuery.php.

144 : MailBoxQuery
145 {
146 $clone = clone $this;
147 $clone->filtered_ids = $filtered_ids;
148
149 return $clone;
150 }

References ILIAS\Mail\Message\MailBoxQuery\$filtered_ids.

◆ withFolderId()

ILIAS\Mail\Message\MailBoxQuery::withFolderId ( ?int  $folder_id)

Definition at line 61 of file MailBoxQuery.php.

61 : MailBoxQuery
62 {
63 $clone = clone $this;
64 $clone->folder_id = $folder_id;
65
66 return $clone;
67 }

References ILIAS\Mail\Message\MailBoxQuery\$folder_id.

◆ withHasAttachment()

ILIAS\Mail\Message\MailBoxQuery::withHasAttachment ( ?bool  $has_attachment)

Definition at line 117 of file MailBoxQuery.php.

117 : MailBoxQuery
118 {
119 $clone = clone $this;
120 $clone->has_attachment = $has_attachment;
121
122 return $clone;
123 }

References ILIAS\Mail\Message\MailBoxQuery\$has_attachment.

◆ withIsSystem()

ILIAS\Mail\Message\MailBoxQuery::withIsSystem ( ?bool  $is_system)

Definition at line 109 of file MailBoxQuery.php.

109 : MailBoxQuery
110 {
111 $clone = clone $this;
112 $clone->is_system = $is_system;
113
114 return $clone;
115 }

References ILIAS\Mail\Message\MailBoxQuery\$is_system.

◆ withIsUnread()

ILIAS\Mail\Message\MailBoxQuery::withIsUnread ( ?bool  $is_unread)

Definition at line 101 of file MailBoxQuery.php.

101 : MailBoxQuery
102 {
103 $clone = clone $this;
104 $clone->is_unread = $is_unread;
105
106 return $clone;
107 }

References ILIAS\Mail\Message\MailBoxQuery\$is_unread.

Referenced by ILIAS\Mail\Message\MailBoxQuery\countUnread().

+ Here is the caller graph for this function:

◆ withLimit()

ILIAS\Mail\Message\MailBoxQuery::withLimit ( int  $limit)

Definition at line 152 of file MailBoxQuery.php.

152 : MailBoxQuery
153 {
154 $clone = clone $this;
155 $clone->limit = $limit;
156
157 return $clone;
158 }

References ILIAS\Mail\Message\MailBoxQuery\$limit.

◆ withOffset()

ILIAS\Mail\Message\MailBoxQuery::withOffset ( int  $offset)

Definition at line 160 of file MailBoxQuery.php.

160 : MailBoxQuery
161 {
162 $clone = clone $this;
163 $clone->offset = $offset;
164
165 return $clone;
166 }

References ILIAS\Mail\Message\MailBoxQuery\$offset.

◆ withOrderColumn()

ILIAS\Mail\Message\MailBoxQuery::withOrderColumn ( ?MailBoxOrderColumn  $order_column)

Definition at line 168 of file MailBoxQuery.php.

168 : MailBoxQuery
169 {
170 $clone = clone $this;
171 if ($order_column !== null) {
172 $clone->order_column = $order_column;
173 } else {
174 $clone->order_column = self::DEFAULT_ORDER_COLUMN;
175 }
176
177 return $clone;
178 }
const MailBoxOrderColumn DEFAULT_ORDER_COLUMN
MailBoxOrderColumn $order_column

References ILIAS\Mail\Message\MailBoxQuery\$order_column, and ILIAS\Mail\Message\MailBoxQuery\DEFAULT_ORDER_COLUMN.

◆ withOrderDirection()

ILIAS\Mail\Message\MailBoxQuery::withOrderDirection ( ?string  $order_direction)

Definition at line 180 of file MailBoxQuery.php.

180 : MailBoxQuery
181 {
182 $clone = clone $this;
183 if (\in_array($order_direction, [Order::ASC, Order::DESC], true)) {
184 $clone->order_direction = $order_direction;
185 } else {
186 $clone->order_direction = self::DEFAULT_ORDER_DIRECTION;
187 }
188
189 return $clone;
190 }
const DESC
Definition: Order.php:31

References ILIAS\Mail\Message\MailBoxQuery\$order_direction, ILIAS\Data\Order\ASC, ILIAS\Mail\Message\MailBoxQuery\DEFAULT_ORDER_DIRECTION, and ILIAS\Data\Order\DESC.

◆ withPeriodEnd()

ILIAS\Mail\Message\MailBoxQuery::withPeriodEnd ( ?DateTimeImmutable  $period_end)

Definition at line 133 of file MailBoxQuery.php.

133 : MailBoxQuery
134 {
135 $clone = clone $this;
136 $clone->period_end = $period_end;
137
138 return $clone;
139 }

References ILIAS\Mail\Message\MailBoxQuery\$period_end.

◆ withPeriodStart()

ILIAS\Mail\Message\MailBoxQuery::withPeriodStart ( ?DateTimeImmutable  $period_start)

Definition at line 125 of file MailBoxQuery.php.

125 : MailBoxQuery
126 {
127 $clone = clone $this;
128 $clone->period_start = $period_start;
129
130 return $clone;
131 }
DateTimeImmutable $period_start

References ILIAS\Mail\Message\MailBoxQuery\$period_start.

◆ withRecipients()

ILIAS\Mail\Message\MailBoxQuery::withRecipients ( ?string  $recipients)

Definition at line 77 of file MailBoxQuery.php.

77 : MailBoxQuery
78 {
79 $clone = clone $this;
80 $clone->recipients = $recipients;
81
82 return $clone;
83 }

References ILIAS\Mail\Message\MailBoxQuery\$recipients.

◆ withSender()

ILIAS\Mail\Message\MailBoxQuery::withSender ( ?string  $sender)

Definition at line 69 of file MailBoxQuery.php.

69 : MailBoxQuery
70 {
71 $clone = clone $this;
72 $clone->sender = $sender;
73
74 return $clone;
75 }

References ILIAS\Mail\Message\MailBoxQuery\$sender.

◆ withSubject()

ILIAS\Mail\Message\MailBoxQuery::withSubject ( ?string  $subject)

Definition at line 85 of file MailBoxQuery.php.

85 : MailBoxQuery
86 {
87 $clone = clone $this;
88 $clone->subject = $subject;
89
90 return $clone;
91 }

References ILIAS\Mail\Message\MailBoxQuery\$subject.

Field Documentation

◆ $body

string ILIAS\Mail\Message\MailBoxQuery::$body = null
private

◆ $db

ilDBInterface ILIAS\Mail\Message\MailBoxQuery::$db
private

Definition at line 36 of file MailBoxQuery.php.

◆ $filtered_ids

array ILIAS\Mail\Message\MailBoxQuery::$filtered_ids = null
private

Definition at line 48 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withFilteredIds().

◆ $folder_id

int ILIAS\Mail\Message\MailBoxQuery::$folder_id = null
private

Definition at line 37 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withFolderId().

◆ $has_attachment

bool ILIAS\Mail\Message\MailBoxQuery::$has_attachment = null
private

Definition at line 44 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withHasAttachment().

◆ $is_system

bool ILIAS\Mail\Message\MailBoxQuery::$is_system = null
private

Definition at line 43 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withIsSystem().

◆ $is_unread

bool ILIAS\Mail\Message\MailBoxQuery::$is_unread = null
private

Definition at line 42 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withIsUnread().

◆ $limit

int ILIAS\Mail\Message\MailBoxQuery::$limit = 999999
private

Definition at line 49 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withLimit().

◆ $offset

int ILIAS\Mail\Message\MailBoxQuery::$offset = 0
private

Definition at line 50 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withOffset().

◆ $order_column

MailBoxOrderColumn ILIAS\Mail\Message\MailBoxQuery::$order_column = self::DEFAULT_ORDER_COLUMN
private

Definition at line 51 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withOrderColumn().

◆ $order_direction

string ILIAS\Mail\Message\MailBoxQuery::$order_direction = self::DEFAULT_ORDER_DIRECTION
private

◆ $period_end

DateTimeImmutable ILIAS\Mail\Message\MailBoxQuery::$period_end = null
private

Definition at line 46 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withPeriodEnd().

◆ $period_start

DateTimeImmutable ILIAS\Mail\Message\MailBoxQuery::$period_start = null
private

Definition at line 45 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withPeriodStart().

◆ $recipients

string ILIAS\Mail\Message\MailBoxQuery::$recipients = null
private

◆ $sender

string ILIAS\Mail\Message\MailBoxQuery::$sender = null
private

Definition at line 38 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withSender().

◆ $subject

string ILIAS\Mail\Message\MailBoxQuery::$subject = null
private

◆ DEFAULT_ORDER_COLUMN

const MailBoxOrderColumn ILIAS\Mail\Message\MailBoxQuery::DEFAULT_ORDER_COLUMN = MailBoxOrderColumn::SEND_TIME
private

Definition at line 33 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withOrderColumn().

◆ DEFAULT_ORDER_DIRECTION

const string ILIAS\Mail\Message\MailBoxQuery::DEFAULT_ORDER_DIRECTION = Order::ASC
private

Definition at line 34 of file MailBoxQuery.php.

Referenced by ILIAS\Mail\Message\MailBoxQuery\withOrderDirection().


The documentation for this class was generated from the following file: