ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 include_once './Services/Mail/classes/class.ilMailNotification.php';
5 
13 {
14  // v Notifications affect members & co. v
16  const TYPE_DISMISS_MEMBER = 21;
17 
20 
21  const TYPE_STATUS_CHANGED = 24;
22 
23  const TYPE_BLOCKED_MEMBER = 25;
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  {
54  parent::__construct();
55  }
56 
61  public function forceSendingMail($a_status)
62  {
63  $this->force_sending_mail = $a_status;
64  }
65 
70  public function send()
71  {
72  if(
73  (int) $this->getRefId() &&
74  in_array($this->getType(), array(self::TYPE_ADMISSION_MEMBER)) )
75  {
76  $obj = ilObjectFactory::getInstanceByRefId( (int) $this->getRefId() );
77 
78  if( $obj->getAutoNotification() == false )
79  {
80  if(!$this->force_sending_mail) {
81  return false;
82  }
83  }
84  }
85 
86  if(!$this->isNotificationTypeEnabled($this->getType()))
87  {
88  return false;
89  }
90 
91  // #11359
92  // parent::send();
93 
94  switch($this->getType())
95  {
96  case self::TYPE_ADMISSION_MEMBER:
97 
98  foreach($this->getRecipients() as $rcp)
99  {
100  $this->initLanguage($rcp);
101  $this->initMail();
102  $this->setSubject(
103  sprintf($this->getLanguageText('crs_added_member'),$this->getObjectTitle(true))
104  );
105  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
106  $this->appendBody("\n\n");
107  $this->appendBody(
108  sprintf($this->getLanguageText('crs_added_member_body'),$this->getObjectTitle())
109  );
110  $this->appendBody("\n\n");
111  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
112  $this->appendBody("\n\n");
113  $this->appendBody($this->createPermanentLink());
114  $this->getMail()->appendInstallationSignature(true);
115 
116  $this->sendMail(array($rcp),array('system'));
117  }
118  break;
119 
120 
121  case self::TYPE_ACCEPTED_SUBSCRIPTION_MEMBER:
122 
123  foreach($this->getRecipients() as $rcp)
124  {
125  $this->initLanguage($rcp);
126  $this->initMail();
127  $this->setSubject(
128  sprintf($this->getLanguageText('crs_accept_subscriber'),$this->getObjectTitle(true))
129  );
130  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
131  $this->appendBody("\n\n");
132  $this->appendBody(
133  sprintf($this->getLanguageText('crs_accept_subscriber_body'),$this->getObjectTitle())
134  );
135  $this->appendBody("\n\n");
136  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
137  $this->appendBody("\n\n");
138  $this->appendBody($this->createPermanentLink());
139  $this->getMail()->appendInstallationSignature(true);
140 
141  $this->sendMail(array($rcp),array('system'));
142  }
143  break;
144 
145  case self::TYPE_REFUSED_SUBSCRIPTION_MEMBER:
146 
147  foreach($this->getRecipients() as $rcp)
148  {
149  $this->initLanguage($rcp);
150  $this->initMail();
151  $this->setSubject(
152  sprintf($this->getLanguageText('crs_reject_subscriber'),$this->getObjectTitle(true))
153  );
154  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
155  $this->appendBody("\n\n");
156  $this->appendBody(
157  sprintf($this->getLanguageText('crs_reject_subscriber_body'),$this->getObjectTitle())
158  );
159 
160  $this->getMail()->appendInstallationSignature(true);
161 
162  $this->sendMail(array($rcp),array('system'));
163  }
164  break;
165 
166  case self::TYPE_STATUS_CHANGED:
167  foreach($this->getRecipients() as $rcp)
168  {
169  $this->initLanguage($rcp);
170  $this->initMail();
171  $this->setSubject(
172  sprintf($this->getLanguageText('crs_status_changed'),$this->getObjectTitle(true))
173  );
174  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
175  $this->appendBody("\n\n");
176  $this->appendBody(
177  sprintf($this->getLanguageText('crs_status_changed_body'),$this->getObjectTitle())
178  );
179 
180  $this->appendBody("\n\n");
181  $this->appendBody($this->createCourseStatus($rcp));
182 
183  $this->appendBody("\n\n");
184  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
185  $this->appendBody("\n\n");
186  $this->appendBody($this->createPermanentLink());
187 
188  $this->getMail()->appendInstallationSignature(true);
189 
190  $this->sendMail(array($rcp),array('system'));
191  }
192  break;
193 
194 
195  case self::TYPE_DISMISS_MEMBER:
196 
197  foreach($this->getRecipients() as $rcp)
198  {
199  $this->initLanguage($rcp);
200  $this->initMail();
201  $this->setSubject(
202  sprintf($this->getLanguageText('crs_dismiss_member'),$this->getObjectTitle(true))
203  );
204  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
205  $this->appendBody("\n\n");
206  $this->appendBody(
207  sprintf($this->getLanguageText('crs_dismiss_member_body'),$this->getObjectTitle())
208  );
209  $this->getMail()->appendInstallationSignature(true);
210  $this->sendMail(array($rcp),array('system'));
211  }
212  break;
213 
214 
215  case self::TYPE_BLOCKED_MEMBER:
216 
217  foreach($this->getRecipients() as $rcp)
218  {
219  $this->initLanguage($rcp);
220  $this->initMail();
221  $this->setSubject(
222  sprintf($this->getLanguageText('crs_blocked_member'),$this->getObjectTitle(true))
223  );
224  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
225  $this->appendBody("\n\n");
226  $this->appendBody(
227  sprintf($this->getLanguageText('crs_blocked_member_body'),$this->getObjectTitle())
228  );
229  $this->getMail()->appendInstallationSignature(true);
230  $this->sendMail(array($rcp),array('system'));
231  }
232  break;
233 
234  case self::TYPE_UNBLOCKED_MEMBER:
235 
236  foreach($this->getRecipients() as $rcp)
237  {
238  $this->initLanguage($rcp);
239  $this->initMail();
240  $this->setSubject(
241  sprintf($this->getLanguageText('crs_unblocked_member'),$this->getObjectTitle(true))
242  );
243  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
244  $this->appendBody("\n\n");
245  $this->appendBody(
246  sprintf($this->getLanguageText('crs_unblocked_member_body'),$this->getObjectTitle())
247  );
248 
249  $this->appendBody("\n\n");
250  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
251  $this->appendBody("\n\n");
252  $this->appendBody($this->createPermanentLink());
253  $this->getMail()->appendInstallationSignature(true);
254 
255  $this->sendMail(array($rcp),array('system'));
256  }
257  break;
258 
259  case self::TYPE_NOTIFICATION_REGISTRATION:
260 
261  foreach($this->getRecipients() as $rcp)
262  {
263  $this->initLanguage($rcp);
264  $this->initMail();
265  $this->setSubject(
266  sprintf($this->getLanguageText('crs_new_subscription'),$this->getObjectTitle(true))
267  );
268  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
269  $this->appendBody("\n\n");
270 
271  $info = $this->getAdditionalInformation();
272  $this->appendBody(
273  sprintf($this->getLanguageText('crs_new_subscription_body'),
274  $this->userToString($info['usr_id']),
275  $this->getObjectTitle()
276  )
277  );
278  $this->appendBody("\n\n");
279  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
280  $this->appendBody("\n\n");
281  $this->appendBody($this->createPermanentLink(array(),'_mem'));
282 
283  $this->appendBody("\n\n");
284  $this->appendBody($this->getLanguageText('crs_notification_explanation_admin'));
285 
286  $this->getMail()->appendInstallationSignature(true);
287  $this->sendMail(array($rcp),array('system'));
288  }
289  break;
290 
291  case self::TYPE_NOTIFICATION_REGISTRATION_REQUEST:
292 
293  foreach($this->getRecipients() as $rcp)
294  {
295  $this->initLanguage($rcp);
296  $this->initMail();
297  $this->setSubject(
298  sprintf($this->getLanguageText('crs_new_subscription_request'),$this->getObjectTitle(true))
299  );
300  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
301  $this->appendBody("\n\n");
302 
303  $info = $this->getAdditionalInformation();
304  $this->appendBody(
305  sprintf($this->getLanguageText('crs_new_subscription_request_body'),
306  $this->userToString($info['usr_id']),
307  $this->getObjectTitle()
308  )
309  );
310  $this->appendBody("\n\n");
311  $this->appendBody($this->getLanguageText('crs_new_subscription_request_body2'));
312  $this->appendBody("\n");
313  $this->appendBody($this->createPermanentLink(array(),'_mem'));
314 
315  $this->appendBody("\n\n");
316  $this->appendBody($this->getLanguageText('crs_notification_explanation_admin'));
317 
318  $this->getMail()->appendInstallationSignature(true);
319  $this->sendMail(array($rcp),array('system'));
320  }
321  break;
322 
323  case self::TYPE_NOTIFICATION_UNSUBSCRIBE:
324 
325  foreach($this->getRecipients() as $rcp)
326  {
327  $this->initLanguage($rcp);
328  $this->initMail();
329  $this->setSubject(
330  sprintf($this->getLanguageText('crs_cancel_subscription'),$this->getObjectTitle(true))
331  );
332  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
333  $this->appendBody("\n\n");
334 
335  $info = $this->getAdditionalInformation();
336  $this->appendBody(
337  sprintf($this->getLanguageText('crs_cancel_subscription_body'),
338  $this->userToString($info['usr_id']),
339  $this->getObjectTitle()
340  )
341  );
342  $this->appendBody("\n\n");
343  $this->appendBody($this->getLanguageText('crs_cancel_subscription_body2'));
344  $this->appendBody("\n\n");
345  $this->appendBody($this->createPermanentLink(array(),'_mem'));
346 
347  $this->appendBody("\n\n");
348  $this->appendBody($this->getLanguageText('crs_notification_explanation_admin'));
349 
350  $this->getMail()->appendInstallationSignature(true);
351  $this->sendMail(array($rcp),array('system'));
352  }
353  break;
354 
355  case self::TYPE_UNSUBSCRIBE_MEMBER:
356  foreach($this->getRecipients() as $rcp)
357  {
358  $this->initLanguage($rcp);
359  $this->initMail();
360  $this->setSubject(
361  sprintf($this->getLanguageText('crs_unsubscribe_member'),$this->getObjectTitle(true))
362  );
363  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
364  $this->appendBody("\n\n");
365  $this->appendBody(
366  sprintf($this->getLanguageText('crs_unsubscribe_member_body'),$this->getObjectTitle())
367  );
368  $this->appendBody("\n\n");
369  $this->appendBody($this->getLanguageText('crs_unsubscribe_member_explanation'));
370  $this->getMail()->appendInstallationSignature(true);
371  $this->sendMail(array($rcp),array('system'));
372  }
373  break;
374 
375  case self::TYPE_SUBSCRIBE_MEMBER:
376 
377  foreach($this->getRecipients() as $rcp)
378  {
379  $this->initLanguage($rcp);
380  $this->initMail();
381  $this->setSubject(
382  sprintf($this->getLanguageText('crs_subscribe_member'),$this->getObjectTitle(true))
383  );
384  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
385  $this->appendBody("\n\n");
386  $this->appendBody(
387  sprintf($this->getLanguageText('crs_subscribe_member_body'),$this->getObjectTitle())
388  );
389 
390  $this->appendBody("\n\n");
391  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
392  $this->appendBody("\n\n");
393  $this->appendBody($this->createPermanentLink());
394  $this->getMail()->appendInstallationSignature(true);
395 
396  $this->sendMail(array($rcp),array('system'));
397  }
398  break;
399 
400  case self::TYPE_WAITING_LIST_MEMBER:
401  foreach($this->getRecipients() as $rcp)
402  {
403  $this->initLanguage($rcp);
404  $this->initMail();
405  $this->setSubject(
406  sprintf($this->getLanguageText('crs_subscribe_wl'),$this->getObjectTitle(true))
407  );
408 
409  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
410 
411  $info = $this->getAdditionalInformation();
412  $this->appendBody("\n\n");
413  $this->appendBody(
414  sprintf($this->getLanguageText('crs_subscribe_wl_body'),
415  $this->getObjectTitle(),
416  $info['position']
417  )
418  );
419  $this->getMail()->appendInstallationSignature(true);
420  $this->sendMail(array($rcp),array('system'));
421  }
422  break;
423  }
424  return true;
425  }
426 
432  protected function initLanguage($a_usr_id)
433  {
434  parent::initLanguage($a_usr_id);
435  $this->getLanguage()->loadLanguageModule('crs');
436  }
437 
443  protected function createCourseStatus($a_usr_id)
444  {
446 
447  $body = $this->getLanguageText('crs_new_status')."\n";
448  $body .= $this->getLanguageText('role').': ';
449 
450 
451  if($part->isAdmin($a_usr_id))
452  {
453  $body .= $this->getLanguageText('crs_admin')."\n";
454 
455  }
456  elseif($part->isTutor($a_usr_id))
457  {
458  $body .= $this->getLanguageText('crs_tutor')."\n";
459  }
460  else
461  {
462  $body .= $this->getLanguageText('crs_member')."\n";
463  }
464 
465  if($part->isAdmin($a_usr_id) or $part->isTutor($a_usr_id))
466  {
467  $body .= $this->getLanguageText('crs_status').': ';
468 
469  if($part->isNotificationEnabled($a_usr_id))
470  {
471  $body .= $this->getLanguageText('crs_notify')."\n";
472  }
473  else
474  {
475  $body .= $this->getLanguageText('crs_no_notify')."\n";
476  }
477  }
478  else
479  {
480  $body .= $this->getLanguageText('crs_access').': ';
481 
482  if($part->isBlocked($a_usr_id))
483  {
484  $body .= $this->getLanguageText('crs_blocked')."\n";
485  }
486  else
487  {
488  $body .= $this->getLanguageText('crs_unblocked')."\n";
489  }
490  }
491 
492  $body .= $this->getLanguageText('crs_passed').': ';
493 
494  if($part->hasPassed($a_usr_id))
495  {
496  $body .= $this->getLanguageText('yes');
497  }
498  else
499  {
500  $body .= $this->getLanguageText('no');
501  }
502  return $body;
503  }
504 
512  protected function isNotificationTypeEnabled($a_type)
513  {
514  global $ilSetting;
515 
516  return
517  $this->force_sending_mail ||
518  $ilSetting->get('mail_crs_member_notification',true) ||
519  in_array($a_type, $this->permanent_enabled_notifications);
520  }
521 }
522 ?>
getType()
Get notification type.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
forceSendingMail($a_status)
Force sending mail independent from global setting.
$a_type
Definition: workflow.php:93
$info
Definition: example_052.php:80
Base class for course/group mail notifications.
getObjectTitle($a_shorten=false)
Create styles array
The data for the language used.
sendMail(array $a_rcp, $a_type, $a_parse_recipients=true)
getRecipients()
get array of recipients
createPermanentLink($a_params=array(), $a_append='')
global $ilSetting
Definition: privfeed.php:17
isNotificationTypeEnabled($a_type)
get setting "mail_crs_member_notification" and excludes types which are not affected by this setting ...
appendBody($a_body)
Append body text.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
$permanent_enabled_notifications
Notifications which are not affected by "mail_crs_member_notification" setting because they addresses...