ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilBuddySystemNotification.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 
27 
33 {
34  public const CONTACT_REQUEST_KEY = 'contact_requested_by';
35  protected ilObjUser $sender;
36  protected ilSetting $settings;
38  protected array $recipientIds = [];
39 
44  public function __construct(ilObjUser $user, ilSetting $settings)
45  {
46  $this->sender = $user;
47  $this->settings = $settings;
48  }
49 
53  public function getRecipientIds(): array
54  {
55  return $this->recipientIds;
56  }
57 
61  public function setRecipientIds(array $recipientIds): void
62  {
63  $this->recipientIds = array_map('intval', $recipientIds);
64  }
65 
66  public function send(): void
67  {
68  foreach ($this->getRecipientIds() as $usr_id) {
69  $user = new ilObjUser($usr_id);
70 
71  $recipientLanguage = ilLanguageFactory::_getLanguage($user->getLanguage());
72  $recipientLanguage->loadLanguageModule('buddysystem');
73 
74  $notification = new ilNotificationConfig(ContactNotificationProvider::NOTIFICATION_TYPE);
75 
76  $personalProfileLink = $recipientLanguage->txt('buddy_noti_cr_profile_not_published');
77  if ($this->hasPublicProfile($this->sender->getId())) {
78  $personalProfileLink = ilLink::_getStaticLink($this->sender->getId(), 'usr', true);
79 
80  $links[] = new ilNotificationLink(
82  $this->sender->getFirstname() . ', ' .
83  $this->sender->getLastname() . ' ' .
84  $this->sender->getLogin()
85  ),
86  $personalProfileLink
87  );
88  }
89  $links[] = new ilNotificationLink(
90  new ilNotificationParameter('buddy_notification_contact_request_link_osd', [], 'buddysystem'),
92  $this->sender->getId(),
93  'usr',
94  true,
95  '_contact_approved'
96  )
97  );
98  $links[] = new ilNotificationLink(
99  new ilNotificationParameter('buddy_notification_contact_request_ignore_osd', [], 'buddysystem'),
101  $this->sender->getId(),
102  'usr',
103  true,
104  '_contact_ignored'
105  )
106  );
107 
108  $bodyParams = [
109  'SALUTATION' => ilMail::getSalutation($user->getId(), $recipientLanguage),
110  'BR' => "\n",
111  'APPROVE_REQUEST' => ilLink::_getStaticLink($this->sender->getId(), 'usr', true, '_contact_approved'),
112  'APPROVE_REQUEST_TXT' => $recipientLanguage->txt('buddy_notification_contact_request_link'),
113  'IGNORE_REQUEST' => ilLink::_getStaticLink($this->sender->getId(), 'usr', true, '_contact_ignored'),
114  'IGNORE_REQUEST_TXT' => $recipientLanguage->txt('buddy_notification_contact_request_ignore'),
115  'REQUESTING_USER' => ilUserUtil::getNamePresentation($this->sender->getId()),
116  'PERSONAL_PROFILE_LINK' => $personalProfileLink,
117  ];
118  $notification->setTitleVar('buddy_notification_contact_request', [], 'buddysystem');
119  $notification->setShortDescriptionVar('buddy_notification_contact_request_short', $bodyParams, 'buddysystem');
120  $notification->setLongDescriptionVar('buddy_notification_contact_request_long', $bodyParams, 'buddysystem');
121  $notification->setLinks($links);
122  $notification->setValidForSeconds(ilNotificationConfig::TTL_LONG);
123  $notification->setVisibleForSeconds(ilNotificationConfig::DEFAULT_TTS);
124  $notification->setIconPath('templates/default/images/icon_usr.svg');
125  $notification->setHandlerParam('mail.sender', (string) ANONYMOUS_USER_ID);
126  $notification->setIdentification(new NotificationIdentification(
127  ContactNotificationProvider::NOTIFICATION_TYPE,
128  self::CONTACT_REQUEST_KEY . '_' . $this->sender->getId(),
129  ));
130 
131  $notification->notifyByUsers([$user->getId()]);
132  }
133  }
134 
135  protected function hasPublicProfile(int $recipientUsrId): bool
136  {
137  $portfolioId = ilObjPortfolio::getDefaultPortfolio($this->sender->getId());
138  if (is_numeric($portfolioId) && $portfolioId > 0) {
139  return (new ilPortfolioAccessHandler())->checkAccessOfUser($recipientUsrId, 'read', '', $portfolioId);
140  }
141 
142  return (
143  $this->sender->getPref('public_profile') === 'y' ||
144  $this->sender->getPref('public_profile') === 'g'
145  );
146  }
147 }
const ANONYMOUS_USER_ID
Definition: constants.php:27
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
description of a localized parameter this information is used locate translations while processing no...
static getDefaultPortfolio(int $a_user_id)
Get default portfolio of user.
__construct(ilObjUser $user, ilSetting $settings)
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
static _getLanguage(string $a_lang_key='')
Get language object.
Access handler for portfolio NOTE: This file needs to stay in the classes directory, WAC will be confused otherwise.