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