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