ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilBuddySystemNotification.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26
28{
29 public const string CONTACT_REQUEST_KEY = 'contact_requested_by';
30
32 protected array $recipient_ids = [];
33
34 public function __construct(protected ilObjUser $sender, protected ilSetting $settings)
35 {
36 }
37
41 public function getRecipientIds(): array
42 {
44 }
45
49 public function setRecipientIds(array $recipient_ids): void
50 {
51 $this->recipient_ids = array_map('\intval', $recipient_ids);
52 }
53
54 public function send(): void
55 {
56 foreach ($this->getRecipientIds() as $usr_id) {
57 $user = new ilObjUser($usr_id);
58
59 $recipient_language = ilLanguageFactory::_getLanguage($user->getLanguage());
60 $recipient_language->loadLanguageModule('buddysystem');
61
62 $notification = new ilNotificationConfig(ContactNotificationProvider::NOTIFICATION_TYPE);
63
64 $approve_url = ilLink::_getLink($this->sender->getId(), 'contact', ['approve']);
65 $ignore_url = ilLink::_getLink($this->sender->getId(), 'contact', ['ignore']);
66
67 $profile_url = $recipient_language->txt('buddy_noti_cr_profile_not_published');
68 if ($this->hasPublicProfile($this->sender->getId())) {
69 $profile_url = 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 $profile_url
78 );
79 }
80 $links[] = new ilNotificationLink(
81 new ilNotificationParameter('buddy_notification_contact_request_link_osd', [], 'buddysystem'),
82 $approve_url
83 );
84 $links[] = new ilNotificationLink(
85 new ilNotificationParameter('buddy_notification_contact_request_ignore_osd', [], 'buddysystem'),
86 $ignore_url
87 );
88
89 $body_params = [
90 'SALUTATION' => ilMail::getSalutation($user->getId(), $recipient_language),
91 'BR' => "\n",
92 'APPROVE_REQUEST' => $approve_url,
93 'APPROVE_REQUEST_TXT' => $recipient_language->txt('buddy_notification_contact_request_link'),
94 'IGNORE_REQUEST' => $ignore_url,
95 'IGNORE_REQUEST_TXT' => $recipient_language->txt('buddy_notification_contact_request_ignore'),
96 'REQUESTING_USER' => ilUserUtil::getNamePresentation($this->sender->getId()),
97 'PERSONAL_PROFILE_LINK' => $profile_url,
98 ];
99 $notification->setTitleVar('buddy_notification_contact_request', [], 'buddysystem');
100 $notification->setShortDescriptionVar('buddy_notification_contact_request_short', $body_params, 'buddysystem');
101 $notification->setLongDescriptionVar('buddy_notification_contact_request_long', $body_params, 'buddysystem');
102 $notification->setLinks($links);
103 $notification->setValidForSeconds(ilNotificationConfig::TTL_LONG);
104 $notification->setVisibleForSeconds(ilNotificationConfig::DEFAULT_TTS);
105 $notification->setIconPath('assets/images/standard/icon_usr.svg');
106 $notification->setHandlerParam('mail.sender', (string) ANONYMOUS_USER_ID);
107 $notification->setIdentification(new NotificationIdentification(
108 ContactNotificationProvider::NOTIFICATION_TYPE,
109 self::CONTACT_REQUEST_KEY . '_' . $this->sender->getId(),
110 ));
111
112 $notification->notifyByUsers([$user->getId()]);
113 }
114 }
115
116 protected function hasPublicProfile(int $recipientUsrId): bool
117 {
118 $portfolio_id = ilObjPortfolio::getDefaultPortfolio($this->sender->getId());
119 if (is_numeric($portfolio_id) && $portfolio_id > 0) {
120 return (new ilPortfolioAccessHandler())->checkAccessOfUser($recipientUsrId, 'read', '', $portfolio_id);
121 }
122
123 return (
124 $this->sender->getPref('public_profile') === 'y' ||
125 $this->sender->getPref('public_profile') === 'g'
126 );
127 }
128}
description of a localized parameter this information is used locate translations while processing no...
__construct(protected ilObjUser $sender, protected ilSetting $settings)
static _getLanguage(string $a_lang_key='')
Get language object.
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
static getDefaultPortfolio(int $a_user_id)
User class.
Access handler for portfolio NOTE: This file needs to stay in the classes directory,...
ILIAS Setting Class.
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=null)
Default behaviour is:
const ANONYMOUS_USER_ID
Definition: constants.php:27