ILIAS  release_8 Revision v8.24
class.ilMimeMailNotification.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
29 protected string $current_recipient;
31
32 public function __construct(bool $a_is_personal_workspace = false)
33 {
34 global $DIC;
35 $this->senderFactory = $DIC["mail.mime.sender.factory"];
36 parent::__construct($a_is_personal_workspace);
37 }
38
39 public function sendMimeMail(string $a_rcp): void
40 {
41 $this->mime_mail->To($a_rcp);
42 $this->mime_mail->Subject($this->getSubject(), true);
43 $this->mime_mail->Body($this->getBody());
44 $this->mime_mail->Send();
45 }
46
47 protected function setSubject(string $a_subject): string
48 {
49 return $this->subject = $a_subject;
50 }
51
52 protected function initMimeMail(): ilMimeMail
53 {
54 $this->mime_mail = new ilMimeMail();
55 $this->mime_mail->From($this->senderFactory->system());
56
57 return $this->mime_mail;
58 }
59
60 protected function initLanguageByIso2Code(string $a_code = ''): void
61 {
62 parent::initLanguageByIso2Code($a_code);
63 $this->getLanguage()->loadLanguageModule('registration');
64 }
65
66 protected function initLanguage(int $a_usr_id): void
67 {
68 parent::initLanguage($a_usr_id);
69 $this->getLanguage()->loadLanguageModule('registration');
70 }
71
76 protected function handleCurrentRecipient($rcp): void
77 {
78 if (is_numeric($rcp)) {
80 $rcp = ilObjectFactory::getInstanceByObjId((int) $rcp, false);
81 if (!($rcp instanceof ilObjUser)) {
82 throw new ilMailException('no_recipient_found');
83 }
84 $this->setCurrentRecipient($rcp->getEmail());
85 $this->initLanguage($rcp->getId());
86 } elseif (is_string($rcp) && ilUtil::is_email($rcp)) {
87 $this->setCurrentRecipient($rcp);
89 } elseif ($rcp instanceof ilObjUser) {
90 $this->setCurrentRecipient($rcp->getEmail());
91 $this->initLanguage($rcp->getId());
92 } else {
93 throw new ilMailException('no_recipient_found');
94 }
95 }
96
98 {
99 $this->current_recipient = $current_recipient;
100 return $this;
101 }
102
103 public function getCurrentRecipient(): string
104 {
106 }
107
109 {
110 $this->mime_mail = $mime_mail;
111 return $this;
112 }
113
114 public function getMimeMail(): ilMimeMail
115 {
116 return $this->mime_mail;
117 }
118}
Class ilMailException.
Class ilMailMimeSenderFactory.
Base class for course/group mail notifications.
Base class for mime mail notifications.
setCurrentRecipient(string $current_recipient)
__construct(bool $a_is_personal_workspace=false)
ilMailMimeSenderFactory $senderFactory
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.
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc