ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCourseMembershipMailNotification.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
52 public function __construct()
53 {
55 }
56
60 protected function initMail() : ilMail
61 {
62 parent::initMail();
63 $this->mail = $this->mail->withContextParameters([
67 ''
68 ),
69 ]);
70
71 return $this->mail;
72 }
73
78 public function forceSendingMail($a_status)
79 {
80 $this->force_sending_mail = $a_status;
81 }
82
87 public function send()
88 {
89 if (
90 (int) $this->getRefId() &&
91 in_array($this->getType(), array(self::TYPE_ADMISSION_MEMBER))) {
92 $obj = ilObjectFactory::getInstanceByRefId((int) $this->getRefId());
93
94 if ($obj->getAutoNotification() == false) {
95 if (!$this->force_sending_mail) {
96 return false;
97 }
98 }
99 }
100
101 if (!$this->isNotificationTypeEnabled($this->getType())) {
102 return false;
103 }
104
105 // #11359
106 // parent::send();
107
108 switch ($this->getType()) {
110
111 foreach ($this->getRecipients() as $rcp) {
112 $this->initLanguage($rcp);
113 $this->initMail();
114 $this->setSubject(
115 sprintf($this->getLanguageText('crs_added_member'), $this->getObjectTitle(true))
116 );
117 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
118 $this->appendBody("\n\n");
119 $this->appendBody(
120 sprintf($this->getLanguageText('crs_added_member_body'), $this->getObjectTitle())
121 );
122 $this->appendBody("\n\n");
123 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
124 $this->appendBody("\n\n");
125 $this->appendBody($this->createPermanentLink());
126 $this->getMail()->appendInstallationSignature(true);
127
128 $this->sendMail(array($rcp));
129 }
130 break;
131
132
134
135 foreach ($this->getRecipients() as $rcp) {
136 $this->initLanguage($rcp);
137 $this->initMail();
138 $this->setSubject(
139 sprintf($this->getLanguageText('crs_accept_subscriber'), $this->getObjectTitle(true))
140 );
141 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
142 $this->appendBody("\n\n");
143 $this->appendBody(
144 sprintf($this->getLanguageText('crs_accept_subscriber_body'), $this->getObjectTitle())
145 );
146 $this->appendBody("\n\n");
147 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
148 $this->appendBody("\n\n");
149 $this->appendBody($this->createPermanentLink());
150 $this->getMail()->appendInstallationSignature(true);
151
152 $this->sendMail(array($rcp));
153 }
154 break;
155
157
158 foreach ($this->getRecipients() as $rcp) {
159 $this->initLanguage($rcp);
160 $this->initMail();
161 $this->setSubject(
162 sprintf($this->getLanguageText('crs_reject_subscriber'), $this->getObjectTitle(true))
163 );
164 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
165 $this->appendBody("\n\n");
166 $this->appendBody(
167 sprintf($this->getLanguageText('crs_reject_subscriber_body'), $this->getObjectTitle())
168 );
169
170 $this->getMail()->appendInstallationSignature(true);
171
172 $this->sendMail(array($rcp));
173 }
174 break;
175
177 foreach ($this->getRecipients() as $rcp) {
178 $this->initLanguage($rcp);
179 $this->initMail();
180 $this->setSubject(
181 sprintf($this->getLanguageText('crs_status_changed'), $this->getObjectTitle(true))
182 );
183 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
184 $this->appendBody("\n\n");
185 $this->appendBody(
186 sprintf($this->getLanguageText('crs_status_changed_body'), $this->getObjectTitle())
187 );
188
189 $this->appendBody("\n\n");
190 $this->appendBody($this->createCourseStatus($rcp));
191
192 $this->appendBody("\n\n");
193 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
194 $this->appendBody("\n\n");
195 $this->appendBody($this->createPermanentLink());
196
197 $this->getMail()->appendInstallationSignature(true);
198
199 $this->sendMail(array($rcp));
200 }
201 break;
202
203
205
206 foreach ($this->getRecipients() as $rcp) {
207 $this->initLanguage($rcp);
208 $this->initMail();
209 $this->setSubject(
210 sprintf($this->getLanguageText('crs_dismiss_member'), $this->getObjectTitle(true))
211 );
212 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
213 $this->appendBody("\n\n");
214 $this->appendBody(
215 sprintf($this->getLanguageText('crs_dismiss_member_body'), $this->getObjectTitle())
216 );
217 $this->getMail()->appendInstallationSignature(true);
218 $this->sendMail(array($rcp));
219 }
220 break;
221
222
224
225 foreach ($this->getRecipients() as $rcp) {
226 $this->initLanguage($rcp);
227 $this->initMail();
228 $this->setSubject(
229 sprintf($this->getLanguageText('crs_blocked_member'), $this->getObjectTitle(true))
230 );
231 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
232 $this->appendBody("\n\n");
233 $this->appendBody(
234 sprintf($this->getLanguageText('crs_blocked_member_body'), $this->getObjectTitle())
235 );
236 $this->getMail()->appendInstallationSignature(true);
237 $this->sendMail(array($rcp));
238 }
239 break;
240
242
243 foreach ($this->getRecipients() as $rcp) {
244 $this->initLanguage($rcp);
245 $this->initMail();
246 $this->setSubject(
247 sprintf($this->getLanguageText('crs_unblocked_member'), $this->getObjectTitle(true))
248 );
249 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
250 $this->appendBody("\n\n");
251 $this->appendBody(
252 sprintf($this->getLanguageText('crs_unblocked_member_body'), $this->getObjectTitle())
253 );
254
255 $this->appendBody("\n\n");
256 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
257 $this->appendBody("\n\n");
258 $this->appendBody($this->createPermanentLink());
259 $this->getMail()->appendInstallationSignature(true);
260
261 $this->sendMail(array($rcp));
262 }
263 break;
264
266
267 foreach ($this->getRecipients() as $rcp) {
268 $this->initLanguage($rcp);
269 $this->initMail();
270 $this->setSubject(
271 sprintf($this->getLanguageText('crs_new_subscription'), $this->getObjectTitle(true))
272 );
273 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
274 $this->appendBody("\n\n");
275
276 $info = $this->getAdditionalInformation();
277 $this->appendBody(
278 sprintf(
279 $this->getLanguageText('crs_new_subscription_body'),
280 $this->userToString($info['usr_id']),
281 $this->getObjectTitle()
282 )
283 );
284 $this->appendBody("\n\n");
285 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
286 $this->appendBody("\n\n");
287 $this->appendBody($this->createPermanentLink(array(), '_mem'));
288
289 $this->appendBody("\n\n");
290 $this->appendBody($this->getLanguageText('crs_notification_explanation_admin'));
291
292 $this->getMail()->appendInstallationSignature(true);
293 $this->sendMail(array($rcp));
294 }
295 break;
296
298
299 foreach ($this->getRecipients() as $rcp) {
300 $this->initLanguage($rcp);
301 $this->initMail();
302 $this->setSubject(
303 sprintf($this->getLanguageText('crs_new_subscription_request'), $this->getObjectTitle(true))
304 );
305 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
306 $this->appendBody("\n\n");
307
308 $info = $this->getAdditionalInformation();
309 $this->appendBody(
310 sprintf(
311 $this->getLanguageText('crs_new_subscription_request_body'),
312 $this->userToString($info['usr_id']),
313 $this->getObjectTitle()
314 )
315 );
316 $this->appendBody("\n\n");
317 $this->appendBody($this->getLanguageText('crs_new_subscription_request_body2'));
318 $this->appendBody("\n");
319 $this->appendBody($this->createPermanentLink(array(), '_mem'));
320
321 $this->appendBody("\n\n");
322 $this->appendBody($this->getLanguageText('crs_notification_explanation_admin'));
323
324 $this->getMail()->appendInstallationSignature(true);
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('crs_cancel_subscription'), $this->getObjectTitle(true))
336 );
337 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
338 $this->appendBody("\n\n");
339
340 $info = $this->getAdditionalInformation();
341 $this->appendBody(
342 sprintf(
343 $this->getLanguageText('crs_cancel_subscription_body'),
344 $this->userToString($info['usr_id']),
345 $this->getObjectTitle()
346 )
347 );
348 $this->appendBody("\n\n");
349 $this->appendBody($this->getLanguageText('crs_cancel_subscription_body2'));
350 $this->appendBody("\n\n");
351 $this->appendBody($this->createPermanentLink(array(), '_mem'));
352
353 $this->appendBody("\n\n");
354 $this->appendBody($this->getLanguageText('crs_notification_explanation_admin'));
355
356 $this->getMail()->appendInstallationSignature(true);
357 $this->sendMail(array($rcp));
358 }
359 break;
360
362 foreach ($this->getRecipients() as $rcp) {
363 $this->initLanguage($rcp);
364 $this->initMail();
365 $this->setSubject(
366 sprintf($this->getLanguageText('crs_unsubscribe_member'), $this->getObjectTitle(true))
367 );
368 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
369 $this->appendBody("\n\n");
370 $this->appendBody(
371 sprintf($this->getLanguageText('crs_unsubscribe_member_body'), $this->getObjectTitle())
372 );
373 $this->appendBody("\n\n");
374 $this->appendBody($this->getLanguageText('crs_unsubscribe_member_explanation'));
375 $this->getMail()->appendInstallationSignature(true);
376 $this->sendMail(array($rcp));
377 }
378 break;
379
381
382 foreach ($this->getRecipients() as $rcp) {
383 $this->initLanguage($rcp);
384 $this->initMail();
385 $this->setSubject(
386 sprintf($this->getLanguageText('crs_subscribe_member'), $this->getObjectTitle(true))
387 );
388 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
389 $this->appendBody("\n\n");
390 $this->appendBody(
391 sprintf($this->getLanguageText('crs_subscribe_member_body'), $this->getObjectTitle())
392 );
393
394 $this->appendBody("\n\n");
395 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
396 $this->appendBody("\n\n");
397 $this->appendBody($this->createPermanentLink());
398 $this->getMail()->appendInstallationSignature(true);
399
400 $this->sendMail(array($rcp));
401 }
402 break;
403
405 foreach ($this->getRecipients() as $rcp) {
406 $this->initLanguage($rcp);
407 $this->initMail();
408 $this->setSubject(
409 sprintf($this->getLanguageText('crs_subscribe_wl'), $this->getObjectTitle(true))
410 );
411
412 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
413
414 $info = $this->getAdditionalInformation();
415 $this->appendBody("\n\n");
416 $this->appendBody(
417 sprintf(
418 $this->getLanguageText('crs_subscribe_wl_body'),
419 $this->getObjectTitle(),
420 $info['position']
421 )
422 );
423 $this->getMail()->appendInstallationSignature(true);
424 $this->sendMail(array($rcp));
425 }
426 break;
427 }
428 return true;
429 }
430
436 protected function initLanguage($a_usr_id)
437 {
438 parent::initLanguage($a_usr_id);
439 $this->getLanguage()->loadLanguageModule('crs');
440 }
441
447 protected function createCourseStatus($a_usr_id)
448 {
450
451 $body = $this->getLanguageText('crs_new_status') . "\n";
452 $body .= $this->getLanguageText('role') . ': ';
453
454
455 if ($part->isAdmin($a_usr_id)) {
456 $body .= $this->getLanguageText('crs_admin') . "\n";
457 } elseif ($part->isTutor($a_usr_id)) {
458 $body .= $this->getLanguageText('crs_tutor') . "\n";
459 } else {
460 $body .= $this->getLanguageText('crs_member') . "\n";
461 }
462
463 if ($part->isAdmin($a_usr_id) or $part->isTutor($a_usr_id)) {
464 $body .= $this->getLanguageText('crs_status') . ': ';
465
466 if ($part->isNotificationEnabled($a_usr_id)) {
467 $body .= $this->getLanguageText('crs_notify') . "\n";
468 } else {
469 $body .= $this->getLanguageText('crs_no_notify') . "\n";
470 }
471 } else {
472 $body .= $this->getLanguageText('crs_access') . ': ';
473
474 if ($part->isBlocked($a_usr_id)) {
475 $body .= $this->getLanguageText('crs_blocked') . "\n";
476 } else {
477 $body .= $this->getLanguageText('crs_unblocked') . "\n";
478 }
479 }
480
481 $body .= $this->getLanguageText('crs_passed') . ': ';
482
483 if ($part->hasPassed($a_usr_id)) {
484 $body .= $this->getLanguageText('yes');
485 } else {
486 $body .= $this->getLanguageText('no');
487 }
488 return $body;
489 }
490
498 protected function isNotificationTypeEnabled($a_type)
499 {
500 global $DIC;
501
502 $ilSetting = $DIC['ilSetting'];
503
504 return
505 $this->force_sending_mail ||
506 $ilSetting->get('mail_crs_member_notification', true) ||
507 in_array($a_type, $this->permanent_enabled_notifications);
508 }
509}
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_crs_member_notification" and excludes types which are not affected by this setting ...
forceSendingMail($a_status)
Force sending mail independent from global setting.
$permanent_enabled_notifications
Notifications which are not affected by "mail_crs_member_notification" setting because they addresses...
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
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