ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCourseMembershipMailNotification.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
26{
27 // v Notifications affect members & co. v
28 public const TYPE_ADMISSION_MEMBER = 20;
29 public const TYPE_DISMISS_MEMBER = 21;
30
33
34 public const TYPE_STATUS_CHANGED = 24;
35
36 public const TYPE_BLOCKED_MEMBER = 25;
37 public const TYPE_UNBLOCKED_MEMBER = 26;
38
39 public const TYPE_UNSUBSCRIBE_MEMBER = 27;
40 public const TYPE_SUBSCRIBE_MEMBER = 28;
41 public const TYPE_WAITING_LIST_MEMBER = 29;
42
43 // v Notifications affect admins v
47
48 public const TYPE_NOTIFICATION_ADMINS = 33;
50
56 protected array $permanent_enabled_notifications = array(
57 self::TYPE_NOTIFICATION_REGISTRATION,
58 self::TYPE_NOTIFICATION_REGISTRATION_REQUEST,
59 self::TYPE_NOTIFICATION_UNSUBSCRIBE
60 );
61
62 private bool $force_sending_mail = false;
63
65
66 public function __construct()
67 {
68 global $DIC;
69
70 $this->setting = $DIC->settings();
72 }
73
77 protected function initMail(): ilMail
78 {
79 parent::initMail();
80 $this->mail = $this->mail->withContextParameters([
84 ''
85 ),
86 ]);
87
88 return $this->mail;
89 }
90
94 public function forceSendingMail(bool $a_status): void
95 {
96 $this->force_sending_mail = $a_status;
97 }
98
99 public function send(): bool
100 {
101 if (
102 $this->getRefId() &&
103 in_array($this->getType(), array(self::TYPE_ADMISSION_MEMBER))) {
105
106 if ($obj->getAutoNotification() == false) {
107 if (!$this->force_sending_mail) {
108 return false;
109 }
110 }
111 }
112 if (!$this->isNotificationTypeEnabled($this->getType())) {
113 return false;
114 }
115 // #11359
116 // parent::send();
117
118 switch ($this->getType()) {
120
121 foreach ($this->getRecipients() as $rcp) {
122 $this->initLanguage($rcp);
123 $this->initMail();
124 $this->setSubject(
125 sprintf($this->getLanguageText('crs_added_member'), $this->getObjectTitle(true))
126 );
127 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
128 $this->appendBody("\n\n");
129 $this->appendBody(
130 sprintf($this->getLanguageText('crs_added_member_body'), $this->getObjectTitle())
131 );
132 $this->appendBody("\n\n");
133 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
134 $this->appendBody("\n\n");
135 $this->appendBody($this->createPermanentLink());
136 $this->getMail()->appendInstallationSignature(true);
137
138 $this->sendMail(array($rcp));
139 }
140 break;
141
143
144 foreach ($this->getRecipients() as $rcp) {
145 $this->initLanguage($rcp);
146 $this->initMail();
147 $this->setSubject(
148 sprintf($this->getLanguageText('crs_accept_subscriber'), $this->getObjectTitle(true))
149 );
150 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
151 $this->appendBody("\n\n");
152 $this->appendBody(
153 sprintf($this->getLanguageText('crs_accept_subscriber_body'), $this->getObjectTitle())
154 );
155 $this->appendBody("\n\n");
156 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
157 $this->appendBody("\n\n");
158 $this->appendBody($this->createPermanentLink());
159 $this->getMail()->appendInstallationSignature(true);
160
161 $this->sendMail(array($rcp));
162 }
163 break;
164
166
167 foreach ($this->getRecipients() as $rcp) {
168 $this->initLanguage($rcp);
169 $this->initMail();
170 $this->setSubject(
171 sprintf($this->getLanguageText('crs_reject_subscriber'), $this->getObjectTitle(true))
172 );
173 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
174 $this->appendBody("\n\n");
175 $this->appendBody(
176 sprintf($this->getLanguageText('crs_reject_subscriber_body'), $this->getObjectTitle())
177 );
178
179 $this->getMail()->appendInstallationSignature(true);
180
181 $this->sendMail(array($rcp));
182 }
183 break;
184
186 foreach ($this->getRecipients() as $rcp) {
187 $this->initLanguage($rcp);
188 $this->initMail();
189 $this->setSubject(
190 sprintf($this->getLanguageText('crs_status_changed'), $this->getObjectTitle(true))
191 );
192 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
193 $this->appendBody("\n\n");
194 $this->appendBody(
195 sprintf($this->getLanguageText('crs_status_changed_body'), $this->getObjectTitle())
196 );
197
198 $this->appendBody("\n\n");
199 $this->appendBody($this->createCourseStatus($rcp));
200
201 $this->appendBody("\n\n");
202 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
203 $this->appendBody("\n\n");
204 $this->appendBody($this->createPermanentLink());
205
206 $this->getMail()->appendInstallationSignature(true);
207
208 $this->sendMail(array($rcp));
209 }
210 break;
211
213
214 foreach ($this->getRecipients() as $rcp) {
215 $this->initLanguage($rcp);
216 $this->initMail();
217 $this->setSubject(
218 sprintf($this->getLanguageText('crs_dismiss_member'), $this->getObjectTitle(true))
219 );
220 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
221 $this->appendBody("\n\n");
222 $this->appendBody(
223 sprintf($this->getLanguageText('crs_dismiss_member_body'), $this->getObjectTitle())
224 );
225 $this->getMail()->appendInstallationSignature(true);
226 $this->sendMail(array($rcp));
227 }
228 break;
229
231
232 foreach ($this->getRecipients() as $rcp) {
233 $this->initLanguage($rcp);
234 $this->initMail();
235 $this->setSubject(
236 sprintf($this->getLanguageText('crs_blocked_member'), $this->getObjectTitle(true))
237 );
238 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
239 $this->appendBody("\n\n");
240 $this->appendBody(
241 sprintf($this->getLanguageText('crs_blocked_member_body'), $this->getObjectTitle())
242 );
243 $this->getMail()->appendInstallationSignature(true);
244 $this->sendMail(array($rcp));
245 }
246 break;
247
249
250 foreach ($this->getRecipients() as $rcp) {
251 $this->initLanguage($rcp);
252 $this->initMail();
253 $this->setSubject(
254 sprintf($this->getLanguageText('crs_unblocked_member'), $this->getObjectTitle(true))
255 );
256 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
257 $this->appendBody("\n\n");
258 $this->appendBody(
259 sprintf($this->getLanguageText('crs_unblocked_member_body'), $this->getObjectTitle())
260 );
261
262 $this->appendBody("\n\n");
263 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
264 $this->appendBody("\n\n");
265 $this->appendBody($this->createPermanentLink());
266 $this->getMail()->appendInstallationSignature(true);
267
268 $this->sendMail(array($rcp));
269 }
270 break;
271
273
274 foreach ($this->getRecipients() as $rcp) {
275 $this->initLanguage($rcp);
276 $this->initMail();
277 $this->setSubject(
278 sprintf($this->getLanguageText('crs_new_subscription'), $this->getObjectTitle(true))
279 );
280 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
281 $this->appendBody("\n\n");
282
284 $this->appendBody(
285 sprintf(
286 $this->getLanguageText('crs_new_subscription_body'),
287 $this->userToString($info['usr_id']),
288 $this->getObjectTitle()
289 )
290 );
291 $this->appendBody("\n\n");
292 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
293 $this->appendBody("\n\n");
294 $this->appendBody($this->createPermanentLink(array(), 'mem'));
295
296 $this->appendBody("\n\n");
297 $this->appendBody($this->getLanguageText('crs_notification_explanation_admin'));
298
299 $this->getMail()->appendInstallationSignature(true);
300 $this->sendMail(array($rcp));
301 }
302 break;
303
305
306 foreach ($this->getRecipients() as $rcp) {
307 $this->initLanguage($rcp);
308 $this->initMail();
309 $this->setSubject(
310 sprintf($this->getLanguageText('crs_new_subscription_request'), $this->getObjectTitle(true))
311 );
312 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
313 $this->appendBody("\n\n");
314
316 $this->appendBody(
317 sprintf(
318 $this->getLanguageText('crs_new_subscription_request_body'),
319 $this->userToString($info['usr_id']),
320 $this->getObjectTitle()
321 )
322 );
323 $this->appendBody("\n\n");
324 $this->appendBody($this->getLanguageText('crs_new_subscription_request_body2'));
325 $this->appendBody("\n");
326 $this->appendBody($this->createPermanentLink(array(), 'mem'));
327
328 $this->appendBody("\n\n");
329 $this->appendBody($this->getLanguageText('crs_notification_explanation_admin'));
330
331 $this->getMail()->appendInstallationSignature(true);
332 $this->sendMail(array($rcp));
333 }
334 break;
335
337
338 foreach ($this->getRecipients() as $rcp) {
339 $this->initLanguage($rcp);
340 $this->initMail();
341 $this->setSubject(
342 sprintf($this->getLanguageText('crs_cancel_subscription'), $this->getObjectTitle(true))
343 );
344 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
345 $this->appendBody("\n\n");
346
348 $this->appendBody(
349 sprintf(
350 $this->getLanguageText('crs_cancel_subscription_body'),
351 $this->userToString($info['usr_id']),
352 $this->getObjectTitle()
353 )
354 );
355 $this->appendBody("\n\n");
356 $this->appendBody($this->getLanguageText('crs_cancel_subscription_body2'));
357 $this->appendBody("\n\n");
358 $this->appendBody($this->createPermanentLink(array(), 'mem'));
359
360 $this->appendBody("\n\n");
361 $this->appendBody($this->getLanguageText('crs_notification_explanation_admin'));
362
363 $this->getMail()->appendInstallationSignature(true);
364 $this->sendMail(array($rcp));
365 }
366 break;
367
369 foreach ($this->getRecipients() as $rcp) {
370 $this->initLanguage($rcp);
371 $this->initMail();
372 $this->setSubject(
373 sprintf($this->getLanguageText('crs_unsubscribe_member'), $this->getObjectTitle(true))
374 );
375 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
376 $this->appendBody("\n\n");
377 $this->appendBody(
378 sprintf($this->getLanguageText('crs_unsubscribe_member_body'), $this->getObjectTitle())
379 );
380 $this->appendBody("\n\n");
381 $this->appendBody($this->getLanguageText('crs_unsubscribe_member_explanation'));
382 $this->getMail()->appendInstallationSignature(true);
383 $this->sendMail(array($rcp));
384 }
385 break;
386
388
389 foreach ($this->getRecipients() as $rcp) {
390 $this->initLanguage($rcp);
391 $this->initMail();
392 $this->setSubject(
393 sprintf($this->getLanguageText('crs_subscribe_member'), $this->getObjectTitle(true))
394 );
395 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
396 $this->appendBody("\n\n");
397 $this->appendBody(
398 sprintf($this->getLanguageText('crs_subscribe_member_body'), $this->getObjectTitle())
399 );
400
401 $this->appendBody("\n\n");
402 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
403 $this->appendBody("\n\n");
404 $this->appendBody($this->createPermanentLink());
405 $this->getMail()->appendInstallationSignature(true);
406
407 $this->sendMail(array($rcp));
408 }
409 break;
410
412 foreach ($this->getRecipients() as $rcp) {
413 $this->initLanguage($rcp);
414 $this->initMail();
415 $this->setSubject(
416 sprintf($this->getLanguageText('crs_subscribe_wl'), $this->getObjectTitle(true))
417 );
418
419 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
420
422 $this->appendBody("\n\n");
423 $this->appendBody(
424 sprintf(
425 $this->getLanguageText('crs_subscribe_wl_body'),
426 $this->getObjectTitle(),
427 $info['position']
428 )
429 );
430 $this->getMail()->appendInstallationSignature(true);
431 $this->sendMail(array($rcp));
432 }
433 break;
434 }
435 return true;
436 }
437
438 protected function initLanguage(int $a_usr_id): void
439 {
440 parent::initLanguage($a_usr_id);
441 $this->getLanguage()->loadLanguageModule('crs');
442 }
443
444 protected function createCourseStatus(int $a_usr_id): string
445 {
447
448 $body = $this->getLanguageText('crs_new_status') . "\n";
449 $body .= $this->getLanguageText('role') . ': ';
450
451 if ($part->isAdmin($a_usr_id)) {
452 $body .= $this->getLanguageText('crs_admin') . "\n";
453 } elseif ($part->isTutor($a_usr_id)) {
454 $body .= $this->getLanguageText('crs_tutor') . "\n";
455 } else {
456 $body .= $this->getLanguageText('crs_member') . "\n";
457 }
458
459 if ($part->isAdmin($a_usr_id) || $part->isTutor($a_usr_id)) {
460 $body .= $this->getLanguageText('crs_status') . ': ';
461
462 if ($part->isNotificationEnabled($a_usr_id)) {
463 $body .= $this->getLanguageText('crs_notify') . "\n";
464 } else {
465 $body .= $this->getLanguageText('crs_no_notify') . "\n";
466 }
467 } else {
468 $body .= $this->getLanguageText('crs_access') . ': ';
469
470 if ($part->isBlocked($a_usr_id)) {
471 $body .= $this->getLanguageText('crs_blocked') . "\n";
472 } else {
473 $body .= $this->getLanguageText('crs_unblocked') . "\n";
474 }
475 }
476
477 $body .= $this->getLanguageText('crs_passed') . ': ';
478
479 if ($part->hasPassed($a_usr_id)) {
480 $body .= $this->getLanguageText('yes');
481 } else {
482 $body .= $this->getLanguageText('no');
483 }
484 return $body;
485 }
486
491 protected function isNotificationTypeEnabled(int $a_type): bool
492 {
493 return
494 $this->force_sending_mail ||
495 $this->setting->get('mail_crs_member_notification', '1') ||
496 in_array($a_type, $this->permanent_enabled_notifications);
497 }
498}
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
forceSendingMail(bool $a_status)
Force sending mail independent from global setting.
array $permanent_enabled_notifications
Notifications which are not affected by "mail_crs_member_notification" setting because they addresses...
isNotificationTypeEnabled(int $a_type)
get setting "mail_crs_member_notification" and excludes types which are not affected by this setting ...
static _getInstanceByObjId(int $a_obj_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)
const string PROP_CONTEXT_SUBJECT_PREFIX
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjId(int $ref_id)
ILIAS Setting Class.
$info
Definition: entry_point.php:21
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26