ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilBuddySystemLinkButton.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
27  protected int $usrId;
29  protected ilLanguage $lng;
30  protected ilObjUser $user;
31 
37  protected function __construct(int $usrId)
38  {
39  global $DIC;
40 
41  $this->usrId = $usrId;
42  $this->buddyList = ilBuddyList::getInstanceByGlobalUser();
43 
44  $this->user = $DIC['ilUser'];
45  $this->lng = $DIC['lng'];
46  }
47 
53  public static function getInstanceByUserId(int $usrId): self
54  {
55  return new self($usrId);
56  }
57 
58  public function getUsrId(): int
59  {
60  return $this->usrId;
61  }
62 
63  public function getBuddyList(): ilBuddyList
64  {
65  return $this->buddyList;
66  }
67 
68  public function getHtml(): string
69  {
70  $this->lng->loadLanguageModule('buddysystem');
71 
72  if (!ilBuddySystem::getInstance()->isEnabled()) {
73  return '';
74  }
75 
76  $relation = $this->buddyList->getRelationByUserId($this->getUsrId());
77 
78  // The ILIAS JF decided to add a new personal setting
79  if (
80  $relation->isUnlinked() &&
81  !ilUtil::yn2tf((string) ilObjUser::_lookupPref($this->getUsrId(), 'bs_allow_to_contact_me'))
82  ) {
83  return '';
84  }
85 
86  $buttonTemplate = new ilTemplate(
87  'tpl.buddy_system_link_button.html',
88  true,
89  true,
90  'Services/Contact/BuddySystem'
91  );
92  $buttonTemplate->setVariable(
93  'BUTTON_HTML',
94  ilBuddySystemRelationStateFactory::getInstance()->getStateButtonRendererByOwnerAndRelation(
95  (int) $this->user->getId(),
96  $relation
97  )->getHtml()
98  );
99  $buttonTemplate->setVariable('BUTTON_BUDDY_ID', $this->getUsrId());
100  $buttonTemplate->setVariable('BUTTON_CSS_CLASS', 'ilBuddySystemLinkWidget');
101  $buttonTemplate->setVariable('BUTTON_CURRENT_STATE', get_class($relation->getState()));
102 
103  return $buttonTemplate->get();
104  }
105 }
static getInstanceByGlobalUser()
static _lookupPref(int $a_usr_id, string $a_keyword)
global $DIC
Definition: feed.php:28
__construct(int $usrId)
ilBuddySystemLinkButton constructor.
Interface ilBuddySystemLinkButtonType.
static yn2tf(string $a_yn)
Class ilBuddySystemLinkButton.