ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
OutboxDatabaseRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Mail\Folder;
22
23use Generator;
24use DateTimeZone;
28use DateTimeImmutable;
30use ilMail;
31
32readonly class OutboxDatabaseRepository implements OutboxRepository
33{
34 public function __construct(
35 private ilDBInterface $db,
36 private ClockFactory $clock,
37 private ilMail $mail,
38 ) {
39 }
40
44 public function getOutboxMails(): Generator
45 {
46 $res = $this->db->queryF(
47 <<<'SQL'
48 SELECT
49 mail_id,
50 rcp_to,
51 rcp_cc,
52 rcp_bcc,
53 m_subject,
54 m_message,
55 attachments,
56 use_placeholders,
57 schedule_datetime,
58 schedule_timezone
59 FROM mail
60 INNER JOIN mail_obj_data ON mail.folder_id = mail_obj_data.obj_id AND mail.user_id = mail_obj_data.user_id
61 WHERE mail_obj_data.m_type = %s
62 AND schedule_datetime IS NOT NULL
63 SQL,
66 );
67 $current_time = $this->clock->utc()->now();
68
69 while ($row = $this->mail->fetchMailData($this->db->fetchAssoc($res))) {
70 $schedule_datetime = new DateTimeImmutable(
71 $row['schedule_datetime'],
72 new DateTimeZone($row['schedule_timezone'])
73 );
74 if ($schedule_datetime <= $current_time) {
75 yield new MailDeliveryData(
76 $row['rcp_to'],
77 $row['rcp_cc'],
78 $row['rcp_bcc'],
79 $row['m_subject'],
80 $row['m_message'],
81 $row['attachments'],
82 (bool) ($row['use_placeholders'] ?? false),
83 isset($row['mail_id']) ? (int) $row['mail_id'] : null
84 );
85 }
86 }
87 }
88}
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
Class ilDBConstants.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69