ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 
66  return $this->legal_documents->userCanReadInternalMail()->applyTo(new Ok($this->user));
67  }
68 
69  public function userWantsToReceiveExternalMails(): bool
70  {
71  return $this->mail_options->getIncomingType() === ilMailOptions::INCOMING_EMAIL ||
72  $this->mail_options->getIncomingType() === ilMailOptions::INCOMING_BOTH;
73  }
74 
75  public function onlyToExternalMailAddress(): bool
76  {
77  return $this->mail_options->getIncomingType() === ilMailOptions::INCOMING_EMAIL;
78  }
79 
83  public function getExternalMailAddress(): array
84  {
85  return $this->mail_options->getExternalEmailAddresses();
86  }
87 }
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:30
final const INCOMING_BOTH