ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilAccountRegistrationMail Class Reference

Class ilAccountRegistrationMail. More...

+ Inheritance diagram for ilAccountRegistrationMail:
+ Collaboration diagram for ilAccountRegistrationMail:

Public Member Functions

 __construct (ilRegistrationSettings $settings, ilLanguage $lng, ilLogger $logger)
 
 getMode ()
 
 withPermanentLinkTarget (string $permanent_link_target)
 
 withDirectRegistrationMode ()
 
 withEmailConfirmationRegistrationMode ()
 
 send (ilObjUser $user, string $rawPassword='', bool $usedRegistrationCode=false)
 
- Public Member Functions inherited from ilMimeMailNotification
 __construct (bool $a_is_personal_workspace=false)
 
 sendMimeMail (string $a_rcp)
 
 setCurrentRecipient (string $current_recipient)
 
 getCurrentRecipient ()
 
 setMimeMail (ilMimeMail $mime_mail)
 
 getMimeMail ()
 
- Public Member Functions inherited from ilMailNotification
 __construct (protected bool $is_in_wsp=false)
 
 setType (int $a_type)
 
 getType ()
 
 setSender (int $a_usr_id)
 
 getSender ()
 
 setRecipients (array $a_rcp)
 
 getRecipients ()
 
 setAttachments (array $a_att)
 
 getAttachments ()
 
 setLangModules (array $a_modules)
 
 getUserLanguage (int $a_usr_id)
 
 setRefId (int $a_id)
 
 getRefId ()
 
 getObjId ()
 
 setObjId (int $a_obj_id)
 
 getObjType ()
 
 setAdditionalInformation (array $a_info)
 
 getAdditionalInformation ()
 
 sendMail (array $a_rcp, bool $a_parse_recipients=true)
 
 getBlockBorder ()
 

Protected Attributes

const MODE_DIRECT_REGISTRATION = 1
 
const MODE_REGISTRATION_WITH_EMAIL_CONFIRMATION = 2
 
- Protected Attributes inherited from ilMimeMailNotification
ilMimeMail $mime_mail
 
string $current_recipient
 
ilMailMimeSenderFactory $sender_factory
 
- Protected Attributes inherited from ilMailNotification
int $type
 
int $sender
 
ilMail $mail = null
 
string $subject = ''
 
string $body = ''
 
array $attachments = []
 
ilLanguage $language
 
array $lang_modules = []
 
array $recipients = []
 
int $ref_id
 
int $obj_id = 0
 
string $obj_type = ''
 
array $additional_info = []
 
ilWorkspaceTree $wsp_tree
 
ilWorkspaceAccessHandler $wsp_access_handler
 

Private Member Functions

 isEmptyMailConfigurationData (array $mailData)
 
 trySendingUserDefinedAccountMail (ilObjUser $user, string $rawPassword)
 
 sendLanguageVariableBasedAccountMail (ilObjUser $user, string $rawPassword, bool $usedRegistrationCode)
 

Private Attributes

ilRegistrationSettings $settings
 
ilLogger $logger
 
int $mode = self::MODE_DIRECT_REGISTRATION
 
string $permanent_link_target = null
 

Additional Inherited Members

- Data Fields inherited from ilMailNotification
final const int SUBJECT_TITLE_LENGTH = 60
 
- Protected Member Functions inherited from ilMimeMailNotification
 setSubject (string $a_subject)
 
 initMimeMail ()
 
 initLanguageByIso2Code (string $a_code='')
 
 initLanguage (int $a_usr_id)
 
