ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilGroupMembershipMailNotification.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Mail/classes/class.ilMailNotification.php';
5
13{
14 // v Notifications affect members & co. v
17
20
22
25
29
30 // v Notifications affect admins v
34
41 self::TYPE_NOTIFICATION_REGISTRATION,
42 self::TYPE_NOTIFICATION_REGISTRATION_REQUEST,
43 self::TYPE_NOTIFICATION_UNSUBSCRIBE
44 );
45
46 private $force_sending_mail = false;
47
48
49
50
54 public function __construct()
55 {
57 }
58
62 protected function initMail() : ilMail
63 {
64 parent::initMail();
65 $this->mail = $this->mail->withContextParameters([
69 ''
70 ),
71 ]);
72
73 return $this->mail;
74 }
75
80 public function forceSendingMail($a_status)
81 {
82 $this->force_sending_mail = $a_status;
83 }
84
85
86
91 public function send()
92 {
93 global $DIC;
94
95 $logger = $DIC->logger()->grp();
96
97 if (!$this->isNotificationTypeEnabled($this->getType())) {
98 $logger->info('Membership mail disabled globally.');
99 return false;
100 }
101
102 if (
103 $this->getType() == self::TYPE_ADMISSION_MEMBER
104 ) {
106 if (!$obj instanceof \ilObjGroup) {
107 $logger->warning('Refid: ' . $this->getRefId() . ' is not of type grp.');
108 return false;
109 }
110 if (!$obj->getAutoNotification()) {
111 if (!$this->force_sending_mail) {
112 $logger->info('Sending welcome mail disabled locally.');
113 return false;
114 }
115 }
116 }
117
118 // parent::send();
119
120 switch ($this->getType()) {
122
123 foreach ($this->getRecipients() as $rcp) {
124 $this->initLanguage($rcp);
125 $this->initMail();
126 $this->setSubject(
127 sprintf($this->getLanguageText('grp_mail_admission_new_sub'), $this->getObjectTitle(true))
128 );
129 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
130 $this->appendBody("\n\n");
131 $this->appendBody(
132 sprintf($this->getLanguageText('grp_mail_admission_new_bod'), $this->getObjectTitle())
133 );
134 $this->appendBody("\n\n");
135 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
136 $this->appendBody("\n\n");
137 $this->appendBody($this->createPermanentLink());
138 $this->getMail()->appendInstallationSignature(true);
139
140 $this->sendMail(array($rcp));
141 }
142 break;
143
145
146 foreach ($this->getRecipients() as $rcp) {
147 $this->initLanguage($rcp);
148 $this->initMail();
149 $this->setSubject(
150 sprintf($this->getLanguageText('grp_mail_dismiss_sub'), $this->getObjectTitle(true))
151 );
152 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
153 $this->appendBody("\n\n");
154 $this->appendBody(
155 sprintf($this->getLanguageText('grp_mail_dismiss_bod'), $this->getObjectTitle())
156 );
157 $this->getMail()->appendInstallationSignature(true);
158 $this->sendMail(array($rcp));
159 }
160 break;
161
162
164
165 foreach ($this->getRecipients() as $rcp) {
166 $this->initLanguage($rcp);
167 $this->initMail();
168 $this->setSubject(
169 sprintf($this->getLanguageText('grp_mail_notification_reg_sub'), $this->getObjectTitle(true))
170 );
171 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
172 $this->appendBody("\n\n");
173
174 $info = $this->getAdditionalInformation();
175 $this->appendBody(
176 sprintf(
177 $this->getLanguageText('grp_mail_notification_reg_bod'),
178 $this->userToString($info['usr_id']),
179 $this->getObjectTitle()
180 )
181 );
182 $this->appendBody("\n\n");
183 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
184 $this->appendBody("\n\n");
185 $this->appendBody($this->createPermanentLink(array(), '_mem'));
186
187 $this->appendBody("\n\n");
188 $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
189
190 $this->getMail()->appendInstallationSignature(true);
191 $this->sendMail(array($rcp));
192 }
193 break;
194
196
197 foreach ($this->getRecipients() as $rcp) {
198 $this->initLanguage($rcp);
199 $this->initMail();
200 $this->setSubject(
201 sprintf($this->getLanguageText('grp_mail_unsubscribe_member_sub'), $this->getObjectTitle(true))
202 );
203 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
204 $this->appendBody("\n\n");
205 $this->appendBody(
206 sprintf($this->getLanguageText('grp_mail_unsubscribe_member_bod'), $this->getObjectTitle())
207 );
208 $this->getMail()->appendInstallationSignature(true);
209 $this->sendMail(array($rcp));
210 }
211 break;
212
214
215 foreach ($this->getRecipients() as $rcp) {
216 $this->initLanguage($rcp);
217 $this->initMail();
218 $this->setSubject(
219 sprintf($this->getLanguageText('grp_mail_notification_unsub_sub'), $this->getObjectTitle(true))
220 );
221 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
222 $this->appendBody("\n\n");
223
224 $info = $this->getAdditionalInformation();
225 $this->appendBody(
226 sprintf(
227 $this->getLanguageText('grp_mail_notification_unsub_bod'),
228 $this->userToString($info['usr_id']),
229 $this->getObjectTitle()
230 )
231 );
232 $this->appendBody("\n\n");
233 $this->appendBody($this->getLanguageText('grp_mail_notification_unsub_bod2'));
234 $this->appendBody("\n\n");
235 $this->appendBody($this->createPermanentLink(array(), '_mem'));
236
237 $this->appendBody("\n\n");
238 $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
239
240 $this->getMail()->appendInstallationSignature(true);
241 $this->sendMail(array($rcp));
242 }
243 break;
244
245
247
248 foreach ($this->getRecipients() as $rcp) {
249 $this->initLanguage($rcp);
250 $this->initMail();
251 $this->setSubject(
252 sprintf($this->getLanguageText('grp_mail_subscribe_member_sub'), $this->getObjectTitle(true))
253 );
254 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
255 $this->appendBody("\n\n");
256 $this->appendBody(
257 sprintf($this->getLanguageText('grp_mail_subscribe_member_bod'), $this->getObjectTitle())
258 );
259
260 $this->appendBody("\n\n");
261 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
262 $this->appendBody("\n\n");
263 $this->appendBody($this->createPermanentLink());
264 $this->getMail()->appendInstallationSignature(true);
265
266 $this->sendMail(array($rcp));
267 }
268 break;
269
270
272
273 foreach ($this->getRecipients() as $rcp) {
274 $this->initLanguage($rcp);
275 $this->initMail();
276 $this->setSubject(
277 sprintf($this->getLanguageText('grp_mail_notification_reg_req_sub'), $this->getObjectTitle(true))
278 );
279 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
280 $this->appendBody("\n\n");
281
282 $info = $this->getAdditionalInformation();
283 $this->appendBody(
284 sprintf(
285 $this->getLanguageText('grp_mail_notification_reg_req_bod'),
286 $this->userToString($info['usr_id']),
287 $this->getObjectTitle()
288 )
289 );
290 $this->appendBody("\n\n");
291 $this->appendBody($this->getLanguageText('grp_mail_notification_reg_req_bod2'));
292 $this->appendBody("\n");
293 $this->appendBody($this->createPermanentLink(array(), '_mem'));
294
295 $this->appendBody("\n\n");
296 $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
297
298 $this->getMail()->appendInstallationSignature(true);
299 $this->sendMail(array($rcp));
300 }
301 break;
302
304
305 foreach ($this->getRecipients() as $rcp) {
306 $this->initLanguage($rcp);
307 $this->initMail();
308 $this->setSubject(
309 sprintf($this->getLanguageText('grp_mail_sub_dec_sub'), $this->getObjectTitle(true))
310 );
311 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
312 $this->appendBody("\n\n");
313 $this->appendBody(
314 sprintf($this->getLanguageText('grp_mail_sub_dec_bod'), $this->getObjectTitle())
315 );
316
317 $this->getMail()->appendInstallationSignature(true);
318
319 $this->sendMail(array($rcp));
320 }
321 break;
322
324
325 foreach ($this->getRecipients() as $rcp) {
326 $this->initLanguage($rcp);
327 $this->initMail();
328 $this->setSubject(
329 sprintf($this->getLanguageText('grp_mail_sub_acc_sub'), $this->getObjectTitle(true))
330 );
331 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
332 $this->appendBody("\n\n");
333 $this->appendBody(
334 sprintf($this->getLanguageText('grp_mail_sub_acc_bod'), $this->getObjectTitle())
335 );
336 $this->appendBody("\n\n");
337 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
338 $this->appendBody("\n\n");
339 $this->appendBody($this->createPermanentLink());
340 $this->getMail()->appendInstallationSignature(true);
341
342 $this->sendMail(array($rcp));
343 }
344 break;
345
347 foreach ($this->getRecipients() as $rcp) {
348 $this->initLanguage($rcp);
349 $this->initMail();
350 $this->setSubject(
351 sprintf($this->getLanguageText('grp_mail_wl_sub'), $this->getObjectTitle(true))
352 );
353
354 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
355
356 $info = $this->getAdditionalInformation();
357 $this->appendBody("\n\n");
358 $this->appendBody(
359 sprintf(
360 $this->getLanguageText('grp_mail_wl_bod'),
361 $this->getObjectTitle(),
362 $info['position']
363 )
364 );
365 $this->getMail()->appendInstallationSignature(true);
366 $this->sendMail(array($rcp));
367 }
368 break;
369
370
372 foreach ($this->getRecipients() as $rcp) {
373 $this->initLanguage($rcp);
374 $this->initMail();
375 $this->setSubject(
376 sprintf($this->getLanguageText('grp_mail_status_sub'), $this->getObjectTitle(true))
377 );
378 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
379 $this->appendBody("\n\n");
380 $this->appendBody(
381 sprintf($this->getLanguageText('grp_mail_status_bod'), $this->getObjectTitle())
382 );
383
384 $this->appendBody("\n\n");
385 $this->appendBody($this->createGroupStatus($rcp));
386
387 $this->appendBody("\n\n");
388 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
389 $this->appendBody("\n\n");
390 $this->appendBody($this->createPermanentLink());
391
392 $this->getMail()->appendInstallationSignature(true);
393
394 $this->sendMail(array($rcp));
395 }
396 break;
397
398 }
399 return true;
400 }
401
407 protected function initLanguage($a_usr_id)
408 {
409 parent::initLanguage($a_usr_id);
410 $this->getLanguage()->loadLanguageModule('grp');
411 }
412
418 protected function createGroupStatus($a_usr_id)
419 {
421
422 $body = $this->getLanguageText('grp_new_status') . "\n";
423 $body .= $this->getLanguageText('role') . ': ';
424
425
426 if ($part->isAdmin($a_usr_id)) {
427 $body .= $this->getLanguageText('il_grp_admin') . "\n";
428 } else {
429 $body .= $this->getLanguageText('il_grp_member') . "\n";
430 }
431
432 if ($part->isAdmin($a_usr_id)) {
433 $body .= $this->getLanguageText('grp_notification') . ': ';
434
435 if ($part->isNotificationEnabled($a_usr_id)) {
436 $body .= $this->getLanguageText('grp_notify_on') . "\n";
437 } else {
438 $body .= $this->getLanguageText('grp_notify_off') . "\n";
439 }
440 }
441 return $body;
442 }
443
451 protected function isNotificationTypeEnabled($a_type)
452 {
453 global $DIC;
454
455 $ilSetting = $DIC['ilSetting'];
456
457 return
458 $this->force_sending_mail ||
459 $ilSetting->get('mail_grp_member_notification', true) ||
460 in_array($a_type, $this->permanent_enabled_notifications);
461 }
462}
An exception for terminatinating execution or to throw for unit testing.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
isNotificationTypeEnabled($a_type)
get setting "mail_grp_member_notification" and excludes types which are not affected by this setting ...
$permanent_enabled_notifications
Notifications which are not affected by "mail_grp_member_notification" setting because they addresses...
forceSendingMail($a_status)
Force sending mail independent from global setting.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Base class for course/group mail notifications.
appendBody($a_body)
Append body text.
getType()
Get notification type.
sendMail(array $a_rcp, $a_parse_recipients=true)
getRecipients()
get array of recipients
getObjectTitle($a_shorten=false)
createPermanentLink($a_params=array(), $a_append='')
static getSalutation($a_usr_id, ilLanguage $a_language=null)
const PROP_CONTEXT_SUBJECT_PREFIX
Class ilObjGroup.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjId($a_id)
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:17