ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  $GLOBALS['DIC']->logger()->grp()->info('Membership mail disabled globally.');
78  return false;
79  }
80  // parent::send();
81 
82  switch ($this->getType()) {
83  case self::TYPE_ADMISSION_MEMBER:
84 
85  foreach ($this->getRecipients() as $rcp) {
86  $this->initLanguage($rcp);
87  $this->initMail();
88  $this->setSubject(
89  sprintf($this->getLanguageText('grp_mail_admission_new_sub'), $this->getObjectTitle(true))
90  );
91  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
92  $this->appendBody("\n\n");
93  $this->appendBody(
94  sprintf($this->getLanguageText('grp_mail_admission_new_bod'), $this->getObjectTitle())
95  );
96  $this->appendBody("\n\n");
97  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
98  $this->appendBody("\n\n");
99  $this->appendBody($this->createPermanentLink());
100  $this->getMail()->appendInstallationSignature(true);
101 
102  $this->sendMail(array($rcp), array('system'));
103  }
104  break;
105 
106  case self::TYPE_DISMISS_MEMBER:
107 
108  foreach ($this->getRecipients() as $rcp) {
109  $this->initLanguage($rcp);
110  $this->initMail();
111  $this->setSubject(
112  sprintf($this->getLanguageText('grp_mail_dismiss_sub'), $this->getObjectTitle(true))
113  );
114  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
115  $this->appendBody("\n\n");
116  $this->appendBody(
117  sprintf($this->getLanguageText('grp_mail_dismiss_bod'), $this->getObjectTitle())
118  );
119  $this->getMail()->appendInstallationSignature(true);
120  $this->sendMail(array($rcp), array('system'));
121  }
122  break;
123 
124 
125  case self::TYPE_NOTIFICATION_REGISTRATION:
126 
127  foreach ($this->getRecipients() as $rcp) {
128  $this->initLanguage($rcp);
129  $this->initMail();
130  $this->setSubject(
131  sprintf($this->getLanguageText('grp_mail_notification_reg_sub'), $this->getObjectTitle(true))
132  );
133  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
134  $this->appendBody("\n\n");
135 
136  $info = $this->getAdditionalInformation();
137  $this->appendBody(
138  sprintf(
139  $this->getLanguageText('grp_mail_notification_reg_bod'),
140  $this->userToString($info['usr_id']),
141  $this->getObjectTitle()
142  )
143  );
144  $this->appendBody("\n\n");
145  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
146  $this->appendBody("\n\n");
147  $this->appendBody($this->createPermanentLink(array(), '_mem'));
148 
149  $this->appendBody("\n\n");
150  $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
151 
152  $this->getMail()->appendInstallationSignature(true);
153  $this->sendMail(array($rcp), array('system'));
154  }
155  break;
156 
157  case self::TYPE_UNSUBSCRIBE_MEMBER:
158 
159  foreach ($this->getRecipients() as $rcp) {
160  $this->initLanguage($rcp);
161  $this->initMail();
162  $this->setSubject(
163  sprintf($this->getLanguageText('grp_mail_unsubscribe_member_sub'), $this->getObjectTitle(true))
164  );
165  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
166  $this->appendBody("\n\n");
167  $this->appendBody(
168  sprintf($this->getLanguageText('grp_mail_unsubscribe_member_bod'), $this->getObjectTitle())
169  );
170  $this->getMail()->appendInstallationSignature(true);
171  $this->sendMail(array($rcp), array('system'));
172  }
173  break;
174 
175  case self::TYPE_NOTIFICATION_UNSUBSCRIBE:
176 
177  foreach ($this->getRecipients() as $rcp) {
178  $this->initLanguage($rcp);
179  $this->initMail();
180  $this->setSubject(
181  sprintf($this->getLanguageText('grp_mail_notification_unsub_sub'), $this->getObjectTitle(true))
182  );
183  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
184  $this->appendBody("\n\n");
185 
186  $info = $this->getAdditionalInformation();
187  $this->appendBody(
188  sprintf(
189  $this->getLanguageText('grp_mail_notification_unsub_bod'),
190  $this->userToString($info['usr_id']),
191  $this->getObjectTitle()
192  )
193  );
194  $this->appendBody("\n\n");
195  $this->appendBody($this->getLanguageText('grp_mail_notification_unsub_bod2'));
196  $this->appendBody("\n\n");
197  $this->appendBody($this->createPermanentLink(array(), '_mem'));
198 
199  $this->appendBody("\n\n");
200  $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
201 
202  $this->getMail()->appendInstallationSignature(true);
203  $this->sendMail(array($rcp), array('system'));
204  }
205  break;
206 
207 
208  case self::TYPE_SUBSCRIBE_MEMBER:
209 
210  foreach ($this->getRecipients() as $rcp) {
211  $this->initLanguage($rcp);
212  $this->initMail();
213  $this->setSubject(
214  sprintf($this->getLanguageText('grp_mail_subscribe_member_sub'), $this->getObjectTitle(true))
215  );
216  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
217  $this->appendBody("\n\n");
218  $this->appendBody(
219  sprintf($this->getLanguageText('grp_mail_subscribe_member_bod'), $this->getObjectTitle())
220  );
221 
222  $this->appendBody("\n\n");
223  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
224  $this->appendBody("\n\n");
225  $this->appendBody($this->createPermanentLink());
226  $this->getMail()->appendInstallationSignature(true);
227 
228  $this->sendMail(array($rcp), array('system'));
229  }
230  break;
231 
232 
233  case self::TYPE_NOTIFICATION_REGISTRATION_REQUEST:
234 
235  foreach ($this->getRecipients() as $rcp) {
236  $this->initLanguage($rcp);
237  $this->initMail();
238  $this->setSubject(
239  sprintf($this->getLanguageText('grp_mail_notification_reg_req_sub'), $this->getObjectTitle(true))
240  );
241  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
242  $this->appendBody("\n\n");
243 
244  $info = $this->getAdditionalInformation();
245  $this->appendBody(
246  sprintf(
247  $this->getLanguageText('grp_mail_notification_reg_req_bod'),
248  $this->userToString($info['usr_id']),
249  $this->getObjectTitle()
250  )
251  );
252  $this->appendBody("\n\n");
253  $this->appendBody($this->getLanguageText('grp_mail_notification_reg_req_bod2'));
254  $this->appendBody("\n");
255  $this->appendBody($this->createPermanentLink(array(), '_mem'));
256 
257  $this->appendBody("\n\n");
258  $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
259 
260  $this->getMail()->appendInstallationSignature(true);
261  $this->sendMail(array($rcp), array('system'));
262  }
263  break;
264 
265  case self::TYPE_REFUSED_SUBSCRIPTION_MEMBER:
266 
267  foreach ($this->getRecipients() as $rcp) {
268  $this->initLanguage($rcp);
269  $this->initMail();
270  $this->setSubject(
271  sprintf($this->getLanguageText('grp_mail_sub_dec_sub'), $this->getObjectTitle(true))
272  );
273  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
274  $this->appendBody("\n\n");
275  $this->appendBody(
276  sprintf($this->getLanguageText('grp_mail_sub_dec_bod'), $this->getObjectTitle())
277  );
278 
279  $this->getMail()->appendInstallationSignature(true);
280 
281  $this->sendMail(array($rcp), array('system'));
282  }
283  break;
284 
285  case self::TYPE_ACCEPTED_SUBSCRIPTION_MEMBER:
286 
287  foreach ($this->getRecipients() as $rcp) {
288  $this->initLanguage($rcp);
289  $this->initMail();
290  $this->setSubject(
291  sprintf($this->getLanguageText('grp_mail_sub_acc_sub'), $this->getObjectTitle(true))
292  );
293  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
294  $this->appendBody("\n\n");
295  $this->appendBody(
296  sprintf($this->getLanguageText('grp_mail_sub_acc_bod'), $this->getObjectTitle())
297  );
298  $this->appendBody("\n\n");
299  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
300  $this->appendBody("\n\n");
301  $this->appendBody($this->createPermanentLink());
302  $this->getMail()->appendInstallationSignature(true);
303 
304  $this->sendMail(array($rcp), array('system'));
305  }
306  break;
307 
308  case self::TYPE_WAITING_LIST_MEMBER:
309  foreach ($this->getRecipients() as $rcp) {
310  $this->initLanguage($rcp);
311  $this->initMail();
312  $this->setSubject(
313  sprintf($this->getLanguageText('grp_mail_wl_sub'), $this->getObjectTitle(true))
314  );
315 
316  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
317 
318  $info = $this->getAdditionalInformation();
319  $this->appendBody("\n\n");
320  $this->appendBody(
321  sprintf(
322  $this->getLanguageText('grp_mail_wl_bod'),
323  $this->getObjectTitle(),
324  $info['position']
325  )
326  );
327  $this->getMail()->appendInstallationSignature(true);
328  $this->sendMail(array($rcp), array('system'));
329  }
330  break;
331 
332 
333  case self::TYPE_STATUS_CHANGED:
334  foreach ($this->getRecipients() as $rcp) {
335  $this->initLanguage($rcp);
336  $this->initMail();
337  $this->setSubject(
338  sprintf($this->getLanguageText('grp_mail_status_sub'), $this->getObjectTitle(true))
339  );
340  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
341  $this->appendBody("\n\n");
342  $this->appendBody(
343  sprintf($this->getLanguageText('grp_mail_status_bod'), $this->getObjectTitle())
344  );
345 
346  $this->appendBody("\n\n");
347  $this->appendBody($this->createGroupStatus($rcp));
348 
349  $this->appendBody("\n\n");
350  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
351  $this->appendBody("\n\n");
352  $this->appendBody($this->createPermanentLink());
353 
354  $this->getMail()->appendInstallationSignature(true);
355 
356  $this->sendMail(array($rcp), array('system'));
357  }
358  break;
359 
360  }
361  return true;
362  }
363 
369  protected function initLanguage($a_usr_id)
370  {
371  parent::initLanguage($a_usr_id);
372  $this->getLanguage()->loadLanguageModule('grp');
373  }
374 
380  protected function createGroupStatus($a_usr_id)
381  {
383 
384  $body = $this->getLanguageText('grp_new_status') . "\n";
385  $body .= $this->getLanguageText('role') . ': ';
386 
387 
388  if ($part->isAdmin($a_usr_id)) {
389  $body .= $this->getLanguageText('il_grp_admin') . "\n";
390  } else {
391  $body .= $this->getLanguageText('il_grp_member') . "\n";
392  }
393 
394  if ($part->isAdmin($a_usr_id)) {
395  $body .= $this->getLanguageText('grp_notification') . ': ';
396 
397  if ($part->isNotificationEnabled($a_usr_id)) {
398  $body .= $this->getLanguageText('grp_notify_on') . "\n";
399  } else {
400  $body .= $this->getLanguageText('grp_notify_off') . "\n";
401  }
402  }
403  return $body;
404  }
405 
413  protected function isNotificationTypeEnabled($a_type)
414  {
415  global $DIC;
416 
417  $ilSetting = $DIC['ilSetting'];
418 
419  return
420  $this->force_sending_mail ||
421  $ilSetting->get('mail_grp_member_notification', true) ||
422  in_array($a_type, $this->permanent_enabled_notifications);
423  }
424 }
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.
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92
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.
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.
$info
Definition: index.php:5
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
static getSalutation($a_usr_id, ilLanguage $a_language=null)