ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilBuddySystemNotification.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
32 {
33  public const CONTACT_REQUEST_KEY = 'contact_requested_by';
35  protected array $recipientIds = [];
36 
37  public function __construct(protected ilObjUser $sender, protected ilSetting $settings)
38  {
39  }
40 
44  public function getRecipientIds(): array
45  {
46  return $this->recipientIds;
47  }
48 
52  public function setRecipientIds(array $recipientIds): void
53  {
54  $this->recipientIds = array_map('intval', $recipientIds);
55  }
56 
57  public function send(): void
58  {
59  foreach ($this->getRecipientIds() as $usr_id) {
60  $user = new ilObjUser($usr_id);
61 
62  $recipientLanguage = ilLanguageFactory::_getLanguage($user->getLanguage());
63  $recipientLanguage->loadLanguageModule('buddysystem');
64 
65  $notification = new ilNotificationConfig(ContactNotificationProvider::NOTIFICATION_TYPE);
66 
67  $personalProfileLink = $recipientLanguage->txt('buddy_noti_cr_profile_not_published');
68  if ($this->hasPublicProfile($this->sender->getId())) {
69  $personalProfileLink = ilLink::_getStaticLink($this->sender->getId(), 'usr', true);
70 
71  $links[] = new ilNotificationLink(
73  $this->sender->getFirstname() . ', ' .
74  $this->sender->getLastname() . ' ' .
75  $this->sender->getLogin()
76  ),
77  $personalProfileLink
78  );
79  }
80  $links[] = new ilNotificationLink(
81  new ilNotificationParameter('buddy_notification_contact_request_link_osd', [], 'buddysystem'),
83  $this->sender->getId(),
84  'usr',
85  true,
86  '_contact_approved'
87  )
88  );
89  $links[] = new ilNotificationLink(
90  new ilNotificationParameter('buddy_notification_contact_request_ignore_osd', [], 'buddysystem'),
92  $this->sender->getId(),
93  'usr',
94  true,
95  '_contact_ignored'
96  )
97  );
98 
99  $bodyParams = [
100  'SALUTATION' => ilMail::getSalutation($user->getId(), $recipientLanguage),
101  'BR' => "\n",
102  'APPROVE_REQUEST' => ilLink::_getStaticLink($this->sender->getId(), 'usr', true, '_contact_approved'),
103  'APPROVE_REQUEST_TXT' => $recipientLanguage->txt('buddy_notification_contact_request_link'),
104  'IGNORE_REQUEST' => ilLink::_getStaticLink($this->sender->getId(), 'usr', true, '_contact_ignored'),
105  'IGNORE_REQUEST_TXT' => $recipientLanguage->txt('buddy_notification_contact_request_ignore'),
106  'REQUESTING_USER' => ilUserUtil::getNamePresentation($this->sender->getId()),
107  'PERSONAL_PROFILE_LINK' => $personalProfileLink,
108  ];
109  $notification->setTitleVar('buddy_notification_contact_request', [], 'buddysystem');
110  $notification->setShortDescriptionVar('buddy_notification_contact_request_short', $bodyParams, 'buddysystem');
111  $notification->setLongDescriptionVar('buddy_notification_contact_request_long', $bodyParams, 'buddysystem');
112  $notification->setLinks($links);
113  $notification->setValidForSeconds(ilNotificationConfig::TTL_LONG);
114  $notification->setVisibleForSeconds(ilNotificationConfig::DEFAULT_TTS);
115  $notification->setIconPath('assets/images/standard/icon_usr.svg');
116  $notification->setHandlerParam('mail.sender', (string) ANONYMOUS_USER_ID);
117  $notification->setIdentification(new NotificationIdentification(
118  ContactNotificationProvider::NOTIFICATION_TYPE,
119  self::CONTACT_REQUEST_KEY . '_' . $this->sender->getId(),
120  ));
121 
122  $notification->notifyByUsers([$user->getId()]);
123  }
124  }
125 
126  protected function hasPublicProfile(int $recipientUsrId): bool
127  {
128  $portfolioId = ilObjPortfolio::getDefaultPortfolio($this->sender->getId());
129  if (is_numeric($portfolioId) && $portfolioId > 0) {
130  return (new ilPortfolioAccessHandler())->checkAccessOfUser($recipientUsrId, 'read', '', $portfolioId);
131  }
132 
133  return (
134  $this->sender->getPref('public_profile') === 'y' ||
135  $this->sender->getPref('public_profile') === 'g'
136  );
137  }
138 }
const ANONYMOUS_USER_ID
Definition: constants.php:27
description of a localized parameter this information is used locate translations while processing no...
static getDefaultPortfolio(int $a_user_id)
__construct(protected ilObjUser $sender, protected ilSetting $settings)
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:
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...