ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLearningSequenceMembershipMailNotification.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
9 {
10  // v Notifications affect members & co. v
12  const TYPE_DISMISS_MEMBER = 21;
15  const TYPE_STATUS_CHANGED = 24;
16  const TYPE_BLOCKED_MEMBER = 25;
21 
22  // v Notifications affect admins v
26 
32  self::TYPE_NOTIFICATION_REGISTRATION,
33  self::TYPE_NOTIFICATION_REGISTRATION_REQUEST,
34  self::TYPE_NOTIFICATION_UNSUBSCRIBE
35  );
36 
37  private $force_sending_mail = false;
38 
42  protected $logger;
43 
44  public function __construct(ilLogger $logger, ilSetting $settings)
45  {
46  parent::__construct();
47 
48  $this->logger = $logger;
49  $this->settings = $settings;
50  }
51 
52  public function forceSendingMail(bool $status)
53  {
54  $this->force_sending_mail = $status;
55  }
56 
57  public function send() : bool
58  {
59  if (!$this->isNotificationTypeEnabled($this->getType())) {
60  $this->logger->info('Membership mail disabled globally.');
61  return false;
62  }
63 
64  switch ($this->getType()) {
65  case self::TYPE_ADMISSION_MEMBER:
66  foreach ($this->getRecipients() as $rcp) {
67  $this->initLanguage($rcp);
68  $this->initMail();
69  $this->setSubject(sprintf(
70  $this->getLanguageText('lso_mail_admission_new_sub'),
71  $this->getObjectTitle(true)
72  ));
74  $rcp,
75  $this->getLanguage()
76  ));
77  $this->appendBody("\n\n");
78  $this->appendBody(sprintf(
79  $this->getLanguageText('lso_mail_admission_new_bod'),
80  $this->getObjectTitle()
81  ));
82  $this->appendBody("\n\n");
83  $this->appendBody(
84  $this->getLanguageText('lso_mail_permanent_link')
85  );
86  $this->appendBody("\n\n");
87  $this->appendBody($this->createPermanentLink());
88  $this->getMail()->appendInstallationSignature(true);
89  $this->sendMail(array($rcp), array('system'));
90  }
91  break;
92  case self::TYPE_DISMISS_MEMBER:
93  foreach ($this->getRecipients() as $rcp) {
94  $this->initLanguage($rcp);
95  $this->initMail();
96  $this->setSubject(sprintf(
97  $this->getLanguageText('lso_mail_dismiss_sub'),
98  $this->getObjectTitle(true)
99  ));
101  $rcp,
102  $this->getLanguage()
103  ));
104  $this->appendBody("\n\n");
105  $this->appendBody(sprintf(
106  $this->getLanguageText('lso_mail_dismiss_bod'),
107  $this->getObjectTitle()
108  ));
109  $this->getMail()->appendInstallationSignature(true);
110  $this->sendMail(array($rcp), array('system'));
111  }
112  break;
113  case self::TYPE_NOTIFICATION_REGISTRATION:
114  foreach ($this->getRecipients() as $rcp) {
115  $this->initLanguage($rcp);
116  $this->initMail();
117  $this->setSubject(sprintf(
118  $this->getLanguageText('lso_mail_notification_reg_sub'),
119  $this->getObjectTitle(true)
120  ));
122  $rcp,
123  $this->getLanguage()
124  ));
125  $this->appendBody("\n\n");
126  $info = $this->getAdditionalInformation();
127  $this->appendBody(sprintf(
128  $this->getLanguageText('lso_mail_notification_reg_bod'),
129  $this->userToString($info['usr_id']),
130  $this->getObjectTitle()
131  ));
132  $this->appendBody("\n\n");
133  $this->appendBody(
134  $this->getLanguageText('lso_mail_permanent_link')
135  );
136  $this->appendBody("\n\n");
137  $this->appendBody(
138  $this->createPermanentLink(array(), '_mem')
139  );
140  $this->appendBody("\n\n");
141  $this->appendBody($this->getLanguageText(
142  'lso_notification_explanation_admin'
143  ));
144  $this->getMail()->appendInstallationSignature(true);
145  $this->sendMail(array($rcp), array('system'));
146  }
147  break;
148  case self::TYPE_UNSUBSCRIBE_MEMBER:
149  foreach ($this->getRecipients() as $rcp) {
150  $this->initLanguage($rcp);
151  $this->initMail();
152  $this->setSubject(sprintf(
153  $this->getLanguageText('lso_mail_unsubscribe_member_sub'),
154  $this->getObjectTitle(true)
155  ));
157  $rcp,
158  $this->getLanguage()
159  ));
160  $this->appendBody("\n\n");
161  $this->appendBody(sprintf(
162  $this->getLanguageText('lso_mail_unsubscribe_member_bod'),
163  $this->getObjectTitle()
164  ));
165  $this->getMail()->appendInstallationSignature(true);
166  $this->sendMail(array($rcp), array('system'));
167  }
168  break;
169  case self::TYPE_NOTIFICATION_UNSUBSCRIBE:
170  foreach ($this->getRecipients() as $rcp) {
171  $this->initLanguage($rcp);
172  $this->initMail();
173  $this->setSubject(sprintf(
174  $this->getLanguageText('lso_mail_notification_unsub_sub'),
175  $this->getObjectTitle(true)
176  ));
178  $rcp,
179  $this->getLanguage()
180  ));
181  $this->appendBody("\n\n");
182  $info = $this->getAdditionalInformation();
183  $this->appendBody(sprintf(
184  $this->getLanguageText('lso_mail_notification_unsub_bod'),
185  $this->userToString($info['usr_id']),
186  $this->getObjectTitle()
187  ));
188  $this->appendBody("\n\n");
189  $this->appendBody(
190  $this->getLanguageText(
191  'lso_mail_notification_unsub_bod2'
192  )
193  );
194  $this->appendBody("\n\n");
195  $this->appendBody($this->createPermanentLink(
196  array(),
197  '_mem'
198  ));
199  $this->appendBody("\n\n");
200  $this->appendBody(
201  $this->getLanguageText(
202  'lso_notification_explanation_admin'
203  )
204  );
205  $this->getMail()->appendInstallationSignature(true);
206  $this->sendMail(array($rcp), array('system'));
207  }
208  break;
209  case self::TYPE_SUBSCRIBE_MEMBER:
210  foreach ($this->getRecipients() as $rcp) {
211  $this->initLanguage($rcp);
212  $this->initMail();
213  $this->setSubject(sprintf(
214  $this->getLanguageText('grp_mail_subscribe_member_sub'),
215  $this->getObjectTitle(true)
216  ));
218  $rcp,
219  $this->getLanguage()
220  ));
221  $this->appendBody("\n\n");
222  $this->appendBody(
223  sprintf(
224  $this->getLanguageText('grp_mail_subscribe_member_bod'),
225  $this->getObjectTitle()
226  )
227  );
228  $this->appendBody("\n\n");
229  $this->appendBody(
230  $this->getLanguageText('grp_mail_permanent_link')
231  );
232  $this->appendBody("\n\n");
233  $this->appendBody($this->createPermanentLink());
234  $this->getMail()->appendInstallationSignature(true);
235  $this->sendMail(array($rcp), array('system'));
236  }
237  break;
238  case self::TYPE_NOTIFICATION_REGISTRATION_REQUEST:
239  foreach ($this->getRecipients() as $rcp) {
240  $this->initLanguage($rcp);
241  $this->initMail();
242  $this->setSubject(sprintf(
243  $this->getLanguageText('grp_mail_notification_reg_req_sub'),
244  $this->getObjectTitle(true)
245  ));
247  $rcp,
248  $this->getLanguage()
249  ));
250  $this->appendBody("\n\n");
251  $info = $this->getAdditionalInformation();
252  $this->appendBody(sprintf(
253  $this->getLanguageText('grp_mail_notification_reg_req_bod'),
254  $this->userToString($info['usr_id']),
255  $this->getObjectTitle()
256  ));
257  $this->appendBody("\n\n");
258  $this->appendBody(
259  $this->getLanguageText('grp_mail_notification_reg_req_bod2')
260  );
261  $this->appendBody("\n");
262  $this->appendBody($this->createPermanentLink(array(), '_mem'));
263  $this->appendBody("\n\n");
264  $this->appendBody(
265  $this->getLanguageText('grp_notification_explanation_admin')
266  );
267  $this->getMail()->appendInstallationSignature(true);
268  $this->sendMail(array($rcp), array('system'));
269  }
270  break;
271  case self::TYPE_REFUSED_SUBSCRIPTION_MEMBER:
272  foreach ($this->getRecipients() as $rcp) {
273  $this->initLanguage($rcp);
274  $this->initMail();
275  $this->setSubject(sprintf(
276  $this->getLanguageText('grp_mail_sub_dec_sub'),
277  $this->getObjectTitle(true)
278  ));
280  $rcp,
281  $this->getLanguage()
282  ));
283  $this->appendBody("\n\n");
284  $this->appendBody(sprintf(
285  $this->getLanguageText('grp_mail_sub_dec_bod'),
286  $this->getObjectTitle()
287  ));
288  $this->getMail()->appendInstallationSignature(true);
289  $this->sendMail(array($rcp), array('system'));
290  }
291  break;
292  case self::TYPE_ACCEPTED_SUBSCRIPTION_MEMBER:
293  foreach ($this->getRecipients() as $rcp) {
294  $this->initLanguage($rcp);
295  $this->initMail();
296  $this->setSubject(sprintf(
297  $this->getLanguageText('grp_mail_sub_acc_sub'),
298  $this->getObjectTitle(true)
299  ));
300  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
301  $this->appendBody("\n\n");
302  $this->appendBody(sprintf(
303  $this->getLanguageText('grp_mail_sub_acc_bod'),
304  $this->getObjectTitle()
305  ));
306  $this->appendBody("\n\n");
307  $this->appendBody(
308  $this->getLanguageText('grp_mail_permanent_link')
309  );
310  $this->appendBody("\n\n");
311  $this->appendBody($this->createPermanentLink());
312  $this->getMail()->appendInstallationSignature(true);
313  $this->sendMail(array($rcp), array('system'));
314  }
315  break;
316  case self::TYPE_WAITING_LIST_MEMBER:
317  foreach ($this->getRecipients() as $rcp) {
318  $this->initLanguage($rcp);
319  $this->initMail();
320  $this->setSubject(sprintf(
321  $this->getLanguageText('grp_mail_wl_sub'),
322  $this->getObjectTitle(true)
323  ));
325  $rcp,
326  $this->getLanguage()
327  ));
328  $info = $this->getAdditionalInformation();
329  $this->appendBody("\n\n");
330  $this->appendBody(sprintf(
331  $this->getLanguageText('grp_mail_wl_bod'),
332  $this->getObjectTitle(),
333  $info['position']
334  ));
335  $this->getMail()->appendInstallationSignature(true);
336  $this->sendMail(array($rcp), array('system'));
337  }
338  break;
339  case self::TYPE_STATUS_CHANGED:
340  foreach ($this->getRecipients() as $rcp) {
341  $this->initLanguage($rcp);
342  $this->initMail();
343  $this->setSubject(sprintf(
344  $this->getLanguageText('grp_mail_status_sub'),
345  $this->getObjectTitle(true)
346  ));
348  $rcp,
349  $this->getLanguage()
350  ));
351  $this->appendBody("\n\n");
352  $this->appendBody(sprintf(
353  $this->getLanguageText('grp_mail_status_bod'),
354  $this->getObjectTitle()
355  ));
356  $this->appendBody("\n\n");
357  $this->appendBody($this->createLearningSequenceStatus((int) $rcp));
358  $this->appendBody("\n\n");
359  $this->appendBody(
360  $this->getLanguageText('grp_mail_permanent_link')
361  );
362  $this->appendBody("\n\n");
363  $this->appendBody($this->createPermanentLink());
364  $this->getMail()->appendInstallationSignature(true);
365  $this->sendMail(array($rcp), array('system'));
366  }
367  break;
368  }
369  return true;
370  }
371 
372  protected function initLanguage($usr_id)
373  {
374  parent::initLanguage($usr_id);
375  $this->getLanguage()->loadLanguageModule('lso');
376  }
377 
378  protected function createLearningSequenceStatus(int $usr_id) : string
379  {
381  $body = $this->getLanguageText('lso_new_status') . "\n";
382  $body .= $this->getLanguageText('role') . ': ';
383 
384  if ($part->isAdmin($usr_id)) {
385  $body .= $this->getLanguageText('il_lso_admin') . "\n";
386  } else {
387  $body .= $this->getLanguageText('il_lso_member') . "\n";
388  }
389 
390  if ($part->isAdmin($usr_id)) {
391  $body .= $this->getLanguageText('lso_notification') . ': ';
392 
393  if ($part->isNotificationEnabled($usr_id)) {
394  $body .= $this->getLanguageText('lso_notify_on') . "\n";
395  } else {
396  $body .= $this->getLanguageText('lso_notify_off') . "\n";
397  }
398  }
399 
400  return $body;
401  }
402 
403  protected function isNotificationTypeEnabled(int $type) : bool
404  {
405  return (
406  $this->force_sending_mail ||
407  $this->settings->get('mail_lso_member_notification', true) ||
408  in_array($type, $this->permanent_enabled_notifications)
409  );
410  }
411 }
getType()
Get notification type.
settings()
Definition: settings.php:2
$permanent_enabled_notifications
Notifications which are not affected by "mail_grp_member_notification" setting because they addresses...
Base class for course/group mail notifications.
getObjectTitle($a_shorten=false)
sendMail(array $a_rcp, $a_type, $a_parse_recipients=true)
getRecipients()
get array of recipients
createPermanentLink($a_params=array(), $a_append='')
appendBody($a_body)
Append body text.
Component logger with individual log levels by component id.
$info
Definition: index.php:5
static getSalutation($a_usr_id, ilLanguage $a_language=null)