ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Mail\Autoresponder\AutoresponderServiceImpl Class Reference
+ Inheritance diagram for ILIAS\Mail\Autoresponder\AutoresponderServiceImpl:
+ Collaboration diagram for ILIAS\Mail\Autoresponder\AutoresponderServiceImpl:

Public Member Functions

 __construct (int $global_idle_time_interval, private bool $auto_responder_status, private readonly AutoresponderRepository $auto_responder_repository, private readonly ClockInterface $clock, ?callable $mail_action=null)
 
 isAutoresponderEnabled ()
 
 enableAutoresponder ()
 
 disableAutoresponder ()
 
 handleAutoresponderMails (int $auto_responder_receiver_usr_id)
 
 enqueueAutoresponderIfEnabled (int $sender_id, ilMailOptions $mail_receiver_options, ilMailOptions $mail_sender_options)
 
 emptyAutoresponderData ()
 
 isAutoresponderEnabled ()
 
 enableAutoresponder ()
 
 disableAutoresponder ()
 
 handleAutoresponderMails (int $auto_responder_receiver_usr_id)
 
 enqueueAutoresponderIfEnabled (int $sender_id, ilMailOptions $mail_receiver_options, ilMailOptions $mail_sender_options)
 
 emptyAutoresponderData ()
 

Protected Attributes

array $auto_responder_data = []
 

Private Member Functions

 normalizeDateTimezone (DateTimeImmutable $date_time)
 
 shouldSendAutoresponder (AutoresponderDto $auto_responder)
 

Private Attributes

 $mail_action
 
readonly DateInterval $idle_time_interval
 

Additional Inherited Members

- Data Fields inherited from ILIAS\Mail\Autoresponder\AutoresponderService
const int AUTO_RESPONDER_DEFAULT_IDLE_TIME = 3
 

Detailed Description

Definition at line 29 of file AutoresponderServiceImpl.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Mail\Autoresponder\AutoresponderServiceImpl::__construct ( int  $global_idle_time_interval,
private bool  $auto_responder_status,
private readonly AutoresponderRepository  $auto_responder_repository,
private readonly ClockInterface  $clock,
?callable  $mail_action = null 
)
Parameters
callable(int,ilMailOptions,DateTimeImmutable)void|null $mail_action

Definition at line 41 of file AutoresponderServiceImpl.php.

47 {
48 $this->mail_action = $mail_action;
49 $this->idle_time_interval = new DateInterval('P' . $global_idle_time_interval . 'D');
50 }

References ILIAS\Mail\Autoresponder\AutoresponderServiceImpl\$mail_action.

Member Function Documentation

◆ disableAutoresponder()

ILIAS\Mail\Autoresponder\AutoresponderServiceImpl::disableAutoresponder ( )

Implements ILIAS\Mail\Autoresponder\AutoresponderService.

Definition at line 62 of file AutoresponderServiceImpl.php.

62 : void
63 {
64 $this->auto_responder_status = false;
65 }

◆ emptyAutoresponderData()

ILIAS\Mail\Autoresponder\AutoresponderServiceImpl::emptyAutoresponderData ( )

Implements ILIAS\Mail\Autoresponder\AutoresponderService.

Definition at line 143 of file AutoresponderServiceImpl.php.

143 : void
144 {
145 $this->auto_responder_data = [];
146 }

◆ enableAutoresponder()

ILIAS\Mail\Autoresponder\AutoresponderServiceImpl::enableAutoresponder ( )

Implements ILIAS\Mail\Autoresponder\AutoresponderService.

Definition at line 57 of file AutoresponderServiceImpl.php.

57 : void
58 {
59 $this->auto_responder_status = true;
60 }

◆ enqueueAutoresponderIfEnabled()

ILIAS\Mail\Autoresponder\AutoresponderServiceImpl::enqueueAutoresponderIfEnabled ( int  $sender_id,
ilMailOptions  $mail_receiver_options,
ilMailOptions  $mail_sender_options 
)

Implements ILIAS\Mail\Autoresponder\AutoresponderService.

Definition at line 133 of file AutoresponderServiceImpl.php.

137 : void {
138 if ($this->auto_responder_status && $mail_receiver_options->isAbsent()) {
139 $this->auto_responder_data[$sender_id] = $mail_receiver_options;
140 }
141 }

◆ handleAutoresponderMails()

ILIAS\Mail\Autoresponder\AutoresponderServiceImpl::handleAutoresponderMails ( int  $auto_responder_receiver_usr_id)

Implements ILIAS\Mail\Autoresponder\AutoresponderService.

