ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilBuddySystemLinkButton.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 $usrId;
12
14 protected $buddyList;
15
17 protected $lng;
18
20 protected $user;
21
27 protected function __construct(int $usrId)
28 {
29 global $DIC;
30
31 $this->usrId = $usrId;
32 $this->buddyList = ilBuddyList::getInstanceByGlobalUser();
33
34 $this->user = $DIC['ilUser'];
35 $this->lng = $DIC['lng'];
36 }
37
43 public static function getInstanceByUserId(int $usrId) : self
44 {
45 return new self($usrId);
46 }
47
51 public function getUsrId() : int
52 {
53 return $this->usrId;
54 }
55
59 public function setUsrId(int $usrId)
60 {
61 $this->usrId = $usrId;
62 }
63
67 public function getBuddyList() : ilBuddyList
68 {
69 return $this->buddyList;
70 }
71
75 public function getHtml() : string
76 {
77 $this->lng->loadLanguageModule('buddysystem');
78
79 if (!ilBuddySystem::getInstance()->isEnabled()) {
80 return '';
81 }
82
83 $relation = $this->buddyList->getRelationByUserId($this->getUsrId());
84
85 // The ILIAS JF decided to add a new personal setting
86 if (
87 $relation->isUnlinked() &&
88 !ilUtil::yn2tf(ilObjUser::_lookupPref($this->getUsrId(), 'bs_allow_to_contact_me'))
89 ) {
90 return '';
91 }
92
93 $buttonTemplate = new ilTemplate(
94 'tpl.buddy_system_link_button.html',
95 true,
96 true,
97 'Services/Contact/BuddySystem'
98 );
99 $buttonTemplate->setVariable(
100 'BUTTON_HTML',
101 ilBuddySystemRelationStateFactory::getInstance()->getStateButtonRendererByOwnerAndRelation(
102 (int) $this->user->getId(),
103 $relation
104 )->getHtml()
105 );
106 $buttonTemplate->setVariable('BUTTON_BUDDY_ID', $this->getUsrId());
107 $buttonTemplate->setVariable('BUTTON_CSS_CLASS', 'ilBuddySystemLinkWidget');
108 $buttonTemplate->setVariable('BUTTON_CURRENT_STATE', get_class($relation->getState()));
109
110 return $buttonTemplate->get();
111 }
112}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Class ilBuddyList.
static getInstanceByGlobalUser()
Class ilBuddySystemLinkButton.
__construct(int $usrId)
ilBuddySystemLinkButton constructor.
static _lookupPref($a_usr_id, $a_keyword)
special template class to simplify handling of ITX/PEAR
static yn2tf($a_yn)
convert "y"/"n" to true/false
Interface ilBuddySystemLinkButtonType.
$DIC
Definition: xapitoken.php:46