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