19 declare(strict_types=1);
57 $this->db = $DIC->database();
102 $clone = clone $this;
110 $clone = clone $this;
118 $clone = clone $this;
126 $clone = clone $this;
134 $clone = clone $this;
145 $clone = clone $this;
153 $clone = clone $this;
161 $clone = clone $this;
169 $clone = clone $this;
170 if ($order_column !==
null) {
173 $clone->order_column = self::DEFAULT_ORDER_COLUMN;
181 $clone = clone $this;
185 $clone->order_direction = self::DEFAULT_ORDER_DIRECTION;
204 if ($this->filtered_ids === []) {
208 $query =
'SELECT COUNT(m.mail_id) cnt ' 212 $res = $this->db->query($query);
213 if ($row = $this->db->fetchAssoc(
$res)) {
214 return (
int) $row[
'cnt'];
226 if ($this->filtered_ids === []) {
230 $query =
'SELECT m.mail_id ' 235 $res = $this->db->query($query);
236 while ($row = $this->db->fetchAssoc(
$res)) {
237 $ids[] = (
int) $row[
'mail_id'];
248 public function query($short): array
250 if ($this->filtered_ids === []) {
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' 260 $query =
'SELECT m.*' 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 .
', ' 275 $this->db->setLimit($this->limit, $this->offset);
276 $res = $this->db->query($query);
279 while ($row = $this->db->fetchAssoc(
$res)) {
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,
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]
298 isset($row[
'tpl_ctx_id']) ? (
string) $row[
'tpl_ctx_id'] : null,
299 isset($row[
'tpl_ctx_params']) ? (
string) $row[
'tpl_ctx_params'] : null
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'";
321 $sender_conditions = [];
322 if (($this->sender ??
'') !==
'') {
323 $sender_conditions[] = $this->db->like(
'u.login',
ilDBConstants::T_TEXT,
'%%' . $this->sender .
'%%');
326 $sender_conditions[] =
'(' .
328 .
" AND p.value = 'y')";
332 $sender_conditions[] =
'(' .
334 .
" AND p.value = 'y')";
337 if (!empty($sender_conditions)) {
338 $parts[] =
'(' . implode(
' OR ', $sender_conditions) .
')';
348 foreach ($text_conditions as $cond) {
349 if (($cond[0] ??
'') !==
'') {
350 $parts[] = $this->db->like(
353 '%%' . $cond[0] .
'%%',
359 if ($this->folder_id !==
null) {
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');
369 if ($this->is_system ===
true) {
371 } elseif ($this->is_system ===
false) {
375 if ($this->has_attachment ===
true) {
378 } elseif ($this->has_attachment ===
false) {
383 if ($this->period_start !==
null) {
384 $parts[] =
'm.send_time >= ' . $this->db->quote(
387 ->setTimezone(
new DateTimeZone(date_default_timezone_get()))
388 ->format(
'Y-m-d H:i:s'),
393 if ($this->period_end !==
null) {
394 $parts[] =
'm.send_time <= ' . $this->db->quote(
397 ->setTimezone(
new DateTimeZone(date_default_timezone_get()))
398 ->format(
'Y-m-d H:i:s'),
403 if (!empty($this->filtered_ids)) {
413 return ' WHERE ' . implode(
' AND ',
$parts);
withIsSystem(?bool $is_system)
DateTimeImmutable $period_end
withHasAttachment(?bool $has_attachment)
const MailBoxOrderColumn DEFAULT_ORDER_COLUMN
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
withFilteredIds(?array $filtered_ids)
MailBoxOrderColumn $order_column
countUnread()
Count the number of unread mails with applied filter.
queryMailIds()
Get a list of mail ids.
DateTimeImmutable $period_start
withOrderColumn(?MailBoxOrderColumn $order_column)
__construct(private readonly int $user_id,)
withOrderDirection(?string $order_direction)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
withSender(?string $sender)
withPeriodEnd(?DateTimeImmutable $period_end)
count()
Count the number of all mails with applied filter.
withFolderId(?int $folder_id)
withRecipients(?string $recipients)
withPeriodStart(?DateTimeImmutable $period_start)
withSubject(?string $subject)
const string DEFAULT_ORDER_DIRECTION
static _isEnabled($a_key)
query($short)
Query for mail data with applied filter.
withIsUnread(?bool $is_unread)