ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
15  const TYPE_DISMISS_MEMBER = 21;
16 
19 
20  const TYPE_STATUS_CHANGED = 24;
21 
22  const TYPE_BLOCKED_MEMBER = 25;
24 
28 
32 
33 
37  public function __construct()
38  {
40  }
41 
46  public function send()
47  {
48  global $ilSetting;
49 
50  if( (int) $this->getRefId() &&
51  in_array($this->getType(), array(self::TYPE_ADMISSION_MEMBER)) )
52  {
53  $obj = ilObjectFactory::getInstanceByRefId( (int) $this->getRefId() );
54 
55  if( $obj->getAutoNotification() == false )
56  {
57  return false;
58  }
59  }
60 
61  // #11359
62  // parent::send();
63 
64  switch($this->getType())
65  {
66  case self::TYPE_ADMISSION_MEMBER:
67 
68  // automatic mails about status change disabled
69  if(!$ilSetting->get('mail_crs_member_notification',true))
70  {
71  return;
72  }
73 
74  foreach($this->getRecipients() as $rcp)
75  {
76  $this->initLanguage($rcp);
77  $this->initMail();
78  $this->setSubject(
79  sprintf($this->getLanguageText('crs_added_member'),$this->getObjectTitle(true))
80  );
81  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
82  $this->appendBody("\n\n");
83  $this->appendBody(
84  sprintf($this->getLanguageText('crs_added_member_body'),$this->getObjectTitle())
85  );
86  $this->appendBody("\n\n");
87  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
88  $this->appendBody("\n\n");
89  $this->appendBody($this->createPermanentLink());
90  $this->getMail()->appendInstallationSignature(true);
91 
92  $this->sendMail(array($rcp),array('system'));
93  }
94  break;
95 
96 
97  case self::TYPE_ACCEPTED_SUBSCRIPTION_MEMBER:
98 
99  foreach($this->getRecipients() as $rcp)
100  {
101  $this->initLanguage($rcp);
102  $this->initMail();
103  $this->setSubject(
104  sprintf($this->getLanguageText('crs_accept_subscriber'),$this->getObjectTitle(true))
105  );
106  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
107  $this->appendBody("\n\n");
108  $this->appendBody(
109  sprintf($this->getLanguageText('crs_accept_subscriber_body'),$this->getObjectTitle())
110  );
111  $this->appendBody("\n\n");
112  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
113  $this->appendBody("\n\n");
114  $this->appendBody($this->createPermanentLink());
115  $this->getMail()->appendInstallationSignature(true);
116 
117  $this->sendMail(array($rcp),array('system'));
118  }
119  break;
120 
121  case self::TYPE_REFUSED_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_reject_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_reject_subscriber_body'),$this->getObjectTitle())
134  );
135 
136  $this->getMail()->appendInstallationSignature(true);
137 
138  $this->sendMail(array($rcp),array('system'));
139  }
140  break;
141 
142  case self::TYPE_STATUS_CHANGED:
143  foreach($this->getRecipients() as $rcp)
144  {
145  $this->initLanguage($rcp);
146  $this->initMail();
147  $this->setSubject(
148  sprintf($this->getLanguageText('crs_status_changed'),$this->getObjectTitle(true))
149  );
150  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
151  $this->appendBody("\n\n");
152  $this->appendBody(
153  sprintf($this->getLanguageText('crs_status_changed_body'),$this->getObjectTitle())
154  );
155 
156  $this->appendBody("\n\n");
157  $this->appendBody($this->createCourseStatus($rcp));
158 
159  $this->appendBody("\n\n");
160  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
161  $this->appendBody("\n\n");
162  $this->appendBody($this->createPermanentLink());
163 
164  $this->getMail()->appendInstallationSignature(true);
165 
166  $this->sendMail(array($rcp),array('system'));
167  }
168  break;
169 
170 
171  case self::TYPE_DISMISS_MEMBER:
172 
173  // automatic mails about status change disabled
174  if(!$ilSetting->get('mail_crs_member_notification',true))
175  {
176  return;
177  }
178 
179  foreach($this->getRecipients() as $rcp)
180  {
181  $this->initLanguage($rcp);
182  $this->initMail();
183  $this->setSubject(
184  sprintf($this->getLanguageText('crs_dismiss_member'),$this->getObjectTitle(true))
185  );
186  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
187  $this->appendBody("\n\n");
188  $this->appendBody(
189  sprintf($this->getLanguageText('crs_dismiss_member_body'),$this->getObjectTitle())
190  );
191  $this->getMail()->appendInstallationSignature(true);
192  $this->sendMail(array($rcp),array('system'));
193  }
194  break;
195 
196 
197  case self::TYPE_BLOCKED_MEMBER:
198 
199  foreach($this->getRecipients() as $rcp)
200  {
201  $this->initLanguage($rcp);
202  $this->initMail();
203  $this->setSubject(
204  sprintf($this->getLanguageText('crs_blocked_member'),$this->getObjectTitle(true))
205  );
206  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
207  $this->appendBody("\n\n");
208  $this->appendBody(
209  sprintf($this->getLanguageText('crs_blocked_member_body'),$this->getObjectTitle())
210  );
211  $this->getMail()->appendInstallationSignature(true);
212  $this->sendMail(array($rcp),array('system'));
213  }
214  break;
215 
216  case self::TYPE_UNBLOCKED_MEMBER:
217 
218  foreach($this->getRecipients() as $rcp)
219  {
220  $this->initLanguage($rcp);
221  $this->initMail();
222  $this->setSubject(
223  sprintf($this->getLanguageText('crs_unblocked_member'),$this->getObjectTitle(true))
224  );
225  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
226  $this->appendBody("\n\n");
227  $this->appendBody(
228  sprintf($this->getLanguageText('crs_unblocked_member_body'),$this->getObjectTitle())
229  );
230 
231  $this->appendBody("\n\n");
232  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
233  $this->appendBody("\n\n");
234  $this->appendBody($this->createPermanentLink());
235  $this->getMail()->appendInstallationSignature(true);
236 
237  $this->sendMail(array($rcp),array('system'));
238  }
239  break;
240 
241  case self::TYPE_NOTIFICATION_REGISTRATION:
242 
243  foreach($this->getRecipients() as $rcp)
244  {
245  $this->initLanguage($rcp);
246  $this->initMail();
247  $this->setSubject(
248  sprintf($this->getLanguageText('crs_new_subscription'),$this->getObjectTitle(true))
249  );
250  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
251  $this->appendBody("\n\n");
252 
253  $info = $this->getAdditionalInformation();
254  $this->appendBody(
255  sprintf($this->getLanguageText('crs_new_subscription_body'),
256  $this->userToString($info['usr_id']),
257  $this->getObjectTitle()
258  )
259  );
260  $this->appendBody("\n\n");
261  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
262  $this->appendBody("\n\n");
263  $this->appendBody($this->createPermanentLink(array(),'_mem'));
264 
265  $this->appendBody("\n\n");
266  $this->appendBody($this->getLanguageText('crs_notification_explanation_admin'));
267 
268  $this->getMail()->appendInstallationSignature(true);
269  $this->sendMail(array($rcp),array('system'));
270  }
271  break;
272 
273  case self::TYPE_NOTIFICATION_REGISTRATION_REQUEST:
274 
275  foreach($this->getRecipients() as $rcp)
276  {
277  $this->initLanguage($rcp);
278  $this->initMail();
279  $this->setSubject(
280  sprintf($this->getLanguageText('crs_new_subscription_request'),$this->getObjectTitle(true))
281  );
282  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
283  $this->appendBody("\n\n");
284 
285  $info = $this->getAdditionalInformation();
286  $this->appendBody(
287  sprintf($this->getLanguageText('crs_new_subscription_request_body'),
288  $this->userToString($info['usr_id']),
289  $this->getObjectTitle()
290  )
291  );
292  $this->appendBody("\n\n");
293  $this->appendBody($this->getLanguageText('crs_new_subscription_request_body2'));
294  $this->appendBody("\n");
295  $this->appendBody($this->createPermanentLink(array(),'_mem'));
296 
297  $this->appendBody("\n\n");
298  $this->appendBody($this->getLanguageText('crs_notification_explanation_admin'));
299 
300  $this->getMail()->appendInstallationSignature(true);
301  $this->sendMail(array($rcp),array('system'));
302  }
303  break;
304 
305  case self::TYPE_NOTIFICATION_UNSUBSCRIBE:
306 
307  foreach($this->getRecipients() as $rcp)
308  {
309  $this->initLanguage($rcp);
310  $this->initMail();
311  $this->setSubject(
312  sprintf($this->getLanguageText('crs_cancel_subscription'),$this->getObjectTitle(true))
313  );
314  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
315  $this->appendBody("\n\n");
316 
317  $info = $this->getAdditionalInformation();
318  $this->appendBody(
319  sprintf($this->getLanguageText('crs_cancel_subscription_body'),
320  $this->userToString($info['usr_id']),
321  $this->getObjectTitle()
322  )
323  );
324  $this->appendBody("\n\n");
325  $this->appendBody($this->getLanguageText('crs_cancel_subscription_body2'));
326  $this->appendBody("\n\n");
327  $this->appendBody($this->createPermanentLink(array(),'_mem'));
328 
329  $this->appendBody("\n\n");
330  $this->appendBody($this->getLanguageText('crs_notification_explanation_admin'));
331 
332  $this->getMail()->appendInstallationSignature(true);
333  $this->sendMail(array($rcp),array('system'));
334  }
335  break;
336 
337  case self::TYPE_UNSUBSCRIBE_MEMBER:
338  foreach($this->getRecipients() as $rcp)
339  {
340  $this->initLanguage($rcp);
341  $this->initMail();
342  $this->setSubject(
343  sprintf($this->getLanguageText('crs_unsubscribe_member'),$this->getObjectTitle(true))
344  );
345  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
346  $this->appendBody("\n\n");
347  $this->appendBody(
348  sprintf($this->getLanguageText('crs_unsubscribe_member_body'),$this->getObjectTitle())
349  );
350  $this->getMail()->appendInstallationSignature(true);
351  $this->sendMail(array($rcp),array('system'));
352  }
353  break;
354 
355  case self::TYPE_SUBSCRIBE_MEMBER:
356 
357  foreach($this->getRecipients() as $rcp)
358  {
359  $this->initLanguage($rcp);
360  $this->initMail();
361  $this->setSubject(
362  sprintf($this->getLanguageText('crs_subscribe_member'),$this->getObjectTitle(true))
363  );
364  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
365  $this->appendBody("\n\n");
366  $this->appendBody(
367  sprintf($this->getLanguageText('crs_subscribe_member_body'),$this->getObjectTitle())
368  );
369 
370  $this->appendBody("\n\n");
371  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
372  $this->appendBody("\n\n");
373  $this->appendBody($this->createPermanentLink());
374  $this->getMail()->appendInstallationSignature(true);
375 
376  $this->sendMail(array($rcp),array('system'));
377  }
378  break;
379 
380  case self::TYPE_WAITING_LIST_MEMBER:
381  foreach($this->getRecipients() as $rcp)
382  {
383  $this->initLanguage($rcp);
384  $this->initMail();
385  $this->setSubject(
386  sprintf($this->getLanguageText('crs_subscribe_wl'),$this->getObjectTitle(true))
387  );
388 
389  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
390 
391  $info = $this->getAdditionalInformation();
392  $this->appendBody("\n\n");
393  $this->appendBody(
394  sprintf($this->getLanguageText('crs_subscribe_wl_body'),
395  $this->getObjectTitle(),
396  $info['position']
397  )
398  );
399  $this->getMail()->appendInstallationSignature(true);
400  $this->sendMail(array($rcp),array('system'));
401  }
402  break;
403  }
404  return true;
405  }
406 
412  protected function initLanguage($a_usr_id)
413  {
414  parent::initLanguage($a_usr_id);
415  $this->getLanguage()->loadLanguageModule('crs');
416  }
417 
423  protected function createCourseStatus($a_usr_id)
424  {
426 
427  $body = $this->getLanguageText('crs_new_status')."\n";
428  $body .= $this->getLanguageText('role').': ';
429 
430 
431  if($part->isAdmin($a_usr_id))
432  {
433  $body .= $this->getLanguageText('crs_admin')."\n";
434 
435  }
436  elseif($part->isTutor($a_usr_id))
437  {
438  $body .= $this->getLanguageText('crs_tutor')."\n";
439  }
440  else
441  {
442  $body .= $this->getLanguageText('crs_member')."\n";
443  }
444 
445  if($part->isAdmin($a_usr_id) or $part->isTutor($a_usr_id))
446  {
447  $body .= $this->getLanguageText('crs_status').': ';
448 
449  if($part->isNotificationEnabled($a_usr_id))
450  {
451  $body .= $this->getLanguageText('crs_notify')."\n";
452  }
453  else
454  {
455  $body .= $this->getLanguageText('crs_no_notify')."\n";
456  }
457  }
458  else
459  {
460  $body .= $this->getLanguageText('crs_access').': ';
461 
462  if($part->isBlocked($a_usr_id))
463  {
464  $body .= $this->getLanguageText('crs_blocked')."\n";
465  }
466  else
467  {
468  $body .= $this->getLanguageText('crs_unblocked')."\n";
469  }
470  }
471 
472  $body .= $this->getLanguageText('crs_passed').': ';
473 
474  if($part->hasPassed($a_usr_id))
475  {
476  $body .= $this->getLanguageText('yes');
477  }
478  else
479  {
480  $body .= $this->getLanguageText('no');
481  }
482  return $body;
483  }
484 }
485 ?>