ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 class Recipient
31 {
32  public function __construct(
33  private readonly int $user_id,
34  private readonly ?ilObjUser $user,
35  private readonly ilMailOptions $mail_options,
36  private readonly 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 
61  {
62  if (!$this->user->checkTimeLimit()) {
63  return new Error('Account expired.');
64  }
65  return $this->legal_documents->userCanReadInternalMail()->applyTo(new Ok($this->user));
66  }
67 
68  public function userWantsToReceiveExternalMails(): bool
69  {
70  return $this->mail_options->getIncomingType() === ilMailOptions::INCOMING_EMAIL ||
71  $this->mail_options->getIncomingType() === ilMailOptions::INCOMING_BOTH;
72  }
73 
74  public function onlyToExternalMailAddress(): bool
75  {
76  return $this->mail_options->getIncomingType() === ilMailOptions::INCOMING_EMAIL;
77  }
78 
82  public function getExternalMailAddress(): array
83  {
84  return $this->mail_options->getExternalEmailAddresses();
85  }
86 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:14
final const INCOMING_EMAIL
__construct(private readonly int $user_id, private readonly ?ilObjUser $user, private readonly ilMailOptions $mail_options, private readonly Conductor $legal_documents)
Definition: Recipient.php:32
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:16
final const INCOMING_BOTH