ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBuddySystemLinkButton.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/JSON/classes/class.ilJsonUtil.php';
5require_once 'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
6require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemGUI.php';
7require_once 'Services/Contact/BuddySystem/classes/states/class.ilBuddySystemRelationStateFactory.php';
8require_once 'Services/Contact/BuddySystem/interfaces/interface.ilBuddySystemLinkButtonType.php';
9
15{
19 protected $usr_id;
20
24 protected $buddylist;
25
29 protected $lng;
30
34 protected $user;
35
39 protected function __construct($usr_id)
40 {
41 global $DIC;
42
43 $this->usr_id = $usr_id;
44 $this->buddylist = ilBuddyList::getInstanceByGlobalUser();
45
46 $this->user = $DIC['ilUser'];
47 $this->lng = $DIC['lng'];
48 }
49
54 public static function getInstanceByUserId($usr_id)
55 {
56 return new self($usr_id);
57 }
58
62 public function getUsrId()
63 {
64 return $this->usr_id;
65 }
66
70 public function setUsrId($usr_id)
71 {
72 $this->usr_id = $usr_id;
73 }
74
78 public function getBuddyList()
79 {
80 return $this->buddylist;
81 }
82
86 public function getHtml()
87 {
88 $this->lng->loadLanguageModule('buddysystem');
89
91
92 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystem.php';
93 if (!ilBuddySystem::getInstance()->isEnabled()) {
94 return '';
95 }
96
97 $relation = $this->buddylist->getRelationByUserId($this->getUsrId());
98
99 // The ILIAS JF decided to add a new personal setting
100 if ($relation->isUnlinked() && !ilUtil::yn2tf(ilObjUser::_lookupPref($this->getUsrId(), 'bs_allow_to_contact_me'))) {
101 return '';
102 }
103
104 $button_tpl = new ilTemplate('tpl.buddy_system_link_button.html', true, true, 'Services/Contact/BuddySystem');
105 $button_tpl->setVariable('BUTTON_HTML', ilBuddySystemRelationStateFactory::getInstance()->getRendererByOwnerAndRelation($this->user->getId(), $relation)->getHtml());
106 $button_tpl->setVariable('BUTTON_BUDDY_ID', $this->getUsrId());
107 $button_tpl->setVariable('BUTTON_CSS_CLASS', 'ilBuddySystemLinkWidget');
108 $button_tpl->setVariable('BUTTON_CURRENT_STATE', get_class($relation->getState()));
109 return $button_tpl->get();
110 }
111}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
static getInstanceByGlobalUser()
Class ilBuddySystemLinkButton.
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
global $DIC
Definition: saml.php:7