ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilBuddySystemNotification.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
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 $recipientIds = [];
18
23 public function __construct(ilObjUser $user, ilSetting $settings)
24 {
25 $this->sender = $user;
26 $this->settings = $settings;
27 }
28
32 public function getRecipientIds() : array
33 {
35 }
36
40 public function setRecipientIds(array $recipientIds)
41 {
42 $this->recipientIds = $recipientIds;
43 }
44
48 public function send() : void
49 {
50 foreach ($this->getRecipientIds() as $usr_id) {
51 $user = new ilObjUser((int) $usr_id);
52
53 $recipientLanguage = ilLanguageFactory::_getLanguage($user->getLanguage());
54 $recipientLanguage->loadLanguageModule('buddysystem');
55
56 $notification = new ilNotificationConfig('buddysystem_request');
57 $notification->setTitleVar('buddy_notification_contact_request', [], 'buddysystem');
58
59 $personalProfileLink = $recipientLanguage->txt('buddy_noti_cr_profile_not_published');
60 if ($this->hasPublicProfile((int) $user->getId())) {
61 $personalProfileLink = ilLink::_getStaticLink($this->sender->getId(), 'usr', true);
62 }
63
64 $bodyParams = [
65 'SALUTATION' => ilMail::getSalutation($user->getId(), $recipientLanguage),
66 'BR' => nl2br("\n"),
67 'APPROVE_REQUEST' => '<a href="' . ilLink::_getStaticLink(
68 $this->sender->getId(),
69 'usr',
70 true,
71 '_contact_approved'
72 ) . '">' . $recipientLanguage->txt('buddy_notification_contact_request_link_osd') . '</a>',
73 'IGNORE_REQUEST' => '<a href="' . ilLink::_getStaticLink(
74 $this->sender->getId(),
75 'usr',
76 true,
77 '_contact_ignored'
78 ) . '">' . $recipientLanguage->txt('buddy_notification_contact_request_ignore_osd') . '</a>',
79 'REQUESTING_USER' => ilUserUtil::getNamePresentation($this->sender->getId())
80 ];
81 $notification->setShortDescriptionVar(
82 'buddy_notification_contact_request_short',
83 $bodyParams,
84 'buddysystem'
85 );
86
87 $bodyParams = [
88 'SALUTATION' => ilMail::getSalutation($user->getId(), $recipientLanguage),
89 'BR' => "\n",
90 'APPROVE_REQUEST' => ilLink::_getStaticLink($this->sender->getId(), 'usr', true, '_contact_approved'),
91 'APPROVE_REQUEST_TXT' => $recipientLanguage->txt('buddy_notification_contact_request_link'),
92 'IGNORE_REQUEST' => ilLink::_getStaticLink($this->sender->getId(), 'usr', true, '_contact_ignored'),
93 'IGNORE_REQUEST_TXT' => $recipientLanguage->txt('buddy_notification_contact_request_ignore'),
94 'REQUESTING_USER' => ilUserUtil::getNamePresentation($this->sender->getId()),
95 'PERSONAL_PROFILE_LINK' => $personalProfileLink,
96 ];
97 $notification->setLongDescriptionVar('buddy_notification_contact_request_long', $bodyParams, 'buddysystem');
98
99 $notification->setAutoDisable(false);
100 $notification->setValidForSeconds(ilNotificationConfig::TTL_LONG);
101 $notification->setVisibleForSeconds(ilNotificationConfig::DEFAULT_TTS);
102 $notification->setIconPath('templates/default/images/icon_usr.svg');
103 $notification->setHandlerParam('mail.sender', ANONYMOUS_USER_ID);
104 $notification->notifyByUsers([$user->getId()]);
105 }
106 }
107
112 protected function hasPublicProfile(int $recipientUsrId) : bool
113 {
114 $portfolioId = ilObjPortfolio::getDefaultPortfolio($this->sender->getId());
115 if (is_numeric($portfolioId) && $portfolioId > 0) {
116 $accessHandler = new ilPortfolioAccessHandler();
117 return $accessHandler->checkAccessOfUser($recipientUsrId, 'read', '', $portfolioId);
118 }
119
120 return (
121 $this->sender->getPref('public_profile') === 'y' ||
122 $this->sender->getPref('public_profile') === 'g'
123 );
124 }
125}
An exception for terminatinating execution or to throw for unit testing.
__construct(ilObjUser $user, ilSetting $settings)
static _getLanguage($a_lang_key='')
Get langauge object.
static getSalutation($a_usr_id, ilLanguage $a_language=null)
Describes a notification and provides methods for publishing this notification.
static getDefaultPortfolio($a_user_id)
Get default portfolio of user.
Access handler for portfolio.
ILIAS Setting Class.
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:
const ANONYMOUS_USER_ID
Definition: constants.php:25
settings()
Definition: settings.php:2