20 private int $addresserId;
21 private int $receiverId;
23 private array $changeFields;
24 private int $counterInvitations;
25 private ?array $event =
null;
27 private ?
Context $context =
null;
35 ?array $changeFields = [],
36 ?
int $counterInvitations = 0
39 $this->eventId = $eventId;
40 $this->addresserId = $addresserId;
41 $this->receiverId = $receiverId;
43 $this->changeFields = $changeFields ?? [];
44 $this->counterInvitations = $counterInvitations ?? 0;
59 'eventId' => $this->eventId,
60 'addresserId' => $this->addresserId,
61 'receiverId' => $this->receiverId,
62 'type' => $this->type,
63 'changeFields' => $this->changeFields,
64 'counterInvitation' => $this->counterInvitations,
72 ->setContextByEvent();
77 private function setEventById(): static
79 if (is_null($this->event))
81 $this->
event = $this->getEvent();
87 private function getEvent(): ?array
93 catch (SystemException $exception)
95 $this->logger->log($exception);
100 private function setContextByEvent(): static
102 $this->setEventById();
107 $this->getAddresser($this->event[
'MEETING'] ??
null),
108 $this->getReceiver(),
112 catch (MemberNotFoundException $exception)
114 $this->logger->log($exception);
123 private function getAddresser(?
string $meetingInfo): ?MailAddresser
125 $addresser = $this->getInfoAboutUser($this->addresserId);
126 if (is_null($addresser))
128 throw new MemberNotFoundException(
"Addresser {$this->addresserId} not found or not active");
133 $this->getSelectedAddresserEmail($meetingInfo) ?? $addresser->getEmail(),
134 $addresser->getName(),
135 $addresser->getLastName()
142 private function getReceiver(): MailReceiver
144 $receiver = $this->getInfoAboutUser($this->receiverId);
145 if (is_null($receiver))
147 throw new MemberNotFoundException(
"Receiver {$this->receiverId} not found or not active");
152 $receiver->getEmail(),
153 $receiver->getName(),
154 $receiver->getLastName()
158 private function getInfoAboutUser(
int $userId): ?EO_User
162 $query = UserTable::query();
164 ->setSelect([
'ID',
'EMAIL',
'NAME',
'LAST_NAME',
'ACTIVE'])
165 ->where(
'ID', $userId)
166 ->where(
'ACTIVE',
true);
168 return $query->exec()->fetchObject();
170 catch (SystemException $exception)
172 $this->logger->log($exception);
177 private function getSelectedAddresserEmail(?
string $serializedMeetingInfo =
null): ?string
179 $meetingInfo = unserialize($serializedMeetingInfo, [
'allowed_classes' =>
false]);
181 return !empty($meetingInfo) && !empty($meetingInfo[
'MAIL_FROM'])
182 ? $meetingInfo[
'MAIL_FROM']
186 private function init(): void
188 $this->logger =
new Logger();
static createInstance(MailAddresser $addresser, MailReceiver $receiver, array $changeFields=null)