ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilForumMailNotification Class Reference
+ Inheritance diagram for ilForumMailNotification:
+ Collaboration diagram for ilForumMailNotification:

Public Member Functions

 __construct (private ilForumNotificationMailData $provider, private ilLogger $logger)
 
 sendMail (array $a_rcp, bool $a_parse_recipients=true)
 
 send ()
 
 isCronjob ()
 
 setIsCronjob (bool $is_cronjob)
 
- Public Member Functions inherited from ilMailNotification
 __construct (protected bool $is_in_wsp=false)
 
 setType (int $a_type)
 
 getType ()
 
 setSender (int $a_usr_id)
 
 getSender ()
 
 setRecipients (array $a_rcp)
 
 getRecipients ()
 
 setAttachments (array $a_att)
 
 getAttachments ()
 
 setLangModules (array $a_modules)
 
 getUserLanguage (int $a_usr_id)
 
 setRefId (int $a_id)
 
 getRefId ()
 
 getObjId ()
 
 setObjId (int $a_obj_id)
 
 getObjType ()
 
 setAdditionalInformation (array $a_info)
 
 getAdditionalInformation ()
 
 sendMail (array $a_rcp, bool $a_parse_recipients=true)
 
 getBlockBorder ()
 

Data Fields

const TYPE_THREAD_DELETED = 54
 
const TYPE_POST_NEW = 60
 
const TYPE_POST_ACTIVATION = 61
 
const TYPE_POST_UPDATED = 62
 
const TYPE_POST_CENSORED = 63
 
const TYPE_POST_DELETED = 64
 
const TYPE_POST_ANSWERED = 65
 
const TYPE_POST_UNCENSORED = 66
 
- Data Fields inherited from ilMailNotification
final const SUBJECT_TITLE_LENGTH = 60
 

Protected Member Functions

 initMail ()
 
 setSubject (string $a_subject)
 
 appendAttachments ()
 
 initLanguage (int $a_usr_id)
 
- Protected Member Functions inherited from ilMailNotification
 setSubject (string $a_subject)
 
 getSubject ()
 
 setBody (string $a_body)
 
 appendBody (string $a_body)
 
 getBody ()
 
 initLanguage (int $a_usr_id)
 
 initLanguageByIso2Code (string $a_code='')
 
 setLanguage (ilLanguage $a_language)
 
 getLanguage ()
 
 getLanguageText (string $a_keyword)
 
 getObjectTitle (bool $a_shorten=false)
 
 initMail ()
 
 getMail ()
 
 createPermanentLink (array $a_params=[], string $a_append='')
 
 userToString (int $a_usr_id)
 
 isRefIdAccessible (int $a_user_id, int $a_ref_id, string $a_permission="read")
 

Private Member Functions

 getPermanentLink (string $type=self::PERMANENT_LINK_POST)
 
 getPostMessage ()
 
 sendMailWithAttachments (string $subjectLanguageId, int $userId, string $customText, string $action, string $date='')
 
 sendMailWithoutAttachments (string $subjectLanguageId, int $userId, string $customText, string $action, ?string $date=null)
 
 createMail (string $subject, int $userId, string $customText, string $action, ?string $date)
 
 addMailSubject (string $subject)
 
 createMailDate (string $date)
 
 addLinkToMail ()
 

Private Attributes

const PERMANENT_LINK_POST = 'PL_Post'
 
const PERMANENT_LINK_FORUM = 'PL_Forum'
 
bool $is_cronjob = false
 

Additional Inherited Members

- Protected Attributes inherited from ilMailNotification
int $type
 
int $sender
 
ilMail $mail = null
 
string $subject = ''
 
string $body = ''
 
array $attachments = []
 
ilLanguage $language
 
array $lang_modules = []
 
array $recipients = []
 
int $ref_id
 
int $obj_id = 0
 
string $obj_type = ''
 
array $additional_info = []
 
