ILIAS  release_8 Revision v8.24
class.ilGroupMembershipMailNotification.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5
12{
13 // v Notifications affect members & co. v
14 public const TYPE_ADMISSION_MEMBER = 20;
15 public const TYPE_DISMISS_MEMBER = 21;
16
19
20 public const TYPE_STATUS_CHANGED = 24;
21
22 public const TYPE_BLOCKED_MEMBER = 25;
23 public const TYPE_UNBLOCKED_MEMBER = 26;
24
25 public const TYPE_UNSUBSCRIBE_MEMBER = 27;
26 public const TYPE_SUBSCRIBE_MEMBER = 28;
27 public const TYPE_WAITING_LIST_MEMBER = 29;
28
29 // Notifications affect admins
33
39 protected array $permanent_enabled_notifications = array(
40 self::TYPE_NOTIFICATION_REGISTRATION,
41 self::TYPE_NOTIFICATION_REGISTRATION_REQUEST,
42 self::TYPE_NOTIFICATION_UNSUBSCRIBE
43 );
44
45 private bool $force_sending_mail = false;
46
49
50
51 public function __construct(bool $a_is_personal_workspace = false)
52 {
53 global $DIC;
54
55 $this->logger = $DIC->logger()->grp();
56 $this->settings = $DIC->settings();
57 parent::__construct($a_is_personal_workspace);
58 }
59
63 protected function initMail(): ilMail
64 {
65 parent::initMail();
66 $this->mail = $this->mail->withContextParameters([
70 ''
71 ),
72 ]);
73
74 return $this->mail;
75 }
76
80 public function forceSendingMail(bool $a_status): void
81 {
82 $this->force_sending_mail = $a_status;
83 }
84
85
86
87 public function send(): bool
88 {
89 if (!$this->isNotificationTypeEnabled($this->getType())) {
90 $this->logger->info('Membership mail disabled globally.');
91 return false;
92 }
93
94 if (
95 $this->getType() == self::TYPE_ADMISSION_MEMBER
96 ) {
98 if (!$obj instanceof \ilObjGroup) {
99 $this->logger->warning('Refid: ' . $this->getRefId() . ' is not of type grp.');
100 return false;
101 }
102 if (!$obj->getAutoNotification()) {
103 if (!$this->force_sending_mail) {
104 $this->logger->info('Sending welcome mail disabled locally.');
105 return false;
106 }
107 }
108 }
109
110 // parent::send();
111
112 switch ($this->getType()) {
114
115 foreach ($this->getRecipients() as $rcp) {
116 $this->initLanguage($rcp);
117 $this->initMail();
118 $this->setSubject(
119 sprintf($this->getLanguageText('grp_mail_admission_new_sub'), $this->getObjectTitle(true))
120 );
121 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
122 $this->appendBody("\n\n");
123 $this->appendBody(
124 sprintf($this->getLanguageText('grp_mail_admission_new_bod'), $this->getObjectTitle())
125 );
126 $this->appendBody("\n\n");
127 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
128 $this->appendBody("\n\n");
129 $this->appendBody($this->createPermanentLink());
130 $this->getMail()->appendInstallationSignature(true);
131
132 $this->sendMail(array($rcp));
133 }
134 break;
135
137
138 foreach ($this->getRecipients() as $rcp) {
139 $this->initLanguage($rcp);
140 $this->initMail();
141 $this->setSubject(
142 sprintf($this->getLanguageText('grp_mail_dismiss_sub'), $this->getObjectTitle(true))
143 );
144 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
145 $this->appendBody("\n\n");
146 $this->appendBody(
147 sprintf($this->getLanguageText('grp_mail_dismiss_bod'), $this->getObjectTitle())
148 );
149 $this->getMail()->appendInstallationSignature(true);
150 $this->sendMail(array($rcp));
151 }
152 break;
153
154
156
157 foreach ($this->getRecipients() as $rcp) {
158 $this->initLanguage($rcp);
159 $this->initMail();
160 $this->setSubject(
161 sprintf($this->getLanguageText('grp_mail_notification_reg_sub'), $this->getObjectTitle(true))
162 );
163 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
164 $this->appendBody("\n\n");
165
166 $info = $this->getAdditionalInformation();
167 $this->appendBody(
168 sprintf(
169 $this->getLanguageText('grp_mail_notification_reg_bod'),
170 $this->userToString($info['usr_id']),
171 $this->getObjectTitle()
172 )
173 );
174 $this->appendBody("\n\n");
175 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
176 $this->appendBody("\n\n");
177 $this->appendBody($this->createPermanentLink(array(), '_mem'));
178
179 $this->appendBody("\n\n");
180 $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
181
182 $this->getMail()->appendInstallationSignature(true);
183 $this->sendMail(array($rcp));
184 }
185 break;
186
188
189 foreach ($this->getRecipients() as $rcp) {
190 $this->initLanguage($rcp);
191 $this->initMail();
192 $this->setSubject(
193 sprintf($this->getLanguageText('grp_mail_unsubscribe_member_sub'), $this->getObjectTitle(true))
194 );
195 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
196 $this->appendBody("\n\n");
197 $this->appendBody(
198 sprintf($this->getLanguageText('grp_mail_unsubscribe_member_bod'), $this->getObjectTitle())
199 );
200 $this->getMail()->appendInstallationSignature(true);
201 $this->sendMail(array($rcp));
202 }
203 break;
204
206
207 foreach ($this->getRecipients() as $rcp) {
208 $this->initLanguage($rcp);
209 $this->initMail();
210 $this->setSubject(
211 sprintf($this->getLanguageText('grp_mail_notification_unsub_sub'), $this->getObjectTitle(true))
212 );
213 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
214 $this->appendBody("\n\n");
215
216 $info = $this->getAdditionalInformation();
217 $this->appendBody(
218 sprintf(
219 $this->getLanguageText('grp_mail_notification_unsub_bod'),
220 $this->userToString($info['usr_id']),
221 $this->getObjectTitle()
222 )
223 );
224 $this->appendBody("\n\n");
225 $this->appendBody($this->getLanguageText('grp_mail_notification_unsub_bod2'));
226 $this->appendBody("\n\n");
227 $this->appendBody($this->createPermanentLink(array(), '_mem'));
228
229 $this->appendBody("\n\n");
230 $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
231
232 $this->getMail()->appendInstallationSignature(true);
233 $this->sendMail(array($rcp));
234 }
235 break;
236
237
239
240 foreach ($this->getRecipients() as $rcp) {
241 $this->initLanguage($rcp);
242 $this->initMail();
243 $this->setSubject(
244 sprintf($this->getLanguageText('grp_mail_subscribe_member_sub'), $this->getObjectTitle(true))
245 );
246 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
247 $this->appendBody("\n\n");
248 $this->appendBody(
249 sprintf($this->getLanguageText('grp_mail_subscribe_member_bod'), $this->getObjectTitle())
250 );
251
252 $this->appendBody("\n\n");
253 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
254 $this->appendBody("\n\n");
255 $this->appendBody($this->createPermanentLink());
256 $this->getMail()->appendInstallationSignature(true);
257
258 $this->sendMail(array($rcp));
259 }
260 break;
261
262
264
265 foreach ($this->getRecipients() as $rcp) {
266 $this->initLanguage($rcp);
267 $this->initMail();
268 $this->setSubject(
269 sprintf($this->getLanguageText('grp_mail_notification_reg_req_sub'), $this->getObjectTitle(true))
270 );
271 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
272 $this->appendBody("\n\n");
273
274 $info = $this->getAdditionalInformation();
275 $this->appendBody(
276 sprintf(
277 $this->getLanguageText('grp_mail_notification_reg_req_bod'),
278 $this->userToString($info['usr_id']),
279 $this->getObjectTitle()
280 )
281 );
282 $this->appendBody("\n\n");
283 $this->appendBody($this->getLanguageText('grp_mail_notification_reg_req_bod2'));
284 $this->appendBody("\n");
285 $this->appendBody($this->createPermanentLink(array(), '_mem'));
286
287 $this->appendBody("\n\n");
288 $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
289
290 $this->getMail()->appendInstallationSignature(true);
291 $this->sendMail(array($rcp));
292 }
293 break;
294
296
297 foreach ($this->getRecipients() as $rcp) {
298 $this->initLanguage($rcp);
299 $this->initMail();
300 $this->setSubject(
301 sprintf($this->getLanguageText('grp_mail_sub_dec_sub'), $this->getObjectTitle(true))
302 );
303 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
304 $this->appendBody("\n\n");
305 $this->appendBody(
306 sprintf($this->getLanguageText('grp_mail_sub_dec_bod'), $this->getObjectTitle())
307 );
308
309 $this->getMail()->appendInstallationSignature(true);
310
311 $this->sendMail(array($rcp));
312 }
313 break;
314
316
317 foreach ($this->getRecipients() as $rcp) {
318 $this->initLanguage($rcp);
319 $this->initMail();
320 $this->setSubject(
321 sprintf($this->getLanguageText('grp_mail_sub_acc_sub'), $this->getObjectTitle(true))
322 );
323 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
324 $this->appendBody("\n\n");
325 $this->appendBody(
326 sprintf($this->getLanguageText('grp_mail_sub_acc_bod'), $this->getObjectTitle())
327 );
328 $this->appendBody("\n\n");
329 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
330 $this->appendBody("\n\n");
331 $this->appendBody($this->createPermanentLink());
332 $this->getMail()->appendInstallationSignature(true);
333
334 $this->sendMail(array($rcp));
335 }
336 break;
337
339 foreach ($this->getRecipients() as $rcp) {
340 $this->initLanguage($rcp);
341 $this->initMail();
342 $this->setSubject(
343 sprintf($this->getLanguageText('grp_mail_wl_sub'), $this->getObjectTitle(true))
344 );
345
346 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
347
348 $info = $this->getAdditionalInformation();
349 $this->appendBody("\n\n");
350 $this->appendBody(
351 sprintf(
352 $this->getLanguageText('grp_mail_wl_bod'),
353 $this->getObjectTitle(),
354 $info['position']
355 )
356 );
357 $this->getMail()->appendInstallationSignature(true);
358 $this->sendMail(array($rcp));
359 }
360 break;
361
362
364 foreach ($this->getRecipients() as $rcp) {
365 $this->initLanguage($rcp);
366 $this->initMail();
367 $this->setSubject(
368 sprintf($this->getLanguageText('grp_mail_status_sub'), $this->getObjectTitle(true))
369 );
370 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
371 $this->appendBody("\n\n");
372 $this->appendBody(
373 sprintf($this->getLanguageText('grp_mail_status_bod'), $this->getObjectTitle())
374 );
375
376 $this->appendBody("\n\n");
377 $this->appendBody($this->createGroupStatus($rcp));
378
379 $this->appendBody("\n\n");
380 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
381 $this->appendBody("\n\n");
382 $this->appendBody($this->createPermanentLink());
383
384 $this->getMail()->appendInstallationSignature(true);
385
386 $this->sendMail(array($rcp));
387 }
388 break;
389 }
390 return true;
391 }
392
396 protected function initLanguage(int $a_usr_id): void
397 {
398 parent::initLanguage($a_usr_id);
399 $this->getLanguage()->loadLanguageModule('grp');
400 }
401
402 protected function createGroupStatus(int $a_usr_id): string
403 {
405
406 $body = $this->getLanguageText('grp_new_status') . "\n";
407 $body .= $this->getLanguageText('role') . ': ';
408
409
410 if ($part->isAdmin($a_usr_id)) {
411 $body .= $this->getLanguageText('il_grp_admin') . "\n";
412 } else {
413 $body .= $this->getLanguageText('il_grp_member') . "\n";
414 }
415
416 if ($part->isAdmin($a_usr_id)) {
417 $body .= $this->getLanguageText('grp_notification') . ': ';
418
419 if ($part->isNotificationEnabled($a_usr_id)) {
420 $body .= $this->getLanguageText('grp_notify_on') . "\n";
421 } else {
422 $body .= $this->getLanguageText('grp_notify_off') . "\n";
423 }
424 }
425 return $body;
426 }
427
432 protected function isNotificationTypeEnabled(int $a_type): bool
433 {
434 return
435 $this->force_sending_mail ||
436 $this->settings->get('mail_grp_member_notification', "1") ||
437 in_array($a_type, $this->permanent_enabled_notifications);
438 }
439}
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.
Base class for course/group mail notifications.
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)
const PROP_CONTEXT_SUBJECT_PREFIX
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc