ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
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 
49 
50 
54  public function __construct()
55  {
56  parent::__construct();
57  }
58 
63  public function forceSendingMail($a_status)
64  {
65  $this->force_sending_mail = $a_status;
66  }
67 
68 
69 
74  public function send()
75  {
76  if(!$this->isNotificationTypeEnabled($this->getType()))
77  {
78  $GLOBALS['ilLog']->write(__METHOD__.': Membership mail disabled globally.');
79  return false;
80  }
81  // parent::send();
82 
83  switch($this->getType())
84  {
85  case self::TYPE_ADMISSION_MEMBER:
86 
87  foreach($this->getRecipients() as $rcp)
88  {
89  $this->initLanguage($rcp);
90  $this->initMail();
91  $this->setSubject(
92  sprintf($this->getLanguageText('grp_mail_admission_new_sub'),$this->getObjectTitle(true))
93  );
94  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
95  $this->appendBody("\n\n");
96  $this->appendBody(
97  sprintf($this->getLanguageText('grp_mail_admission_new_bod'),$this->getObjectTitle())
98  );
99  $this->appendBody("\n\n");
100  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
101  $this->appendBody("\n\n");
102  $this->appendBody($this->createPermanentLink());
103  $this->getMail()->appendInstallationSignature(true);
104 
105  $this->sendMail(array($rcp),array('system'));
106  }
107  break;
108 
109  case self::TYPE_DISMISS_MEMBER:
110 
111  foreach($this->getRecipients() as $rcp)
112  {
113  $this->initLanguage($rcp);
114  $this->initMail();
115  $this->setSubject(
116  sprintf($this->getLanguageText('grp_mail_dismiss_sub'),$this->getObjectTitle(true))
117  );
118  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
119  $this->appendBody("\n\n");
120  $this->appendBody(
121  sprintf($this->getLanguageText('grp_mail_dismiss_bod'),$this->getObjectTitle())
122  );
123  $this->getMail()->appendInstallationSignature(true);
124  $this->sendMail(array($rcp),array('system'));
125  }
126  break;
127 
128 
129  case self::TYPE_NOTIFICATION_REGISTRATION:
130 
131  foreach($this->getRecipients() as $rcp)
132  {
133  $this->initLanguage($rcp);
134  $this->initMail();
135  $this->setSubject(
136  sprintf($this->getLanguageText('grp_mail_notification_reg_sub'),$this->getObjectTitle(true))
137  );
138  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
139  $this->appendBody("\n\n");
140 
141  $info = $this->getAdditionalInformation();
142  $this->appendBody(
143  sprintf($this->getLanguageText('grp_mail_notification_reg_bod'),
144  $this->userToString($info['usr_id']),
145  $this->getObjectTitle()
146  )
147  );
148  $this->appendBody("\n\n");
149  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
150  $this->appendBody("\n\n");
151  $this->appendBody($this->createPermanentLink(array(),'_mem'));
152 
153  $this->appendBody("\n\n");
154  $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
155 
156  $this->getMail()->appendInstallationSignature(true);
157  $this->sendMail(array($rcp),array('system'));
158  }
159  break;
160 
161  case self::TYPE_UNSUBSCRIBE_MEMBER:
162 
163  foreach($this->getRecipients() as $rcp)
164  {
165  $this->initLanguage($rcp);
166  $this->initMail();
167  $this->setSubject(
168  sprintf($this->getLanguageText('grp_mail_unsubscribe_member_sub'),$this->getObjectTitle(true))
169  );
170  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
171  $this->appendBody("\n\n");
172  $this->appendBody(
173  sprintf($this->getLanguageText('grp_mail_unsubscribe_member_bod'),$this->getObjectTitle())
174  );
175  $this->getMail()->appendInstallationSignature(true);
176  $this->sendMail(array($rcp),array('system'));
177  }
178  break;
179 
180  case self::TYPE_NOTIFICATION_UNSUBSCRIBE:
181 
182  foreach($this->getRecipients() as $rcp)
183  {
184  $this->initLanguage($rcp);
185  $this->initMail();
186  $this->setSubject(
187  sprintf($this->getLanguageText('grp_mail_notification_unsub_sub'),$this->getObjectTitle(true))
188  );
189  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
190  $this->appendBody("\n\n");
191 
192  $info = $this->getAdditionalInformation();
193  $this->appendBody(
194  sprintf($this->getLanguageText('grp_mail_notification_unsub_bod'),
195  $this->userToString($info['usr_id']),
196  $this->getObjectTitle()
197  )
198  );
199  $this->appendBody("\n\n");
200  $this->appendBody($this->getLanguageText('grp_mail_notification_unsub_bod2'));
201  $this->appendBody("\n\n");
202  $this->appendBody($this->createPermanentLink(array(),'_mem'));
203 
204  $this->appendBody("\n\n");
205  $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
206 
207  $this->getMail()->appendInstallationSignature(true);
208  $this->sendMail(array($rcp),array('system'));
209  }
210  break;
211 
212 
213  case self::TYPE_SUBSCRIBE_MEMBER:
214 
215  foreach($this->getRecipients() as $rcp)
216  {
217  $this->initLanguage($rcp);
218  $this->initMail();
219  $this->setSubject(
220  sprintf($this->getLanguageText('grp_mail_subscribe_member_sub'),$this->getObjectTitle(true))
221  );
222  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
223  $this->appendBody("\n\n");
224  $this->appendBody(
225  sprintf($this->getLanguageText('grp_mail_subscribe_member_bod'),$this->getObjectTitle())
226  );
227 
228  $this->appendBody("\n\n");
229  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
230  $this->appendBody("\n\n");
231  $this->appendBody($this->createPermanentLink());
232  $this->getMail()->appendInstallationSignature(true);
233 
234  $this->sendMail(array($rcp),array('system'));
235  }
236  break;
237 
238 
239  case self::TYPE_NOTIFICATION_REGISTRATION_REQUEST:
240 
241  foreach($this->getRecipients() as $rcp)
242  {
243  $this->initLanguage($rcp);
244  $this->initMail();
245  $this->setSubject(
246  sprintf($this->getLanguageText('grp_mail_notification_reg_req_sub'),$this->getObjectTitle(true))
247  );
248  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
249  $this->appendBody("\n\n");
250 
251  $info = $this->getAdditionalInformation();
252  $this->appendBody(
253  sprintf($this->getLanguageText('grp_mail_notification_reg_req_bod'),
254  $this->userToString($info['usr_id']),
255  $this->getObjectTitle()
256  )
257  );
258  $this->appendBody("\n\n");
259  $this->appendBody($this->getLanguageText('grp_mail_notification_reg_req_bod2'));
260  $this->appendBody("\n");
261  $this->appendBody($this->createPermanentLink(array(),'_mem'));
262 
263  $this->appendBody("\n\n");
264  $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
265 
266  $this->getMail()->appendInstallationSignature(true);
267  $this->sendMail(array($rcp),array('system'));
268  }
269  break;
270 
271  case self::TYPE_REFUSED_SUBSCRIPTION_MEMBER:
272 
273  foreach($this->getRecipients() as $rcp)
274  {
275  $this->initLanguage($rcp);
276  $this->initMail();
277  $this->setSubject(
278  sprintf($this->getLanguageText('grp_mail_sub_dec_sub'),$this->getObjectTitle(true))
279  );
280  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
281  $this->appendBody("\n\n");
282  $this->appendBody(
283  sprintf($this->getLanguageText('grp_mail_sub_dec_bod'),$this->getObjectTitle())
284  );
285 
286  $this->getMail()->appendInstallationSignature(true);
287 
288  $this->sendMail(array($rcp),array('system'));
289  }
290  break;
291 
292  case self::TYPE_ACCEPTED_SUBSCRIPTION_MEMBER:
293 
294  foreach($this->getRecipients() as $rcp)
295  {
296  $this->initLanguage($rcp);
297  $this->initMail();
298  $this->setSubject(
299  sprintf($this->getLanguageText('grp_mail_sub_acc_sub'),$this->getObjectTitle(true))
300  );
301  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
302  $this->appendBody("\n\n");
303  $this->appendBody(
304  sprintf($this->getLanguageText('grp_mail_sub_acc_bod'),$this->getObjectTitle())
305  );
306  $this->appendBody("\n\n");
307  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
308  $this->appendBody("\n\n");
309  $this->appendBody($this->createPermanentLink());
310  $this->getMail()->appendInstallationSignature(true);
311 
312  $this->sendMail(array($rcp),array('system'));
313  }
314  break;
315 
316  case self::TYPE_WAITING_LIST_MEMBER:
317  foreach($this->getRecipients() as $rcp)
318  {
319  $this->initLanguage($rcp);
320  $this->initMail();
321  $this->setSubject(
322  sprintf($this->getLanguageText('grp_mail_wl_sub'),$this->getObjectTitle(true))
323  );
324 
325  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
326 
327  $info = $this->getAdditionalInformation();
328  $this->appendBody("\n\n");
329  $this->appendBody(
330  sprintf($this->getLanguageText('grp_mail_wl_bod'),
331  $this->getObjectTitle(),
332  $info['position']
333  )
334  );
335  $this->getMail()->appendInstallationSignature(true);
336  $this->sendMail(array($rcp),array('system'));
337  }
338  break;
339 
340 
341  case self::TYPE_STATUS_CHANGED:
342  foreach($this->getRecipients() as $rcp)
343  {
344  $this->initLanguage($rcp);
345  $this->initMail();
346  $this->setSubject(
347  sprintf($this->getLanguageText('grp_mail_status_sub'),$this->getObjectTitle(true))
348  );
349  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
350  $this->appendBody("\n\n");
351  $this->appendBody(
352  sprintf($this->getLanguageText('grp_mail_status_bod'),$this->getObjectTitle())
353  );
354 
355  $this->appendBody("\n\n");
356  $this->appendBody($this->createGroupStatus($rcp));
357 
358  $this->appendBody("\n\n");
359  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
360  $this->appendBody("\n\n");
361  $this->appendBody($this->createPermanentLink());
362 
363  $this->getMail()->appendInstallationSignature(true);
364 
365  $this->sendMail(array($rcp),array('system'));
366  }
367  break;
368 
369  }
370  return true;
371  }
372 
378  protected function initLanguage($a_usr_id)
379  {
380  parent::initLanguage($a_usr_id);
381  $this->getLanguage()->loadLanguageModule('grp');
382  }
383 
389  protected function createGroupStatus($a_usr_id)
390  {
392 
393  $body = $this->getLanguageText('grp_new_status')."\n";
394  $body .= $this->getLanguageText('role').': ';
395 
396 
397  if($part->isAdmin($a_usr_id))
398  {
399  $body .= $this->getLanguageText('il_grp_admin')."\n";
400 
401  }
402  else
403  {
404  $body .= $this->getLanguageText('il_grp_member')."\n";
405  }
406 
407  if($part->isAdmin($a_usr_id))
408  {
409  $body .= $this->getLanguageText('grp_notification').': ';
410 
411  if($part->isNotificationEnabled($a_usr_id))
412  {
413  $body .= $this->getLanguageText('grp_notify_on')."\n";
414  }
415  else
416  {
417  $body .= $this->getLanguageText('grp_notify_off')."\n";
418  }
419  }
420  return $body;
421  }
422 
430  protected function isNotificationTypeEnabled($a_type)
431  {
432  global $ilSetting;
433 
434  return
435  $this->force_sending_mail ||
436  $ilSetting->get('mail_grp_member_notification',true) ||
437  in_array($a_type, $this->permanent_enabled_notifications);
438  }
439 }
440 ?>
isNotificationTypeEnabled($a_type)
get setting "mail_grp_member_notification" and excludes types which are not affected by this setting ...
getType()
Get notification type.
forceSendingMail($a_status)
Force sending mail independent from global setting.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$a_type
Definition: workflow.php:93
$info
Definition: example_052.php:80
Base class for course/group mail notifications.
getObjectTitle($a_shorten=false)
$permanent_enabled_notifications
Notifications which are not affected by "mail_grp_member_notification" setting because they addresses...
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
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
appendBody($a_body)
Append body text.