ilWorkspaceTree $wsp_tree
 
ilWorkspaceAccessHandler $wsp_access_handler
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilForumMailNotification::__construct ( private ilForumNotificationMailData  $provider,
private ilLogger  $logger 
)

Definition at line 39 of file class.ilForumMailNotification.php.

References ILIAS\MetaData\Repository\Validation\Data\__construct().

40  {
41  parent::__construct(false);
42  }
__construct(VocabulariesInterface $vocabularies)
+ Here is the call graph for this function:

Member Function Documentation

◆ addLinkToMail()

ilForumMailNotification::addLinkToMail ( )
private

Definition at line 400 of file class.ilForumMailNotification.php.

References ilMail\_getInstallationSignature(), ilMailNotification\appendBody(), and getPermanentLink().

Referenced by sendMailWithAttachments(), and sendMailWithoutAttachments().

400  : void
401  {
402  $this->appendBody($this->getPermanentLink());
404  }
getPermanentLink(string $type=self::PERMANENT_LINK_POST)
static _getInstallationSignature()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addMailSubject()

ilForumMailNotification::addMailSubject ( string  $subject)
private

Definition at line 370 of file class.ilForumMailNotification.php.

References ilMailNotification\getLanguageText(), initMail(), and setSubject().

Referenced by createMail().

370  : void
371  {
372  $this->initMail();
373 
374  $container_text = '';
375  if ($this->provider->providesClosestContainer()) {
376  $container_text = ' (' .
377  $this->getLanguageText('obj_' . $this->provider->closestContainer()->getType()) .
378  ' "' . $this->provider->closestContainer()->getTitle() . '")';
379  }
380 
381  $this->setSubject(sprintf(
382  $this->getLanguageText($subject),
383  $this->provider->getForumTitle(),
384  $container_text,
385  $this->provider->getThreadTitle()
386  ));
387  }
getLanguageText(string $a_keyword)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendAttachments()

ilForumMailNotification::appendAttachments ( )
protected

Definition at line 68 of file class.ilForumMailNotification.php.

References ilMailNotification\appendBody(), ilMailNotification\getLanguageText(), ILIAS\Repository\logger(), and ilMailNotification\setAttachments().

Referenced by sendMailWithAttachments().

68  : void
69  {
70  if ($this->provider->getAttachments() !== []) {
71  $this->logger->debug('Adding attachments ...');
72  foreach ($this->provider->getAttachments() as $attachment) {
73  $this->appendBody($this->getLanguageText('attachment') . ': ' . $attachment . "\n");
74  }
75  $this->appendBody("\n------------------------------------------------------------\n");
76  $this->setAttachments($this->provider->getAttachments());
77  }
78  }
getLanguageText(string $a_keyword)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createMail()

ilForumMailNotification::createMail ( string  $subject,
int  $userId,
string  $customText,
string  $action,
?string  $date 
)
private

Definition at line 319 of file class.ilForumMailNotification.php.

References $message, addMailSubject(), ilMailNotification\appendBody(), createMailDate(), ilMailNotification\getLanguage(), ilMailNotification\getLanguageText(), getPostMessage(), ilMail\getSalutation(), and ilMailNotification\setBody().

Referenced by sendMailWithAttachments(), and sendMailWithoutAttachments().

325  : void {
326  if (is_string($date)) {
327  $date = $this->createMailDate($date);
328  }
329 
330  $this->addMailSubject($subject);
331 
332  $this->setBody(ilMail::getSalutation($userId, $this->getLanguage()));
333  $this->appendBody("\n\n");
334  $this->appendBody($customText);
335  $this->appendBody("\n\n");
336  $this->appendBody($this->getLanguageText('forum') . ': ' . $this->provider->getForumTitle());
337  $this->appendBody("\n\n");
338  if ($this->provider->providesClosestContainer()) {
339  $this->appendBody(
340  $this->getLanguageText('frm_noti_obj_' . $this->provider->closestContainer()->getType()) . ': ' .
341  $this->provider->closestContainer()->getTitle()
342  );
343  $this->appendBody("\n\n");
344  }
345  $this->appendBody($this->getLanguageText('thread') . ': ' . $this->provider->getThreadTitle());
346  $this->appendBody("\n\n");
347  $this->appendBody($this->getLanguageText($action) . ": \n------------------------------------------------------------\n");
348 
349  $this->appendBody($this->getLanguageText('author') . ': ' . $this->provider->getPostUserName($this->getLanguage()));
350  $this->appendBody("\n");
351  if (is_string($date) && $date !== '') {
352  $this->appendBody($this->getLanguageText('date') . ': ' . $date);
353  $this->appendBody("\n");
354  }
355  $this->appendBody($this->getLanguageText('subject') . ': ' . $this->provider->getPostTitle());
356  $this->appendBody("\n");
357  $this->appendBody($this->getLanguageText('frm_noti_message'));
358  $this->appendBody("\n");
359 
360  $message = strip_tags($this->getPostMessage());
361 
362  if ($this->provider->isPostCensored()) {
363  $message = $this->provider->getCensorshipComment();
364  }
365 
366  $this->appendBody($message . "\n");
367  $this->appendBody("------------------------------------------------------------\n");
368  }
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
getLanguageText(string $a_keyword)
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createMailDate()

ilForumMailNotification::createMailDate ( string  $date)
private

Definition at line 389 of file class.ilForumMailNotification.php.

References ilDatePresentation\formatDate(), IL_CAL_DATETIME, ILIAS\UI\examples\Symbol\Glyph\Language\language(), and ilDatePresentation\setLanguage().

Referenced by createMail().

389  : string
390  {
392 
393  if ($date === '') {
394  $date = $this->provider->getPostDate();
395  }
396 
398  }
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static setLanguage(ilLanguage $a_lng)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPermanentLink()

ilForumMailNotification::getPermanentLink ( string  $type = self::PERMANENT_LINK_POST)
private

Definition at line 239 of file class.ilForumMailNotification.php.

References $DIC, ilMailNotification\$type, ilUtil\_getHttpPath(), CLIENT_ID, ilMailNotification\getLanguageText(), and ILIAS\Repository\logger().

Referenced by addLinkToMail().

239  : string
240  {
241  global $DIC;
242 
243  $ilClientIniFile = $DIC['ilClientIniFile'];
244 
245  if ($type === self::PERMANENT_LINK_FORUM) {
246  $language_text = $this->getLanguageText('forums_notification_show_frm');
247  $forum_parameters = $this->provider->getRefId();
248  } else {
249  $language_text = $this->getLanguageText('forums_notification_show_post');
250  $forum_parameters = $this->provider->getRefId() . '_' . $this->provider->getThreadId() . '_' . $this->provider->getPostId();
251  }
252 
253  $this->logger->debug(sprintf(
254  'Building permanent with parameters %s',
255  $forum_parameters
256  ));
257 
258  $posting_link = sprintf(
259  $language_text,
260  rtrim(ilUtil::_getHttpPath(), '/') . '/goto.php?target=frm_' . $forum_parameters . '&client_id=' . CLIENT_ID
261  ) . "\n\n";
262 
263  $posting_link .= sprintf(
264  $this->getLanguageText('forums_notification_intro'),
265  $ilClientIniFile->readVariable('client', 'name'),
266  rtrim(ilUtil::_getHttpPath(), '/') . '/?client_id=' . CLIENT_ID
267  ) . "\n\n";
268 
269  $this->logger->debug(sprintf(
270  'Link built: %s',
271  $posting_link
272  ));
273 
274  return $posting_link;
275  }
global $DIC
Definition: feed.php:28
const CLIENT_ID
Definition: constants.php:41
getLanguageText(string $a_keyword)
static _getHttpPath()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPostMessage()

ilForumMailNotification::getPostMessage ( )
private

Definition at line 277 of file class.ilForumMailNotification.php.

Referenced by createMail().

277  : string
278  {
279  $pos_message = $this->provider->getPostMessage();
280  if (strip_tags($pos_message) !== $pos_message) {
281  $pos_message = preg_replace("/\n/i", '', $pos_message);
282  $pos_message = preg_replace('/<li([^>]*)>/i', "\n<li$1>", $pos_message);
283  $pos_message = preg_replace("/<\/ul([^>]*)>(?!\s*?(<p|<ul))/i", "</ul$1>\n", $pos_message);
284  $pos_message = preg_replace("/<br(\s*)(\/?)>/i", "\n", $pos_message);
285  $pos_message = preg_replace('/<p([^>]*)>/i', "\n\n", $pos_message);
286  $pos_message = preg_replace("/<\/p([^>]*)>/i", '', $pos_message);
287 
288  return $pos_message;
289  }
290 
291  return $pos_message;
292  }
+ Here is the caller graph for this function:

◆ initLanguage()

ilForumMailNotification::initLanguage ( int  $a_usr_id)
protected

Definition at line 223 of file class.ilForumMailNotification.php.

References ILIAS\UI\examples\Symbol\Glyph\Language\language().

Referenced by send().

223  : void
224  {
225  parent::initLanguage($a_usr_id);
226  $this->language->loadLanguageModule('forum');
227  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initMail()

ilForumMailNotification::initMail ( )
protected

Definition at line 44 of file class.ilForumMailNotification.php.

References ilMailNotification\$mail, and ILIAS\Repository\logger().

Referenced by addMailSubject().

44  : ilMail
45  {
46  $mail = parent::initMail();
47  $this->logger->debug('Initialized mail service');
48  return $mail;
49  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isCronjob()

ilForumMailNotification::isCronjob ( )

Definition at line 229 of file class.ilForumMailNotification.php.

References $is_cronjob.

229  : bool
230  {
231  return $this->is_cronjob;
232  }

◆ send()

ilForumMailNotification::send ( )

Definition at line 80 of file class.ilForumMailNotification.php.

References $DIC, $ilSetting, $lng, ilMailNotification\getLanguageText(), ilMailNotification\getRecipients(), ilMailNotification\getType(), initLanguage(), ILIAS\Repository\logger(), sendMailWithAttachments(), sendMailWithoutAttachments(), ilDatePresentation\setLanguage(), ilDatePresentation\setUseRelativeDates(), and ilDatePresentation\useRelativeDates().

80  : bool
81  {
82  global $DIC;
83  $ilSetting = $DIC->settings();
84  $lng = $DIC->language();
85 
86  if (!$ilSetting->get('forum_notification', '0')) {
87  $this->logger->debug('Forum notifications are globally disabled');
88  return false;
89  }
90 
91  if (!$this->getRecipients()) {
92  $this->logger->debug('No notification recipients, nothing to do');
93  return false;
94  }
95 
96  $lng->loadLanguageModule('forum');
97 
100 
101  switch ($this->getType()) {
102  case self::TYPE_THREAD_DELETED:
103  foreach ($this->getRecipients() as $rcp) {
104  $this->initLanguage($rcp);
105  $customText = sprintf(
106  $this->getLanguageText('thread_deleted_by'),
107  $this->provider->getDeletedBy(),
108  $this->provider->getForumTitle()
109  );
111  'frm_noti_subject_del_thread',
112  (int) $rcp,
113  $customText,
114  'content_deleted_thread'
115  );
116  }
117  break;
118 
119  case self::TYPE_POST_NEW:
120  foreach ($this->getRecipients() as $rcp) {
121  $this->initLanguage($rcp);
122  $customText = sprintf(
123  $this->getLanguageText('frm_noti_new_post'),
124  $this->provider->getForumTitle()
125  );
126  $this->sendMailWithAttachments('frm_noti_subject_new_post', (int) $rcp, $customText, 'new_post');
127  }
128  break;
129 
130  case self::TYPE_POST_ACTIVATION:
131  foreach ($this->getRecipients() as $rcp) {
132  $this->initLanguage($rcp);
133  $customText = $this->getLanguageText('forums_post_activation_mail');
134  $this->sendMailWithAttachments('frm_noti_subject_act_post', (int) $rcp, $customText, 'new_post');
135  }
136  break;
137 
138  case self::TYPE_POST_ANSWERED:
139  foreach ($this->getRecipients() as $rcp) {
140  $this->initLanguage($rcp);
141  $customText = $this->getLanguageText('forum_post_replied');
142  $this->sendMailWithAttachments('frm_noti_subject_answ_post', (int) $rcp, $customText, 'new_post');
143  }
144  break;
145 
146  case self::TYPE_POST_UPDATED:
147  foreach ($this->getRecipients() as $rcp) {
148  $this->initLanguage($rcp);
149  $customText = sprintf(
150  $this->getLanguageText('post_updated_by'),
151  $this->provider->getPostUpdateUserName($this->getLanguage()),
152  $this->provider->getForumTitle()
153  );
155  'frm_noti_subject_upt_post',
156  (int) $rcp,
157  $customText,
158  'content_post_updated',
159  $this->provider->getPostUpdate()
160  );
161  }
162  break;
163 
164  case self::TYPE_POST_CENSORED:
165  foreach ($this->getRecipients() as $rcp) {
166  $this->initLanguage($rcp);
167  $customText = sprintf(
168  $this->getLanguageText('post_censored_by'),
169  $this->provider->getPostUpdateUserName($this->getLanguage()),
170  $this->provider->getForumTitle()
171  );
173  'frm_noti_subject_cens_post',
174  (int) $rcp,
175  $customText,
176  'content_censored_post',
177  $this->provider->getPostCensoredDate()
178  );
179  }
180  break;
181 
182  case self::TYPE_POST_UNCENSORED:
183  foreach ($this->getRecipients() as $rcp) {
184  $this->initLanguage($rcp);
185  $customText = sprintf(
186  $this->getLanguageText('post_uncensored_by'),
187  $this->provider->getPostUpdateUserName($this->getLanguage())
188  );
190  'frm_noti_subject_uncens_post',
191  (int) $rcp,
192  $customText,
193  'forums_the_post',
194  $this->provider->getPostCensoredDate()
195  );
196  }
197  break;
198 
199  case self::TYPE_POST_DELETED:
200  foreach ($this->getRecipients() as $rcp) {
201  $this->initLanguage($rcp);
202  $customText = sprintf(
203  $this->getLanguageText('post_deleted_by'),
204  $this->provider->getDeletedBy(),
205  $this->provider->getForumTitle()
206  );
208  'frm_noti_subject_del_post',
209  (int) $rcp,
210  $customText,
211  'content_deleted_post'
212  );
213  }
214  break;
215  }
216 
219 
220  return true;
221  }
static setLanguage(ilLanguage $a_lng)
sendMailWithAttachments(string $subjectLanguageId, int $userId, string $customText, string $action, string $date='')
global $DIC
Definition: feed.php:28
$lng
getLanguageText(string $a_keyword)
sendMailWithoutAttachments(string $subjectLanguageId, int $userId, string $customText, string $action, ?string $date=null)
global $ilSetting
Definition: privfeed.php:18
static setUseRelativeDates(bool $a_status)
set use relative dates
+ Here is the call graph for this function:

◆ sendMail()

ilForumMailNotification::sendMail ( array  $a_rcp,
bool  $a_parse_recipients = true 
)

Definition at line 51 of file class.ilForumMailNotification.php.

References ILIAS\Repository\logger().

Referenced by sendMailWithAttachments(), and sendMailWithoutAttachments().

51  : void
52  {
53  $this->logger->debug(sprintf(
54  'Delegating notification transport to mail service for recipients: %s',
55  print_r($a_rcp, true)
56  ));
57  parent::sendMail($a_rcp, $a_parse_recipients);
58  $this->logger->debug('Notification transport delegated');
59  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendMailWithAttachments()

ilForumMailNotification::sendMailWithAttachments ( string  $subjectLanguageId,
int  $userId,
string  $customText,
string  $action,
string  $date = '' 
)
private

Definition at line 294 of file class.ilForumMailNotification.php.

References addLinkToMail(), appendAttachments(), createMail(), and sendMail().

Referenced by send().

300  : void {
301  $this->createMail($subjectLanguageId, $userId, $customText, $action, $date);
302  $this->appendAttachments();
303  $this->addLinkToMail();
304  $this->sendMail([$userId]);
305  }
createMail(string $subject, int $userId, string $customText, string $action, ?string $date)
sendMail(array $a_rcp, bool $a_parse_recipients=true)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendMailWithoutAttachments()

ilForumMailNotification::sendMailWithoutAttachments ( string  $subjectLanguageId,
int  $userId,
string  $customText,
string  $action,
?string  $date = null 
)
private

Definition at line 307 of file class.ilForumMailNotification.php.

References addLinkToMail(), createMail(), and sendMail().

Referenced by send().

313  : void {
314  $this->createMail($subjectLanguageId, $userId, $customText, $action, $date);
315  $this->addLinkToMail();
316  $this->sendMail([$userId]);
317  }
createMail(string $subject, int $userId, string $customText, string $action, ?string $date)
sendMail(array $a_rcp, bool $a_parse_recipients=true)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setIsCronjob()

ilForumMailNotification::setIsCronjob ( bool  $is_cronjob)

Definition at line 234 of file class.ilForumMailNotification.php.

References $is_cronjob.

234  : void
235  {
236  $this->is_cronjob = $is_cronjob;
237  }

◆ setSubject()

ilForumMailNotification::setSubject ( string  $a_subject)
protected

Definition at line 61 of file class.ilForumMailNotification.php.

References ILIAS\Repository\logger().

Referenced by addMailSubject().

61  : string
62  {
63  $value = parent::setSubject($a_subject);
64  $this->logger->debug(sprintf('Setting subject to: %s', $a_subject));
65  return $value;
66  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $is_cronjob

bool ilForumMailNotification::$is_cronjob = false
private

Definition at line 37 of file class.ilForumMailNotification.php.

Referenced by isCronjob(), and setIsCronjob().

◆ PERMANENT_LINK_FORUM

const ilForumMailNotification::PERMANENT_LINK_FORUM = 'PL_Forum'
private

Definition at line 27 of file class.ilForumMailNotification.php.

◆ PERMANENT_LINK_POST

const ilForumMailNotification::PERMANENT_LINK_POST = 'PL_Post'
private

Definition at line 26 of file class.ilForumMailNotification.php.

◆ TYPE_POST_ACTIVATION

const ilForumMailNotification::TYPE_POST_ACTIVATION = 61

◆ TYPE_POST_ANSWERED

const ilForumMailNotification::TYPE_POST_ANSWERED = 65

◆ TYPE_POST_CENSORED

const ilForumMailNotification::TYPE_POST_CENSORED = 63

◆ TYPE_POST_DELETED

◆ TYPE_POST_NEW

const ilForumMailNotification::TYPE_POST_NEW = 60

◆ TYPE_POST_UNCENSORED

const ilForumMailNotification::TYPE_POST_UNCENSORED = 66

◆ TYPE_POST_UPDATED

const ilForumMailNotification::TYPE_POST_UPDATED = 62

◆ TYPE_THREAD_DELETED


The documentation for this class was generated from the following file: