ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBuddySystemLinkButton.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
24 protected ilLanguage $lng;
25 protected ilObjUser $user;
26
27 protected function __construct(protected int $usrId)
28 {
29 global $DIC;
30 $this->buddyList = ilBuddyList::getInstanceByGlobalUser();
31
32 $this->user = $DIC['ilUser'];
33 $this->lng = $DIC['lng'];
34 }
35
39 public static function getInstanceByUserId(int $usrId): self
40 {
41 return new self($usrId);
42 }
43
44 public function getUsrId(): int
45 {
46 return $this->usrId;
47 }
48
49 public function getBuddyList(): ilBuddyList
50 {
51 return $this->buddyList;
52 }
53
54 public function getHtml(): string
55 {
56 $this->lng->loadLanguageModule('buddysystem');
57
58 if (!ilBuddySystem::getInstance()->isEnabled()) {
59 return '';
60 }
61
62 $relation = $this->buddyList->getRelationByUserId($this->getUsrId());
63
64 // The ILIAS JF decided to add a new personal setting
65 if ($relation->isUnlinked() &&
66 !ilUtil::yn2tf((string) ilObjUser::_lookupPref($this->getUsrId(), 'bs_allow_to_contact_me'))) {
67 return '';
68 }
69
70 $buttonTemplate = new ilTemplate(
71 'tpl.buddy_system_link_button.html',
72 true,
73 true,
74 'components/ILIAS/Contact/BuddySystem'
75 );
76 $buttonTemplate->setVariable(
77 'BUTTON_HTML',
78 ilBuddySystemRelationStateFactory::getInstance()->getStateButtonRendererByOwnerAndRelation(
79 $this->user->getId(),
81 )->getHtml()
82 );
83 $buttonTemplate->setVariable('BUTTON_BUDDY_ID', $this->getUsrId());
84 $buttonTemplate->setVariable('BUTTON_CSS_CLASS', ilBuddySystemLinkButtonType::ROOT_CSS_CLASS);
85 $buttonTemplate->setVariable('BUTTON_CURRENT_STATE', $relation->getState()::class);
86
87 return $buttonTemplate->get();
88 }
89}
$relation
Class ilBuddyList.
static getInstanceByGlobalUser(?ilObjUser $user=null)
language handling
User class.
static _lookupPref(int $a_usr_id, string $a_keyword)
special template class to simplify handling of ITX/PEAR
static yn2tf(string $a_yn)
global $DIC
Definition: shib_login.php:26