ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLearningSequenceMembershipMailNotification.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 // Notifications affect members & co.
24 public const TYPE_ADMISSION_MEMBER = 20;
25 public const TYPE_DISMISS_MEMBER = 21;
28 public const TYPE_STATUS_CHANGED = 24;
29 public const TYPE_BLOCKED_MEMBER = 25;
30 public const TYPE_UNBLOCKED_MEMBER = 26;
31 public const TYPE_UNSUBSCRIBE_MEMBER = 27;
32 public const TYPE_SUBSCRIBE_MEMBER = 28;
33 public const TYPE_WAITING_LIST_MEMBER = 29;
34
35 // Notifications affect admins
39
48 ];
49
50 protected ilLogger $logger;
52 private bool $force_sending_mail = false;
53
55 {
57
58 $this->logger = $logger;
59 $this->settings = $settings;
60 }
61
62 public function forceSendingMail(bool $status): void
63 {
64 $this->force_sending_mail = $status;
65 }
66
67 public function send(): bool
68 {
69 if (!$this->isNotificationTypeEnabled($this->getType())) {
70 $this->logger->info('Membership mail disabled globally.');
71 return false;
72 }
73
74 switch ($this->getType()) {
76 foreach ($this->getRecipients() as $rcp) {
77 $this->initLanguage($rcp);
78 $this->initMail();
79 $this->setSubject(sprintf(
80 $this->getLanguageText('lso_mail_admission_new_sub'),
81 $this->getObjectTitle(true)
82 ));
84 $rcp,
85 $this->getLanguage()
86 ));
87 $this->appendBody("\n\n");
88 $this->appendBody(sprintf(
89 $this->getLanguageText('lso_mail_admission_new_bod'),
90 $this->getObjectTitle()
91 ));
92 $this->appendBody("\n\n");
93 $this->appendBody(
94 $this->getLanguageText('lso_mail_permanent_link')
95 );
96 $this->appendBody("\n\n");
97 $this->appendBody($this->createPermanentLink());
98 $this->getMail()->appendInstallationSignature(true);
99 $this->sendMail(array($rcp));
100 }
101 break;
103 foreach ($this->getRecipients() as $rcp) {
104 $this->initLanguage($rcp);
105 $this->initMail();
106 $this->setSubject(sprintf(
107 $this->getLanguageText('lso_mail_dismiss_sub'),
108 $this->getObjectTitle(true)
109 ));
111 $rcp,
112 $this->getLanguage()
113 ));
114 $this->appendBody("\n\n");
115 $this->appendBody(sprintf(
116 $this->getLanguageText('lso_mail_dismiss_bod'),
117 $this->getObjectTitle()
118 ));
119 $this->getMail()->appendInstallationSignature(true);
120 $this->sendMail(array($rcp));
121 }
122 break;
124 foreach ($this->getRecipients() as $rcp) {
125 $this->initLanguage($rcp);
126 $this->initMail();
127 $this->setSubject(sprintf(
128 $this->getLanguageText('lso_mail_notification_reg_sub'),
129 $this->getObjectTitle(true)
130 ));
132 $rcp,
133 $this->getLanguage()
134 ));
135 $this->appendBody("\n\n");
137 $this->appendBody(sprintf(
138 $this->getLanguageText('lso_mail_notification_reg_bod'),
139 $this->userToString($info['usr_id']),
140 $this->getObjectTitle()
141 ));
142 $this->appendBody("\n\n");
143 $this->appendBody(
144 $this->getLanguageText('lso_mail_permanent_link')
145 );
146 $this->appendBody("\n\n");
147 $this->appendBody(
148 $this->createPermanentLink(array(), '_mem')
149 );
150 $this->appendBody("\n\n");
151 $this->appendBody($this->getLanguageText(
152 'lso_notification_explanation_admin'
153 ));
154 $this->getMail()->appendInstallationSignature(true);
155 $this->sendMail(array($rcp));
156 }
157 break;
159 foreach ($this->getRecipients() as $rcp) {
160 $this->initLanguage($rcp);
161 $this->initMail();
162 $this->setSubject(sprintf(
163 $this->getLanguageText('lso_mail_unsubscribe_member_sub'),
164 $this->getObjectTitle(true)
165 ));
167 $rcp,
168 $this->getLanguage()
169 ));
170 $this->appendBody("\n\n");
171 $this->appendBody(sprintf(
172 $this->getLanguageText('lso_mail_unsubscribe_member_bod'),
173 $this->getObjectTitle()
174 ));
175 $this->getMail()->appendInstallationSignature(true);
176 $this->sendMail(array($rcp));
177 }
178 break;
180 foreach ($this->getRecipients() as $rcp) {
181 $this->initLanguage($rcp);
182 $this->initMail();
183 $this->setSubject(sprintf(
184 $this->getLanguageText('lso_mail_notification_unsub_sub'),
185 $this->getObjectTitle(true)
186 ));
188 $rcp,
189 $this->getLanguage()
190 ));
191 $this->appendBody("\n\n");
193 $this->appendBody(sprintf(
194 $this->getLanguageText('lso_mail_notification_unsub_bod'),
195 $this->userToString($info['usr_id']),
196 $this->getObjectTitle()
197 ));
198 $this->appendBody("\n\n");
199 $this->appendBody(
200 $this->getLanguageText(
201 'lso_mail_notification_unsub_bod2'
202 )
203 );
204 $this->appendBody("\n\n");
205 $this->appendBody($this->createPermanentLink(
206 array(),
207 '_mem'
208 ));
209 $this->appendBody("\n\n");
210 $this->appendBody(
211 $this->getLanguageText(
212 'lso_notification_explanation_admin'
213 )
214 );
215 $this->getMail()->appendInstallationSignature(true);
216 $this->sendMail(array($rcp));
217 }
218 break;
220 foreach ($this->getRecipients() as $rcp) {
221 $this->initLanguage($rcp);
222 $this->initMail();
223 $this->setSubject(sprintf(
224 $this->getLanguageText('grp_mail_subscribe_member_sub'),
225 $this->getObjectTitle(true)
226 ));
228 $rcp,
229 $this->getLanguage()
230 ));
231 $this->appendBody("\n\n");
232 $this->appendBody(
233 sprintf(
234 $this->getLanguageText('grp_mail_subscribe_member_bod'),
235 $this->getObjectTitle()
236 )
237 );
238 $this->appendBody("\n\n");
239 $this->appendBody(
240 $this->getLanguageText('grp_mail_permanent_link')
241 );
242 $this->appendBody("\n\n");
243 $this->appendBody($this->createPermanentLink());
244 $this->getMail()->appendInstallationSignature(true);
245 $this->sendMail(array($rcp));
246 }
247 break;
249 foreach ($this->getRecipients() as $rcp) {
250 $this->initLanguage($rcp);
251 $this->initMail();
252 $this->setSubject(sprintf(
253 $this->getLanguageText('grp_mail_notification_reg_req_sub'),
254 $this->getObjectTitle(true)
255 ));
257 $rcp,
258 $this->getLanguage()
259 ));
260 $this->appendBody("\n\n");
262 $this->appendBody(sprintf(
263 $this->getLanguageText('grp_mail_notification_reg_req_bod'),
264 $this->userToString($info['usr_id']),
265 $this->getObjectTitle()
266 ));
267 $this->appendBody("\n\n");
268 $this->appendBody(
269 $this->getLanguageText('grp_mail_notification_reg_req_bod2')
270 );
271 $this->appendBody("\n");
272 $this->appendBody($this->createPermanentLink(array(), '_mem'));
273 $this->appendBody("\n\n");
274 $this->appendBody(
275 $this->getLanguageText('grp_notification_explanation_admin')
276 );
277 $this->getMail()->appendInstallationSignature(true);
278 $this->sendMail(array($rcp));
279 }
280 break;
282 foreach ($this->getRecipients() as $rcp) {
283 $this->initLanguage($rcp);
284 $this->initMail();
285 $this->setSubject(sprintf(
286 $this->getLanguageText('grp_mail_sub_dec_sub'),
287 $this->getObjectTitle(true)
288 ));
290 $rcp,
291 $this->getLanguage()
292 ));
293 $this->appendBody("\n\n");
294 $this->appendBody(sprintf(
295 $this->getLanguageText('grp_mail_sub_dec_bod'),
296 $this->getObjectTitle()
297 ));
298 $this->getMail()->appendInstallationSignature(true);
299 $this->sendMail(array($rcp));
300 }
301 break;
303 foreach ($this->getRecipients() as $rcp) {
304 $this->initLanguage($rcp);
305 $this->initMail();
306 $this->setSubject(sprintf(
307 $this->getLanguageText('grp_mail_sub_acc_sub'),
308 $this->getObjectTitle(true)
309 ));
310 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
311 $this->appendBody("\n\n");
312 $this->appendBody(sprintf(
313 $this->getLanguageText('grp_mail_sub_acc_bod'),
314 $this->getObjectTitle()
315 ));
316 $this->appendBody("\n\n");
317 $this->appendBody(
318 $this->getLanguageText('grp_mail_permanent_link')
319 );
320 $this->appendBody("\n\n");
321 $this->appendBody($this->createPermanentLink());
322 $this->getMail()->appendInstallationSignature(true);
323 $this->sendMail(array($rcp));
324 }
325 break;
327 foreach ($this->getRecipients() as $rcp) {
328 $this->initLanguage($rcp);
329 $this->initMail();
330 $this->setSubject(sprintf(
331 $this->getLanguageText('grp_mail_wl_sub'),
332 $this->getObjectTitle(true)
333 ));
335 $rcp,
336 $this->getLanguage()
337 ));
339 $this->appendBody("\n\n");
340 $this->appendBody(sprintf(
341 $this->getLanguageText('grp_mail_wl_bod'),
342 $this->getObjectTitle(),
343 $info['position']
344 ));
345 $this->getMail()->appendInstallationSignature(true);
346 $this->sendMail(array($rcp));
347 }
348 break;
350 foreach ($this->getRecipients() as $rcp) {
351 $this->initLanguage($rcp);
352 $this->initMail();
353 $this->setSubject(sprintf(
354 $this->getLanguageText('grp_mail_status_sub'),
355 $this->getObjectTitle(true)
356 ));
358 $rcp,
359 $this->getLanguage()
360 ));
361 $this->appendBody("\n\n");
362 $this->appendBody(sprintf(
363 $this->getLanguageText('grp_mail_status_bod'),
364 $this->getObjectTitle()
365 ));
366 $this->appendBody("\n\n");
367 $this->appendBody($this->createLearningSequenceStatus((int) $rcp));
368 $this->appendBody("\n\n");
369 $this->appendBody(
370 $this->getLanguageText('grp_mail_permanent_link')
371 );
372 $this->appendBody("\n\n");
373 $this->appendBody($this->createPermanentLink());
374 $this->getMail()->appendInstallationSignature(true);
375 $this->sendMail(array($rcp));
376 }
377 break;
378 }
379 return true;
380 }
381
382 protected function initLanguage(int $usr_id): void
383 {
384 parent::initLanguage($usr_id);
385 $this->getLanguage()->loadLanguageModule('lso');
386 }
387
388 protected function createLearningSequenceStatus(int $usr_id): string
389 {
391 $body = $this->getLanguageText('lso_new_status') . "\n";
392 $body .= $this->getLanguageText('role') . ': ';
393
394 if ($part->isAdmin($usr_id)) {
395 $body .= $this->getLanguageText('il_lso_admin') . "\n";
396 } else {
397 $body .= $this->getLanguageText('il_lso_member') . "\n";
398 }
399
400 if ($part->isAdmin($usr_id)) {
401 $body .= $this->getLanguageText('lso_notification') . ': ';
402
403 if ($part->isNotificationEnabled($usr_id)) {
404 $body .= $this->getLanguageText('lso_notify_on') . "\n";
405 } else {
406 $body .= $this->getLanguageText('lso_notify_off') . "\n";
407 }
408 }
409
410 return $body;
411 }
412
413 protected function isNotificationTypeEnabled(int $type): bool
414 {
415 return (
416 $this->force_sending_mail ||
417 $this->settings->get('mail_lso_member_notification', "true") ||
418 in_array($type, $this->permanent_enabled_notifications)
419 );
420 }
421}
array $permanent_enabled_notifications
Notifications which are not affected by "mail_grp_member_notification" setting because they addresses...
Component logger with individual log levels by component id.
getObjectTitle(bool $a_shorten=false)
sendMail(array $a_rcp, bool $a_parse_recipients=true)
createPermanentLink(array $a_params=[], string $a_append='')
getLanguageText(string $a_keyword)
setSubject(string $a_subject)
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
ILIAS Setting Class.
$info
Definition: entry_point.php:21
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc