ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGroupMembershipMailNotification.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
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 // Notifications affect admins
47
53 protected array $permanent_enabled_notifications = array(
54 self::TYPE_NOTIFICATION_REGISTRATION,
55 self::TYPE_NOTIFICATION_REGISTRATION_REQUEST,
56 self::TYPE_NOTIFICATION_UNSUBSCRIBE
57 );
58
59 private bool $force_sending_mail = false;
60
63
64
65 public function __construct(bool $a_is_personal_workspace = false)
66 {
67 global $DIC;
68
69 $this->logger = $DIC->logger()->grp();
70 $this->settings = $DIC->settings();
71 parent::__construct($a_is_personal_workspace);
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
100
101 public function send(): bool
102 {
103 if (!$this->isNotificationTypeEnabled($this->getType())) {
104 $this->logger->info('Membership mail disabled globally.');
105 return false;
106 }
107
108 if (
109 $this->getType() == self::TYPE_ADMISSION_MEMBER
110 ) {
112 if (!$obj instanceof \ilObjGroup) {
113 $this->logger->warning('Refid: ' . $this->getRefId() . ' is not of type grp.');
114 return false;
115 }
116 if (!$obj->getAutoNotification()) {
117 if (!$this->force_sending_mail) {
118 $this->logger->info('Sending welcome mail disabled locally.');
119 return false;
120 }
121 }
122 }
123
124 // parent::send();
125
126 switch ($this->getType()) {
128
129 foreach ($this->getRecipients() as $rcp) {
130 $this->initLanguage($rcp);
131 $this->initMail();
132 $this->setSubject(
133 sprintf($this->getLanguageText('grp_mail_admission_new_sub'), $this->getObjectTitle(true))
134 );
135 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
136 $this->appendBody("\n\n");
137 $this->appendBody(
138 sprintf($this->getLanguageText('grp_mail_admission_new_bod'), $this->getObjectTitle())
139 );
140 $this->appendBody("\n\n");
141 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
142 $this->appendBody("\n\n");
143 $this->appendBody($this->createPermanentLink());
144 $this->getMail()->appendInstallationSignature(true);
145
146 $this->sendMail(array($rcp));
147 }
148 break;
149
151
152 foreach ($this->getRecipients() as $rcp) {
153 $this->initLanguage($rcp);
154 $this->initMail();
155 $this->setSubject(
156 sprintf($this->getLanguageText('grp_mail_dismiss_sub'), $this->getObjectTitle(true))
157 );
158 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
159 $this->appendBody("\n\n");
160 $this->appendBody(
161 sprintf($this->getLanguageText('grp_mail_dismiss_bod'), $this->getObjectTitle())
162 );
163 $this->getMail()->appendInstallationSignature(true);
164 $this->sendMail(array($rcp));
165 }
166 break;
167
168
170
171 foreach ($this->getRecipients() as $rcp) {
172 $this->initLanguage($rcp);
173 $this->initMail();
174 $this->setSubject(
175 sprintf($this->getLanguageText('grp_mail_notification_reg_sub'), $this->getObjectTitle(true))
176 );
177 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
178 $this->appendBody("\n\n");
179
181 $this->appendBody(
182 sprintf(
183 $this->getLanguageText('grp_mail_notification_reg_bod'),
184 $this->userToString($info['usr_id']),
185 $this->getObjectTitle()
186 )
187 );
188 $this->appendBody("\n\n");
189 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
190 $this->appendBody("\n\n");
191 $this->appendBody($this->createPermanentLink(array(), 'mem'));
192
193 $this->appendBody("\n\n");
194 $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
195
196 $this->getMail()->appendInstallationSignature(true);
197 $this->sendMail(array($rcp));
198 }
199 break;
200
202
203 foreach ($this->getRecipients() as $rcp) {
204 $this->initLanguage($rcp);
205 $this->initMail();
206 $this->setSubject(
207 sprintf($this->getLanguageText('grp_mail_unsubscribe_member_sub'), $this->getObjectTitle(true))
208 );
209 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
210 $this->appendBody("\n\n");
211 $this->appendBody(
212 sprintf($this->getLanguageText('grp_mail_unsubscribe_member_bod'), $this->getObjectTitle())
213 );
214 $this->getMail()->appendInstallationSignature(true);
215 $this->sendMail(array($rcp));
216 }
217 break;
218
220
221 foreach ($this->getRecipients() as $rcp) {
222 $this->initLanguage($rcp);
223 $this->initMail();
224 $this->setSubject(
225 sprintf($this->getLanguageText('grp_mail_notification_unsub_sub'), $this->getObjectTitle(true))
226 );
227 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
228 $this->appendBody("\n\n");
229
231 $this->appendBody(
232 sprintf(
233 $this->getLanguageText('grp_mail_notification_unsub_bod'),
234 $this->userToString($info['usr_id']),
235 $this->getObjectTitle()
236 )
237 );
238 $this->appendBody("\n\n");
239 $this->appendBody($this->getLanguageText('grp_mail_notification_unsub_bod2'));
240 $this->appendBody("\n\n");
241 $this->appendBody($this->createPermanentLink(array(), 'mem'));
242
243 $this->appendBody("\n\n");
244 $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
245
246 $this->getMail()->appendInstallationSignature(true);
247 $this->sendMail(array($rcp));
248 }
249 break;
250
251
253
254 foreach ($this->getRecipients() as $rcp) {
255 $this->initLanguage($rcp);
256 $this->initMail();
257 $this->setSubject(
258 sprintf($this->getLanguageText('grp_mail_subscribe_member_sub'), $this->getObjectTitle(true))
259 );
260 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
261 $this->appendBody("\n\n");
262 $this->appendBody(
263 sprintf($this->getLanguageText('grp_mail_subscribe_member_bod'), $this->getObjectTitle())
264 );
265
266 $this->appendBody("\n\n");
267 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
268 $this->appendBody("\n\n");
269 $this->appendBody($this->createPermanentLink());
270 $this->getMail()->appendInstallationSignature(true);
271
272 $this->sendMail(array($rcp));
273 }
274 break;
275
276
278
279 foreach ($this->getRecipients() as $rcp) {
280 $this->initLanguage($rcp);
281 $this->initMail();
282 $this->setSubject(
283 sprintf($this->getLanguageText('grp_mail_notification_reg_req_sub'), $this->getObjectTitle(true))
284 );
285 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
286 $this->appendBody("\n\n");
287
289 $this->appendBody(
290 sprintf(
291 $this->getLanguageText('grp_mail_notification_reg_req_bod'),
292 $this->userToString($info['usr_id']),
293 $this->getObjectTitle()
294 )
295 );
296 $this->appendBody("\n\n");
297 $this->appendBody($this->getLanguageText('grp_mail_notification_reg_req_bod2'));
298 $this->appendBody("\n");
299 $this->appendBody($this->createPermanentLink(array(), 'mem'));
300
301 $this->appendBody("\n\n");
302 $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
303
304 $this->getMail()->appendInstallationSignature(true);
305 $this->sendMail(array($rcp));
306 }
307 break;
308
310
311 foreach ($this->getRecipients() as $rcp) {
312 $this->initLanguage($rcp);
313 $this->initMail();
314 $this->setSubject(
315 sprintf($this->getLanguageText('grp_mail_sub_dec_sub'), $this->getObjectTitle(true))
316 );
317 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
318 $this->appendBody("\n\n");
319 $this->appendBody(
320 sprintf($this->getLanguageText('grp_mail_sub_dec_bod'), $this->getObjectTitle())
321 );
322
323 $this->getMail()->appendInstallationSignature(true);
324
325 $this->sendMail(array($rcp));
326 }
327 break;
328
330
331 foreach ($this->getRecipients() as $rcp) {
332 $this->initLanguage($rcp);
333 $this->initMail();
334 $this->setSubject(
335 sprintf($this->getLanguageText('grp_mail_sub_acc_sub'), $this->getObjectTitle(true))
336 );
337 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
338 $this->appendBody("\n\n");
339 $this->appendBody(
340 sprintf($this->getLanguageText('grp_mail_sub_acc_bod'), $this->getObjectTitle())
341 );
342 $this->appendBody("\n\n");
343 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
344 $this->appendBody("\n\n");
345 $this->appendBody($this->createPermanentLink());
346 $this->getMail()->appendInstallationSignature(true);
347
348 $this->sendMail(array($rcp));
349 }
350 break;
351
353 foreach ($this->getRecipients() as $rcp) {
354 $this->initLanguage($rcp);
355 $this->initMail();
356 $this->setSubject(
357 sprintf($this->getLanguageText('grp_mail_wl_sub'), $this->getObjectTitle(true))
358 );
359
360 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
361
363 $this->appendBody("\n\n");
364 $this->appendBody(
365 sprintf(
366 $this->getLanguageText('grp_mail_wl_bod'),
367 $this->getObjectTitle(),
368 $info['position']
369 )
370 );
371 $this->getMail()->appendInstallationSignature(true);
372 $this->sendMail(array($rcp));
373 }
374 break;
375
376
378 foreach ($this->getRecipients() as $rcp) {
379 $this->initLanguage($rcp);
380 $this->initMail();
381 $this->setSubject(
382 sprintf($this->getLanguageText('grp_mail_status_sub'), $this->getObjectTitle(true))
383 );
384 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
385 $this->appendBody("\n\n");
386 $this->appendBody(
387 sprintf($this->getLanguageText('grp_mail_status_bod'), $this->getObjectTitle())
388 );
389
390 $this->appendBody("\n\n");
391 $this->appendBody($this->createGroupStatus($rcp));
392
393 $this->appendBody("\n\n");
394 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
395 $this->appendBody("\n\n");
396 $this->appendBody($this->createPermanentLink());
397
398 $this->getMail()->appendInstallationSignature(true);
399
400 $this->sendMail(array($rcp));
401 }
402 break;
403 }
404 return true;
405 }
406
410 protected function initLanguage(int $a_usr_id): void
411 {
412 parent::initLanguage($a_usr_id);
413 $this->getLanguage()->loadLanguageModule('grp');
414 }
415
416 protected function createGroupStatus(int $a_usr_id): string
417 {
419
420 $body = $this->getLanguageText('grp_new_status') . "\n";
421 $body .= $this->getLanguageText('role') . ': ';
422
423
424 if ($part->isAdmin($a_usr_id)) {
425 $body .= $this->getLanguageText('il_grp_admin') . "\n";
426 } else {
427 $body .= $this->getLanguageText('il_grp_member') . "\n";
428 }
429
430 if ($part->isAdmin($a_usr_id)) {
431 $body .= $this->getLanguageText('grp_notification') . ': ';
432
433 if ($part->isNotificationEnabled($a_usr_id)) {
434 $body .= $this->getLanguageText('grp_notify_on') . "\n";
435 } else {
436 $body .= $this->getLanguageText('grp_notify_off') . "\n";
437 }
438 }
439 return $body;
440 }
441
446 protected function isNotificationTypeEnabled(int $a_type): bool
447 {
448 return
449 $this->force_sending_mail ||
450 $this->settings->get('mail_grp_member_notification', "1") ||
451 in_array($a_type, $this->permanent_enabled_notifications);
452 }
453}
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
isNotificationTypeEnabled(int $a_type)
get setting "mail_grp_member_notification" and excludes types which are not affected by this setting ...
forceSendingMail(bool $a_status)
Force sending mail independent from global setting.
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
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)
const string PROP_CONTEXT_SUBJECT_PREFIX
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
Class ilObjGroup.
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