ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 30 of file MailBoxQuery.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 53 of file MailBoxQuery.php.

55 {
56 global $DIC;
57 $this->db = $DIC->database();
58 }
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 202 of file MailBoxQuery.php.

202 : int
203 {
204 if ($this->filtered_ids === []) {
205 return 0;
206 }
207
208 $query = 'SELECT COUNT(m.mail_id) cnt '
209 . $this->getFrom()
210 . $this->getWhere();
211
212 $res = $this->db->query($query);
213 if ($row = $this->db->fetchAssoc($res)) {
214 return (int) $row['cnt'];
215 }
216
217 return 0;
218 }
$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 194 of file MailBoxQuery.php.

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

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

+ Here is the call graph for this function:

◆ getFrom()

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

Definition at line 306 of file MailBoxQuery.php.

307 {
308 return " FROM mail m
309 LEFT JOIN usr_data u ON u.usr_id = m.sender_id
310 LEFT JOIN usr_pref p ON p.usr_id = m.sender_id AND p.keyword = 'public_profile'";
311 }

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 313 of file MailBoxQuery.php.

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

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

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 224 of file MailBoxQuery.php.

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

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 92 of file MailBoxQuery.php.

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

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

◆ withFilteredIds()

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

Definition at line 143 of file MailBoxQuery.php.

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

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

◆ withFolderId()

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

Definition at line 60 of file MailBoxQuery.php.

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

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

◆ withHasAttachment()

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

Definition at line 116 of file MailBoxQuery.php.

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

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

◆ withIsSystem()

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

Definition at line 108 of file MailBoxQuery.php.

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

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

◆ withIsUnread()

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

Definition at line 100 of file MailBoxQuery.php.

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

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 151 of file MailBoxQuery.php.

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

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

◆ withOffset()

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

Definition at line 159 of file MailBoxQuery.php.

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

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

◆ withOrderColumn()

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

Definition at line 167 of file MailBoxQuery.php.

167 : MailBoxQuery
168 {
169 $clone = clone $this;
170 if ($order_column !== null) {
171 $clone->order_column = $order_column;
172 } else {
173 $clone->order_column = self::DEFAULT_ORDER_COLUMN;
174 }
175
176 return $clone;
177 }
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 179 of file MailBoxQuery.php.

179 : MailBoxQuery
180 {
181 $clone = clone $this;
182 if (\in_array($order_direction, [Order::ASC, Order::DESC], true)) {
183 $clone->order_direction = $order_direction;
184 } else {
185 $clone->order_direction = self::DEFAULT_ORDER_DIRECTION;
186 }
187
188 return $clone;
189 }
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 132 of file MailBoxQuery.php.

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

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

◆ withPeriodStart()

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

Definition at line 124 of file MailBoxQuery.php.

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

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

◆ withRecipients()

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

Definition at line 76 of file MailBoxQuery.php.

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

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

◆ withSender()

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

Definition at line 68 of file MailBoxQuery.php.

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

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

◆ withSubject()

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

Definition at line 84 of file MailBoxQuery.php.

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

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 35 of file MailBoxQuery.php.

◆ $filtered_ids

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

Definition at line 47 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 36 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 43 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 42 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 41 of file MailBoxQuery.php.

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

◆ $limit

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

Definition at line 48 of file MailBoxQuery.php.

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

◆ $offset

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

Definition at line 49 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 50 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 45 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 44 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 37 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 32 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 33 of file MailBoxQuery.php.

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


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