- Protected Member Functions inherited from ilMailNotification
 setSubject (string $a_subject)
 
 getSubject ()
 
 setBody (string $a_body)
 
 appendBody (string $a_body)
 
 getBody ()
 
 initLanguage (int $a_usr_id)
 
 initLanguageByIso2Code (string $a_code='')
 
 setLanguage (ilLanguage $a_language)
 
 getLanguage ()
 
 getLanguageText (string $a_keyword)
 
 getObjectTitle (bool $a_shorten=false)
 
 initMail ()
 
 getMail ()
 
 createPermanentLink (array $a_params=[], string $a_append='')
 
 userToString (int $a_usr_id)
 
 isRefIdAccessible (int $a_user_id, int $a_ref_id, string $a_permission='read')
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAccountRegistrationMail::__construct ( ilRegistrationSettings  $settings,
ilLanguage  $lng,
ilLogger  $logger 
)

Member Function Documentation

◆ getMode()

ilAccountRegistrationMail::getMode ( )

Definition at line 42 of file class.ilAccountRegistrationMail.php.

References $mode.

Referenced by sendLanguageVariableBasedAccountMail().

42  : int
43  {
44  return $this->mode;
45  }
+ Here is the caller graph for this function:

◆ isEmptyMailConfigurationData()

ilAccountRegistrationMail::isEmptyMailConfigurationData ( array  $mailData)
private

Definition at line 74 of file class.ilAccountRegistrationMail.php.

Referenced by trySendingUserDefinedAccountMail().

74  : bool
75  {
76  return !(
77  isset($mailData['body'], $mailData['subject']) &&
78  is_string($mailData['body']) &&
79  $mailData['body'] !== '' &&
80  is_string($mailData['subject']) &&
81  $mailData['subject'] !== ''
82  );
83  }
+ Here is the caller graph for this function:

◆ send()

ilAccountRegistrationMail::send ( ilObjUser  $user,
string  $rawPassword = '',
bool  $usedRegistrationCode = false 
)

Definition at line 228 of file class.ilAccountRegistrationMail.php.

References sendLanguageVariableBasedAccountMail(), and trySendingUserDefinedAccountMail().

228  : void
229  {
230  if (!$this->trySendingUserDefinedAccountMail($user, $rawPassword)) {
231  $this->sendLanguageVariableBasedAccountMail($user, $rawPassword, $usedRegistrationCode);
232  }
233  }
sendLanguageVariableBasedAccountMail(ilObjUser $user, string $rawPassword, bool $usedRegistrationCode)
trySendingUserDefinedAccountMail(ilObjUser $user, string $rawPassword)
+ Here is the call graph for this function:

◆ sendLanguageVariableBasedAccountMail()

ilAccountRegistrationMail::sendLanguageVariableBasedAccountMail ( ilObjUser  $user,
string  $rawPassword,
bool  $usedRegistrationCode 
)
private

Definition at line 163 of file class.ilAccountRegistrationMail.php.

References ilMail\_getInstallationSignature(), ilMailNotification\appendBody(), CLIENT_ID, ilObjUser\getEmail(), ilObjUser\getFullname(), ilObject\getId(), ilObjUser\getLanguage(), ilObjUser\getLogin(), getMode(), ilRegistrationSettings\IL_REG_APPROVE, ilMimeMailNotification\initLanguageByIso2Code(), ilMimeMailNotification\initMimeMail(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), ILIAS\Repository\logger(), ilMimeMailNotification\sendMimeMail(), ilMailNotification\setBody(), ilMimeMailNotification\setSubject(), and ILIAS\Repository\settings().

Referenced by send().

