ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
AutoresponderNotification.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Mail\Autoresponder;
22 
24 use ilMailOptions;
27 use ilDateTime;
28 
30 {
31  public function __construct(
32  private readonly ilMailOptions $sender_mail_options,
33  int $receiver_id,
34  private readonly DateTimeImmutable $next_auto_responder_datetime
35  ) {
37 
38  $this->setSender($sender_mail_options->getUsrId());
39  $this->setRecipients([$receiver_id]);
40  }
41 
42  public function send(): bool
43  {
44  $use_relative_dates = ilDatePresentation::useRelativeDates();
46 
47  foreach ($this->getRecipients() as $recipient) {
48  $this->initLanguage($recipient);
49  $this->initMail();
50 
51  $this->getMail()->setSaveInSentbox(false);
52  $former_language = ilDatePresentation::getLanguage();
54 
55  $this->setSubject($this->sender_mail_options->getAbsenceAutoresponderSubject());
56 
57  $this->setBody($this->sender_mail_options->getAbsenceAutoresponderBody());
58  $this->appendBody("\n");
59  $this->appendBody($this->sender_mail_options->getSignature());
60  $this->appendBody("\n\n");
61  $this->appendBody(
62  str_ireplace(
63  [
64  '[NEXT_AUTO_RESPONDER_DATETIME]'
65  ],
66  [
68  new ilDateTime($this->next_auto_responder_datetime->getTimestamp(), IL_CAL_UNIX)
69  )
70  ],
71  $this->getLanguageText('mail_absence_auto_responder_body_hint')
72  )
73  );
74 
75  $this->sendMail([$recipient]);
76 
77  ilDatePresentation::setLanguage($former_language);
78  }
79 
80  ilDatePresentation::setUseRelativeDates($use_relative_dates);
81 
82  return true;
83  }
84 }
static array static setUseRelativeDates(bool $a_status)
set use relative dates
sendMail(array $a_rcp, bool $a_parse_recipients=true)
const IL_CAL_UNIX
static setLanguage(ilLanguage $a_lng)
getLanguageText(string $a_keyword)
__construct(private readonly ilMailOptions $sender_mail_options, int $receiver_id, private readonly DateTimeImmutable $next_auto_responder_datetime)
__construct(Container $dic, ilPlugin $plugin)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
setSubject(string $a_subject)