ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
Recipient.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Mail;
22 
27 use ilObjUser;
28 use ilMailOptions;
29 
30 final readonly class Recipient
31 {
32  public function __construct(
33  private int $user_id,
34  private ?ilObjUser $user,
35  private ilMailOptions $mail_options,
36  private Conductor $legal_documents
37  ) {
38  }
39 
40  public function getUserId(): int
41  {
42  return $this->user_id;
43  }
44 
45  public function getMailOptions(): ilMailOptions
46  {
47  return $this->mail_options;
48  }
49 
50  public function isUser(): bool
51  {
52  return !is_null($this->user);
53  }
54 
55  public function isUserActive(): bool
56  {
57  return $this->user->getActive();
58  }
59 
60  public function isUserExpired(): bool
61  {
62  return !$this->user->checkTimeLimit();
63  }
64 
66  {
67  if ($this->isUserExpired()) {
68  return new Error('Account expired.');
69  }
70 
71  return $this->legal_documents->userCanReadInternalMail()->applyTo(new Ok($this->user));
72  }
73 
74  public function userWantsToReceiveExternalMails(): bool
75  {
76  return $this->mail_options->getIncomingType() === ilMailOptions::INCOMING_EMAIL ||
77  $this->mail_options->getIncomingType() === ilMailOptions::INCOMING_BOTH;
78  }
79 
80  public function onlyToExternalMailAddress(): bool
81  {
82  return $this->mail_options->getIncomingType() === ilMailOptions::INCOMING_EMAIL;
83  }
84 
88  public function getExternalMailAddress(): array
89  {
90  return $this->mail_options->getExternalEmailAddresses();
91  }
92 }
final const int INCOMING_BOTH
final const int INCOMING_EMAIL
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:30
__construct(private int $user_id, private ?ilObjUser $user, private ilMailOptions $mail_options, private Conductor $legal_documents)
Definition: Recipient.php:32