ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilSessionMembershipMailNotification.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  public const TYPE_ADMISSION_MEMBER = 20;
30  public const TYPE_DISMISS_MEMBER = 21;
31 
34 
35 
36  public const TYPE_BLOCKED_MEMBER = 25;
37  public const TYPE_UNBLOCKED_MEMBER = 26;
38 
39  public const TYPE_UNSUBSCRIBE_MEMBER = 27;
40  public const TYPE_SUBSCRIBE_MEMBER = 28;
41 
42  public const TYPE_NOTIFICATION_REGISTRATION = 30;
44  public const TYPE_NOTIFICATION_UNSUBSCRIBE = 32;
45 
46  public const TYPE_ENTER_NOTIFICATION = 100;
47  public const TYPE_REGISTER_NOTIFICATION = 101;
48  public const TYPE_UNREGISTER_NOTIFICATION = 102;
49 
50  protected ilSetting $setting;
51 
52  public function __construct()
53  {
54  global $DIC;
55 
56  $this->setting = $DIC->settings();
57 
59  }
60 
61  public function send(int $userId = 0): ?bool
62  {
64 
65  // parent::send();
66 
67  switch ($this->getType()) {
68  case self::TYPE_ADMISSION_MEMBER:
69 
70  // automatic mails about status change disabled
71  if (!$ilSetting->get('mail_grp_member_notification')) {
72  return null;
73  }
74 
75  foreach ($this->getRecipients() as $rcp) {
76  $this->initLanguage($rcp);
77  $this->initMail();
78  $this->setSubject(
79  sprintf($this->getLanguageText('grp_mail_admission_new_sub'), $this->getObjectTitle(true))
80  );
81  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
82  $this->appendBody("\n\n");
83  $this->appendBody(
84  sprintf($this->getLanguageText('grp_mail_admission_new_bod'), $this->getObjectTitle())
85  );
86  $this->appendBody("\n\n");
87  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
88  $this->appendBody("\n\n");
89  $this->appendBody($this->createPermanentLink());
90  $this->getMail()->appendInstallationSignature(true);
91 
92  $this->sendMail(array($rcp));
93  }
94  break;
95 
96  case self::TYPE_DISMISS_MEMBER:
97 
98  // automatic mails about status change disabled
99  if (!$ilSetting->get('mail_grp_member_notification')) {
100  return null;
101  }
102 
103  foreach ($this->getRecipients() as $rcp) {
104  $this->initLanguage($rcp);
105  $this->initMail();
106  $this->setSubject(
107  sprintf($this->getLanguageText('grp_mail_dismiss_sub'), $this->getObjectTitle(true))
108  );
109  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
110  $this->appendBody("\n\n");
111  $this->appendBody(
112  sprintf($this->getLanguageText('grp_mail_dismiss_bod'), $this->getObjectTitle())
113  );
114  $this->getMail()->appendInstallationSignature(true);
115  $this->sendMail(array($rcp));
116  }
117  break;
118 
119  case self::TYPE_SUBSCRIBE_MEMBER:
120 
121  foreach ($this->getRecipients() as $rcp) {
122  $this->initLanguage($rcp);
123  $this->initMail();
124  $this->setSubject(
125  sprintf($this->getLanguageText('grp_mail_subscribe_member_sub'), $this->getObjectTitle(true))
126  );
127  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
128  $this->appendBody("\n\n");
129  $this->appendBody(
130  sprintf($this->getLanguageText('grp_mail_subscribe_member_bod'), $this->getObjectTitle())
131  );
132 
133  $this->appendBody("\n\n");
134  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
135  $this->appendBody("\n\n");
136  $this->appendBody($this->createPermanentLink());
137  $this->getMail()->appendInstallationSignature(true);
138 
139  $this->sendMail(array($rcp));
140  }
141  break;
142 
143  case self::TYPE_NOTIFICATION_REGISTRATION_REQUEST:
144 
145  foreach ($this->getRecipients() as $rcp) {
146  $this->initLanguage($rcp);
147  $this->initMail();
148  $this->setSubject(
149  sprintf($this->getLanguageText('grp_mail_notification_reg_req_sub'), $this->getObjectTitle(true))
150  );
151  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
152  $this->appendBody("\n\n");
153 
154  $info = $this->getAdditionalInformation();
155  $this->appendBody(
156  sprintf(
157  $this->getLanguageText('grp_mail_notification_reg_req_bod'),
158  $this->userToString($info['usr_id']),
159  $this->getObjectTitle()
160  )
161  );
162  $this->appendBody("\n\n");
163  $this->appendBody($this->getLanguageText('grp_mail_notification_reg_req_bod2'));
164  $this->appendBody("\n");
165  $this->appendBody($this->createPermanentLink([], 'mem'));
166 
167  $this->appendBody("\n\n");
168  $this->appendBody($this->getLanguageText('grp_notification_explanation_admin'));
169 
170  $this->getMail()->appendInstallationSignature(true);
171  $this->sendMail(array($rcp));
172  }
173  break;
174 
175  case self::TYPE_REFUSED_SUBSCRIPTION_MEMBER:
176 
177  foreach ($this->getRecipients() as $rcp) {
178  $this->initLanguage($rcp);
179  $this->initMail();
180  $this->setSubject(
181  sprintf($this->getLanguageText('sess_mail_sub_dec_sub'), $this->getObjectTitle(true))
182  );
183  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
184  $this->appendBody("\n\n");
185  $this->appendBody(
186  sprintf($this->getLanguageText('sess_mail_sub_dec_bod'), $this->getObjectTitle())
187  );
188 
189  $this->getMail()->appendInstallationSignature(true);
190 
191  $this->sendMail(array($rcp));
192  }
193  break;
194 
195  case self::TYPE_ACCEPTED_SUBSCRIPTION_MEMBER:
196 
197  foreach ($this->getRecipients() as $rcp) {
198  $this->initLanguage($rcp);
199  $this->initMail();
200  $this->setSubject(
201  sprintf($this->getLanguageText('sess_mail_sub_acc_sub'), $this->getObjectTitle(true))
202  );
203  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
204  $this->appendBody("\n\n");
205  $this->appendBody(
206  sprintf($this->getLanguageText('sess_mail_sub_acc_bod'), $this->getObjectTitle())
207  );
208  $this->appendBody("\n\n");
209  $this->appendBody($this->getLanguageText('sess_mail_permanent_link'));
210  $this->appendBody("\n\n");
211  $this->appendBody($this->createPermanentLink());
212  $this->getMail()->appendInstallationSignature(true);
213 
214  $this->sendMail(array($rcp));
215  }
216  break;
217 
218  case self::TYPE_ENTER_NOTIFICATION:
219  if (0 === $userId) {
220  throw new ilException('No user id given');
221  }
222 
223  $userObject = ilObjectFactory::getInstanceByObjId($userId, false);
224  if (!($userObject instanceof \ilObjUser)) {
225  throw new ilException(sprintf('User with ID "%s" does not exist.', $userId));
226  }
227 
228  foreach ($this->getRecipients() as $rcp) {
229  $this->initLanguage($rcp);
230  $this->initMail();
231  $this->setSubject(
232  sprintf(
233  $this->getLanguageText('session_mail_subject_entered'),
234  $userObject->getFullname(),
235  $this->getObjectTitle(true)
236  )
237  );
238  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
239  $this->appendBody("\n\n");
240  $this->appendBody(
241  sprintf(
242  $this->getLanguageText('entered_notification'),
243  $userObject->getFullname(),
244  $this->getObjectTitle()
245  )
246  );
247  $this->appendBody("\n\n");
248  $this->appendBody($this->getLanguageText('sess_mail_permanent_link_participants'));
249  $this->appendBody("\n\n");
250  $this->appendBody($this->createPermanentLink([], 'part'));
251  $this->getMail()->appendInstallationSignature(true);
252 
253  $this->sendMail(array($rcp));
254  }
255  break;
256 
257  case self::TYPE_REGISTER_NOTIFICATION:
258  if (0 === $userId) {
259  throw new ilException('No user id given');
260  }
261 
262  $userObject = ilObjectFactory::getInstanceByObjId($userId, false);
263  if (!($userObject instanceof \ilObjUser)) {
264  throw new ilException(sprintf('User with ID "%s" does not exist.', $userId));
265  }
266 
267  foreach ($this->getRecipients() as $rcp) {
268  $this->initLanguage($rcp);
269  $this->initMail();
270  $this->setSubject(
271  sprintf(
272  $this->getLanguageText('session_mail_subject_registered'),
273  $userObject->getFullname(),
274  $this->getObjectTitle(true)
275  )
276  );
277  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
278  $this->appendBody("\n\n");
279  $this->appendBody(
280  sprintf(
281  $this->getLanguageText('register_notification'),
282  $userObject->getFullname(),
283  $this->getObjectTitle()
284  )
285  );
286  $this->appendBody("\n\n");
287  $this->appendBody($this->getLanguageText('sess_mail_permanent_link_participants'));
288  $this->appendBody("\n\n");
289  $this->appendBody($this->createPermanentLink([], 'part'));
290  $this->getMail()->appendInstallationSignature(true);
291 
292  $this->sendMail(array($rcp));
293  }
294  break;
295 
296  case self::TYPE_UNREGISTER_NOTIFICATION:
297  if (0 === $userId) {
298  throw new ilException('No user id given');
299  }
300 
301  $userObject = ilObjectFactory::getInstanceByObjId($userId, false);
302  if (!($userObject instanceof \ilObjUser)) {
303  throw new ilException(sprintf('User with ID "%s" does not exist.', $userId));
304  }
305 
306  foreach ($this->getRecipients() as $rcp) {
307  $this->initLanguage($rcp);
308  $this->initMail();
309  $this->setSubject(
310  sprintf(
311  $this->getLanguageText('session_mail_subject_deletion'),
312  $userObject->getFullname(),
313  $this->getObjectTitle(true)
314  )
315  );
316  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
317  $this->appendBody("\n\n");
318  $this->appendBody(
319  sprintf(
320  $this->getLanguageText('deletion_notification'),
321  $userObject->getFullname(),
322  $this->getObjectTitle()
323  )
324  );
325  $this->appendBody("\n\n");
326  $this->appendBody($this->getLanguageText('sess_mail_permanent_link_participants'));
327  $this->appendBody("\n\n");
328  $this->appendBody($this->createPermanentLink([], 'part'));
329  $this->getMail()->appendInstallationSignature(true);
330 
331  $this->sendMail(array($rcp));
332  }
333  break;
334  }
335  return true;
336  }
337 
338  protected function initLanguage(int $a_usr_id): void
339  {
340  parent::initLanguage($a_usr_id);
341  $this->getLanguage()->loadLanguageModule('sess');
342  }
343 }
sendMail(array $a_rcp, bool $a_parse_recipients=true)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
global $DIC
Definition: shib_login.php:22
getLanguageText(string $a_keyword)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
getObjectTitle(bool $a_shorten=false)
createPermanentLink(array $a_params=[], string $a_append='')
global $ilSetting
Definition: privfeed.php:31
__construct(Container $dic, ilPlugin $plugin)
setSubject(string $a_subject)