167  : void {
168  if (!$user->getEmail()) {
169  $this->logger->debug(sprintf(
170  'Missing email address, did not send account registration mail for user %s (id: %s) ...',
171  $user->getLogin(),
172  $user->getId()
173  ));
174  return;
175  }
176 
177  $this->logger->debug(sprintf(
178  'Sending language variable dependent welcome email to user %s (id: %s|language: %s) as fallback ...',
179  $user->getLogin(),
180  $user->getId(),
181  $user->getLanguage()
182  ));
183 
184  $this->initMimeMail();
185 
186  $this->initLanguageByIso2Code($user->getLanguage());
187 
188  $this->setSubject($this->language->txt('reg_mail_subject'));
189 
190  $this->setBody($this->language->txt('reg_mail_body_salutation') . ' ' . $user->getFullname() . ',');
191  $this->appendBody("\n\n");
192  $this->appendBody($this->language->txt('reg_mail_body_text1'));
193  $this->appendBody("\n\n");
194  $this->appendBody($this->language->txt('reg_mail_body_text2'));
195  $this->appendBody("\n");
196  $this->appendBody(ILIAS_HTTP_PATH . '/login.php?client_id=' . CLIENT_ID);
197  $this->appendBody("\n");
198  $this->appendBody($this->language->txt('login') . ': ' . $user->getLogin());
199  $this->appendBody("\n");
200 
201  if ($this->settings->passwordGenerationEnabled()) {
202  $this->appendBody($this->language->txt('passwd') . ': ' . $rawPassword);
203  $this->appendBody("\n");
204  }
205 
206  if ($this->getMode() === self::MODE_DIRECT_REGISTRATION) {
207  if ($this->settings->getRegistrationType() === ilRegistrationSettings::IL_REG_APPROVE && !$usedRegistrationCode) {
208  $this->appendBody("\n");
209  $this->appendBody($this->language->txt('reg_mail_body_pwd_generation'));
210  $this->appendBody("\n\n");
211  }
212  } elseif ($this->getMode() === self::MODE_REGISTRATION_WITH_EMAIL_CONFIRMATION) {
213  $this->appendBody("\n");
214  $this->appendBody($this->language->txt('reg_mail_body_forgot_password_info'));
215  $this->appendBody("\n\n");
216  }
217 
218  $this->appendBody($this->language->txt('reg_mail_body_text3'));
219  $this->appendBody("\n");
220  $this->appendBody($user->getProfileAsString($this->language));
222 
223  $this->sendMimeMail($user->getEmail());
224 
225  $this->logger->debug('Welcome email sent');
226  }
getFullname(int $a_max_strlen=0)
const CLIENT_ID
Definition: constants.php:41
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
static _getInstallationSignature()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ trySendingUserDefinedAccountMail()

ilAccountRegistrationMail::trySendingUserDefinedAccountMail ( ilObjUser  $user,
string  $rawPassword 
)
private

Definition at line 85 of file class.ilAccountRegistrationMail.php.

References ilObjUserFolder\_lookupNewAccountMail(), ilObject\getId(), ilObjUser\getLanguage(), ilObjUser\getLogin(), isEmptyMailConfigurationData(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), ILIAS\Repository\logger(), ILIAS\Repository\settings(), and USER_FOLDER_ID.

Referenced by send().

85  : bool
86  {
87  $trimStrings = static function ($value) {
88  if (is_string($value)) {
89  $value = trim($value);
90  }
91 
92  return $value;
93  };
94 
95  $this->logger->debug(sprintf(
96  'Trying to send configurable email dependent welcome email to user %s (id: %s|language: %s) ...',
97  $user->getLogin(),
98  $user->getId(),
99  $user->getLanguage()
100  ));
101 
102  $mailData = array_map($trimStrings, ilObjUserFolder::_lookupNewAccountMail($user->getLanguage()));
103 
104  if ($this->isEmptyMailConfigurationData($mailData)) {
105  $this->logger->debug(sprintf(
106  'Either subject or email missing, trying to determine email configuration via default language: %s',
107  $this->language->getDefaultLanguage()
108  ));
109 
110  $mailData = ilObjUserFolder::_lookupNewAccountMail($this->language->getDefaultLanguage());
111  if (!is_array($mailData)) {
112  $this->logger->debug(sprintf(
113  "Did not find any email configuration for language '%s' at all, skipping attempt ...",
114  $this->language->getDefaultLanguage()
115  ));
116  return false;
117  }
118 
119  $mailData = array_map($trimStrings, $mailData);
120  if ($this->isEmptyMailConfigurationData($mailData)) {
121  $this->logger->debug('Did not find any valid email configuration, skipping attempt ...');
122  return false;
123  }
124  }
125 
126  $accountMail = new ilAccountMail();
127  $accountMail->setUser($user);
128  $accountMail->setPermanentLinkTarget($this->permanent_link_target);
129 
130  if ($this->settings->passwordGenerationEnabled()) {
131  $accountMail->setUserPassword($rawPassword);
132  }
133 
134  if (isset($mailData['att_file'])) {
136  $fs->create();
137 
138  $pathToFile = '/' . implode('/', array_map(static function (string $pathPart): string {
139  return trim($pathPart, '/');
140  }, [
141  $fs->getAbsolutePath(),
142  $mailData['lang'],
143  ]));
144 
145  $accountMail->addAttachment($pathToFile, $mailData['att_file']);
146 
147  $this->logger->debug(sprintf(
148  "Attaching '%s' as '%s' ...",
149  $pathToFile,
150  $mailData['att_file']
151  ));
152  } else {
153  $this->logger->debug('Not attachments configured for this email configuration ...');
154  }
155 
156  $accountMail->send();
157 
158  $this->logger->debug('Welcome email sent');
159 
160  return true;
161  }
const USER_FOLDER_ID
Definition: constants.php:33
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupNewAccountMail(string $a_lang)
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ withDirectRegistrationMode()