Definition at line 67 of file AutoresponderServiceImpl.php.

67 : void
68 {
69 if ($this->auto_responder_data === []) {
70 return;
71 }
72
73 foreach ($this->auto_responder_data as $auto_responder_sender_usr_id => $mail_options) {
74 if ($this->auto_responder_repository->exists(
75 $auto_responder_sender_usr_id,
76 $auto_responder_receiver_usr_id
77 )) {
78 $auto_responder = $this->auto_responder_repository->findBySenderIdAndReceiverId(
79 $auto_responder_sender_usr_id,
80 $auto_responder_receiver_usr_id
81 );
82 } else {
83 $auto_responder = new AutoresponderDto(
84 $auto_responder_sender_usr_id,
85 $auto_responder_receiver_usr_id,
86 $this->normalizeDateTimezone($this->clock->now())
87 ->sub($this->idle_time_interval)
88 ->modify('-1 second')
89 );
90 }
91
92 if ($this->shouldSendAutoresponder($auto_responder)) {
93 $auto_responder = $auto_responder->withSentTime($this->clock->now());
94
95 if ($this->mail_action !== null) {
97 $auto_responder_sender_usr_id,
98 $mail_options,
99 $auto_responder->getSentTime()->add($this->idle_time_interval)
100 );
101 } else {
102 $mail = new AutoresponderNotification(
103 $mail_options,
104 $auto_responder_receiver_usr_id,
105 $auto_responder->getSentTime()->add($this->idle_time_interval)
106 );
107 $mail->send();
108 }
109
110 $this->auto_responder_repository->store($auto_responder);
111 }
112 }
113 }

References ILIAS\Mail\Autoresponder\AutoresponderServiceImpl\$mail_action, ILIAS\Mail\Autoresponder\AutoresponderServiceImpl\normalizeDateTimezone(), and ILIAS\Mail\Autoresponder\AutoresponderServiceImpl\shouldSendAutoresponder().

+ Here is the call graph for this function:

◆ isAutoresponderEnabled()

ILIAS\Mail\Autoresponder\AutoresponderServiceImpl::isAutoresponderEnabled ( )

Implements ILIAS\Mail\Autoresponder\AutoresponderService.

Definition at line 52 of file AutoresponderServiceImpl.php.

52 : bool
53 {
54 return $this->auto_responder_status;
55 }

◆ normalizeDateTimezone()

ILIAS\Mail\Autoresponder\AutoresponderServiceImpl::normalizeDateTimezone ( DateTimeImmutable  $date_time)
private

Definition at line 115 of file AutoresponderServiceImpl.php.

115 : DateTimeImmutable
116 {
117 return $date_time->setTimezone(new DateTimeZone('UTC'));
118 }

Referenced by ILIAS\Mail\Autoresponder\AutoresponderServiceImpl\handleAutoresponderMails(), and ILIAS\Mail\Autoresponder\AutoresponderServiceImpl\shouldSendAutoresponder().

+ Here is the caller graph for this function:

◆ shouldSendAutoresponder()

ILIAS\Mail\Autoresponder\AutoresponderServiceImpl::shouldSendAutoresponder ( AutoresponderDto  $auto_responder)
private

Definition at line 120 of file AutoresponderServiceImpl.php.

120 : bool
121 {
122 // Normalize timezones
123 $last_send_time_with_added_interval = $this
124 ->normalizeDateTimezone($auto_responder->getSentTime())
125 ->add($this->idle_time_interval);
126
127 $now = $this->normalizeDateTimezone($this->clock->now());
128
129 // Don't compare the objects because of microseconds
130 return $last_send_time_with_added_interval->format('Y-m-d H:i:s') <= $now->format('Y-m-d H:i:s');
131 }

References ILIAS\Mail\Autoresponder\AutoresponderDto\getSentTime(), and ILIAS\Mail\Autoresponder\AutoresponderServiceImpl\normalizeDateTimezone().

Referenced by ILIAS\Mail\Autoresponder\AutoresponderServiceImpl\handleAutoresponderMails().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $auto_responder_data

array< int, ilMailOptions > ILIAS\Mail\Autoresponder\AutoresponderServiceImpl::$auto_responder_data = []
protected

Definition at line 36 of file AutoresponderServiceImpl.php.

◆ $idle_time_interval

readonly DateInterval ILIAS\Mail\Autoresponder\AutoresponderServiceImpl::$idle_time_interval
private

Definition at line 33 of file AutoresponderServiceImpl.php.

◆ $mail_action

ILIAS\Mail\Autoresponder\AutoresponderServiceImpl::$mail_action
private

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