ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMimeMailNotification.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
24 protected string $current_recipient;
26
27 public function __construct(bool $a_is_personal_workspace = false)
28 {
29 global $DIC;
30 $this->sender_factory = $DIC->mail()->mime()->senderFactory();
31 parent::__construct($a_is_personal_workspace);
32 }
33
34 public function sendMimeMail(string $a_rcp): void
35 {
36 $this->mime_mail->To($a_rcp);
37 $this->mime_mail->Subject($this->getSubject(), true);
38 $this->mime_mail->Body($this->getBody());
39 $this->mime_mail->Send();
40 }
41
42 protected function setSubject(string $a_subject): string
43 {
44 return $this->subject = $a_subject;
45 }
46
47 protected function initMimeMail(): ilMimeMail
48 {
49 $this->mime_mail = new ilMimeMail();
50 $this->mime_mail->From($this->sender_factory->system());
51
52 return $this->mime_mail;
53 }
54
55 protected function initLanguageByIso2Code(string $a_code = ''): void
56 {
57 parent::initLanguageByIso2Code($a_code);
58 $this->getLanguage()->loadLanguageModule('registration');
59 }
60
61 protected function initLanguage(int $a_usr_id): void
62 {
63 parent::initLanguage($a_usr_id);
64 $this->getLanguage()->loadLanguageModule('registration');
65 }
66
71 protected function handleCurrentRecipient($rcp): void
72 {
73 if (is_numeric($rcp)) {
75 $rcp = ilObjectFactory::getInstanceByObjId((int) $rcp, false);
76 if (!$rcp instanceof ilObjUser) {
77 throw new ilMailException('no_recipient_found');
78 }
79 $this->setCurrentRecipient($rcp->getEmail());
80 $this->initLanguage($rcp->getId());
81 } elseif (is_string($rcp) && ilUtil::is_email($rcp)) {
82 $this->setCurrentRecipient($rcp);
84 } elseif ($rcp instanceof ilObjUser) {
85 $this->setCurrentRecipient($rcp->getEmail());
86 $this->initLanguage($rcp->getId());
87 } else {
88 throw new ilMailException('no_recipient_found');
89 }
90 }
91
93 {
94 $this->current_recipient = $current_recipient;
95 return $this;
96 }
97
98 public function getCurrentRecipient(): string
99 {
101 }
102
104 {
105 $this->mime_mail = $mime_mail;
106 return $this;
107 }
108
109 public function getMimeMail(): ilMimeMail
110 {
111 return $this->mime_mail;
112 }
113}
setCurrentRecipient(string $current_recipient)
__construct(bool $a_is_personal_workspace=false)
ilMailMimeSenderFactory $sender_factory
User class.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static is_email(string $a_email, ?ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
This preg-based function checks whether an e-mail address is formally valid.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26