ilAccountRegistrationMail::withDirectRegistrationMode ( )

Definition at line 60 of file class.ilAccountRegistrationMail.php.

61  {
62  $clone = clone $this;
63  $clone->mode = self::MODE_DIRECT_REGISTRATION;
64  return $clone;
65  }
Class ilAccountRegistrationMail.

◆ withEmailConfirmationRegistrationMode()

ilAccountRegistrationMail::withEmailConfirmationRegistrationMode ( )

Definition at line 67 of file class.ilAccountRegistrationMail.php.

68  {
69  $clone = clone $this;
70  $clone->mode = self::MODE_REGISTRATION_WITH_EMAIL_CONFIRMATION;
71  return $clone;
72  }
Class ilAccountRegistrationMail.

◆ withPermanentLinkTarget()

ilAccountRegistrationMail::withPermanentLinkTarget ( string  $permanent_link_target)

Definition at line 47 of file class.ilAccountRegistrationMail.php.

References $permanent_link_target.

47  : self
48  {
49  if ($permanent_link_target === '') {
50  throw new InvalidArgumentException(
51  'Permanent link target must not be empty'
52  );
53  }
54 
55  $clone = clone $this;
56  $clone->permanent_link_target = $permanent_link_target;
57  return $clone;
58  }

Field Documentation

◆ $logger

ilLogger ilAccountRegistrationMail::$logger
private

Definition at line 31 of file class.ilAccountRegistrationMail.php.

Referenced by __construct().

◆ $mode

int ilAccountRegistrationMail::$mode = self::MODE_DIRECT_REGISTRATION
private

Definition at line 32 of file class.ilAccountRegistrationMail.php.

Referenced by getMode().

◆ $permanent_link_target

string ilAccountRegistrationMail::$permanent_link_target = null
private

Definition at line 33 of file class.ilAccountRegistrationMail.php.

Referenced by withPermanentLinkTarget().

◆ $settings

ilRegistrationSettings ilAccountRegistrationMail::$settings
private

Definition at line 30 of file class.ilAccountRegistrationMail.php.

Referenced by __construct().

◆ MODE_DIRECT_REGISTRATION

const ilAccountRegistrationMail::MODE_DIRECT_REGISTRATION = 1
protected

Definition at line 27 of file class.ilAccountRegistrationMail.php.

◆ MODE_REGISTRATION_WITH_EMAIL_CONFIRMATION

const ilAccountRegistrationMail::MODE_REGISTRATION_WITH_EMAIL_CONFIRMATION = 2
protected

Definition at line 28 of file class.ilAccountRegistrationMail.php.


The documentation for this class was generated from the following file: