ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBuddySystemNotification.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
11  protected $sender;
12 
14  protected $settings;
15 
17  protected $recipient_ids = [];
18 
24  {
25  $this->sender = $user;
26  $this->settings = $settings;
27  }
28 
32  public function getRecipientIds()
33  {
34  return $this->recipient_ids;
35  }
36 
40  public function setRecipientIds(array $recipient_ids)
41  {
42  $this->recipient_ids = $recipient_ids;
43  }
44 
48  public function send()
49  {
50  foreach ($this->getRecipientIds() as $usr_id) {
51  $user = new ilObjUser((int) $usr_id);
52 
53  $rcp_lng = ilLanguageFactory::_getLanguage($user->getLanguage());
54  $rcp_lng->loadLanguageModule('buddysystem');
55 
56  $notification = new ilNotificationConfig('buddysystem_request');
57  $notification->setTitleVar('buddy_notification_contact_request', array(), 'buddysystem');
58 
59  $personalProfileLink = $rcp_lng->txt('buddy_noti_cr_profile_not_published');
60  if ($this->hasPublicProfile($user->getId())) {
61  $personalProfileLink = \ilLink::_getStaticLink($this->sender->getId(), 'usr', true);
62  }
63 
64  $bodyParams = array(
65  'SALUTATION' => ilMail::getSalutation($user->getId(), $rcp_lng),
66  'BR' => nl2br("\n"),
67  'APPROVE_REQUEST' => '<a href="' . ilLink::_getStaticLink($this->sender->getId(), 'usr', true, '_contact_approved') . '">' . $rcp_lng->txt('buddy_notification_contact_request_link_osd') . '</a>',
68  'IGNORE_REQUEST' => '<a href="' . ilLink::_getStaticLink($this->sender->getId(), 'usr', true, '_contact_ignored') . '">' . $rcp_lng->txt('buddy_notification_contact_request_ignore_osd') . '</a>',
69  'REQUESTING_USER' => ilUserUtil::getNamePresentation($this->sender->getId())
70  );
71  $notification->setShortDescriptionVar('buddy_notification_contact_request_short', $bodyParams, 'buddysystem');
72 
73  $bodyParams = array(
74  'SALUTATION' => ilMail::getSalutation($user->getId(), $rcp_lng),
75  'BR' => "\n",
76  'APPROVE_REQUEST' => ilLink::_getStaticLink($this->sender->getId(), 'usr', true, '_contact_approved'),
77  'APPROVE_REQUEST_TXT' => $rcp_lng->txt('buddy_notification_contact_request_link'),
78  'IGNORE_REQUEST' => ilLink::_getStaticLink($this->sender->getId(), 'usr', true, '_contact_ignored'),
79  'IGNORE_REQUEST_TXT' => $rcp_lng->txt('buddy_notification_contact_request_ignore'),
80  'REQUESTING_USER' => ilUserUtil::getNamePresentation($this->sender->getId()),
81  'PERSONAL_PROFILE_LINK' => $personalProfileLink,
82  );
83  $notification->setLongDescriptionVar('buddy_notification_contact_request_long', $bodyParams, 'buddysystem');
84 
85  $notification->setAutoDisable(false);
86  $notification->setValidForSeconds(ilNotificationConfig::TTL_LONG);
87  $notification->setVisibleForSeconds(ilNotificationConfig::DEFAULT_TTS);
88  $notification->setIconPath('templates/default/images/icon_usr.svg');
89  $notification->setHandlerParam('mail.sender', ANONYMOUS_USER_ID);
90  $notification->notifyByUsers(array($user->getId()));
91  }
92  }
93 
98  protected function hasPublicProfile($recipientUsrId)
99  {
100  $portfolioId = \ilObjPortfolio::getDefaultPortfolio($this->sender->getId());
101  if (is_numeric($portfolioId) && $portfolioId > 0) {
102  $accessHandler = new \ilPortfolioAccessHandler();
103  return $accessHandler->checkAccessOfUser($recipientUsrId, 'read', '', $portfolioId);
104  }
105 
106  return (
107  $this->sender->getPref('public_profile') === 'y' ||
108  $this->sender->getPref('public_profile') === 'g'
109  );
110  }
111 }
settings()
Definition: settings.php:2
Describes a notification and provides methods for publishing this notification.
__construct(ilObjUser $user, \ilSetting $settings)
static _getLanguage($a_lang_key='')
Get langauge object.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
$user
Definition: migrateto20.php:57
static getDefaultPortfolio($a_user_id)
Get default portfolio of user.
static getSalutation($a_usr_id, ilLanguage $a_language=null)