ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_once 'Services/JSON/classes/class.ilJsonUtil.php';
5 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
6 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemGUI.php';
7 require_once 'Services/Contact/BuddySystem/classes/states/class.ilBuddySystemRelationStateFactory.php';
8 require_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  {
95  return '';
96  }
97 
98  $relation = $this->buddylist->getRelationByUserId($this->getUsrId());
99 
100  // The ILIAS JF decided to add a new personal setting
101  if($relation->isUnlinked() && !ilUtil::yn2tf(ilObjUser::_lookupPref($this->getUsrId(), 'bs_allow_to_contact_me')))
102  {
103  return '';
104  }
105 
106  $button_tpl = new ilTemplate('tpl.buddy_system_link_button.html', true, true, 'Services/Contact/BuddySystem');
107  $button_tpl->setVariable('BUTTON_HTML', ilBuddySystemRelationStateFactory::getInstance()->getRendererByOwnerAndRelation($this->user->getId(), $relation)->getHtml());
108  $button_tpl->setVariable('BUTTON_BUDDY_ID', $this->getUsrId());
109  $button_tpl->setVariable('BUTTON_CSS_CLASS', 'ilBuddySystemLinkWidget');
110  $button_tpl->setVariable('BUTTON_CURRENT_STATE', get_class($relation->getState()));
111  return $button_tpl->get();
112  }
113 }
static getInstanceByGlobalUser()
user()
Definition: user.php:4
special template class to simplify handling of ITX/PEAR
Class ilBuddySystemLinkButtonType.
static _lookupPref($a_usr_id, $a_keyword)
global $DIC
Class ilBuddySystemLinkButton.
static yn2tf($a_yn)
convert "y"/"n" to true/false