ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilBuddySystemGUI Class Reference

Class ilBuddySystemGUI. More...

+ Collaboration diagram for ilBuddySystemGUI:

Public Member Functions

 __construct ()
 
 executeCommand ()
 

Static Public Member Functions

static initializeFrontend ()
 

Data Fields

const BS_REQUEST_HTTP_GET = 1
 
const BS_REQUEST_HTTP_POST = 2
 

Protected Member Functions

 isRequestParameterGiven ($key, $type)
 

Protected Attributes

 $ctrl
 
 $buddylist
 
 $statefactory
 
 $user
 
 $lng
 

Static Protected Attributes

static $frontend_initialized = false
 

Private Member Functions

 requestCommand ()
 
 ignoreCommand ()
 
 linkCommand ()
 
 transitionCommand ($cmd, $positive_feedback_lng_id, callable $onBeforeExecute=null)
 
 transitionAsyncCommand ()
 Performs a state transition based on the request action. More...
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBuddySystemGUI::__construct ( )

Definition at line 50 of file class.ilBuddySystemGUI.php.

References $DIC, ilBuddySystemRelationStateFactory\getInstance(), ilBuddyList\getInstanceByGlobalUser(), and user().

51  {
52  global $DIC;
53 
54  $this->ctrl = $DIC['ilCtrl'];
55  $this->user = $DIC['ilUser'];
56  $this->lng = $DIC['lng'];
57 
58  require_once 'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
59  require_once 'Services/Contact/BuddySystem/classes/states/class.ilBuddySystemRelationStateFactory.php';
60  $this->buddylist = ilBuddyList::getInstanceByGlobalUser();
61  $this->statefactory = ilBuddySystemRelationStateFactory::getInstance();
62 
63  $this->lng->loadLanguageModule('buddysystem');
64  }
static getInstanceByGlobalUser()
user()
Definition: user.php:4
global $DIC
+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilBuddySystemGUI::executeCommand ( )
Exceptions
RuntimeException

Definition at line 99 of file class.ilBuddySystemGUI.php.

References $cmd, and user().

100  {
101  if($this->user->isAnonymous())
102  {
103  throw new RuntimeException('This controller only accepts requests of logged in users');
104  }
105 
106  $next_class = $this->ctrl->getNextClass($this);
107  $cmd = $this->ctrl->getCmd();
108 
109  switch($next_class)
110  {
111  default:
112  $cmd .= 'Command';
113  $this->$cmd();
114  break;
115  }
116  }
$cmd
Definition: sahs_server.php:35
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ ignoreCommand()

ilBuddySystemGUI::ignoreCommand ( )
private

Definition at line 154 of file class.ilBuddySystemGUI.php.

References transitionCommand().

155  {
156  $this->transitionCommand('ignore', 'buddy_request_ignored');
157  }
transitionCommand($cmd, $positive_feedback_lng_id, callable $onBeforeExecute=null)
+ Here is the call graph for this function:

◆ initializeFrontend()

static ilBuddySystemGUI::initializeFrontend ( )
static

Definition at line 69 of file class.ilBuddySystemGUI.php.

References $config, $DIC, array, and ilJsonUtil\encode().

Referenced by ilBuddySystemLinkButton\getHtml(), and ilMainMenuGUI\populateWithBuddySystem().

70  {
71  global $DIC;
72 
73  if(!self::$frontend_initialized)
74  {
75  $DIC->language()->loadLanguageModule('buddysystem');
76 
77  require_once 'Services/JSON/classes/class.ilJsonUtil.php';
78 
79  $DIC['tpl']->addJavascript('./Services/Contact/BuddySystem/js/buddy_system.js');
80 
81  $config = new stdClass();
82  $config->http_post_url = $DIC->ctrl()->getFormActionByClass(array('ilUIPluginRouterGUI', 'ilBuddySystemGUI'), '', '', true, false);
83  $config->transition_state_cmd = 'transitionAsync';
84  $DIC['tpl']->addOnLoadCode("il.BuddySystem.setConfig(".ilJsonUtil::encode($config).");");
85 
86  $btn_config = new stdClass();
87  $btn_config->bnt_class = 'ilBuddySystemLinkWidget';
88 
89  $DIC['tpl']->addOnLoadCode("il.BuddySystemButton.setConfig(".ilJsonUtil::encode($btn_config).");");
90  $DIC['tpl']->addOnLoadCode("il.BuddySystemButton.init();");
91 
92  self::$frontend_initialized = true;
93  }
94  }
static encode($mixed, $suppress_native=false)
Create styles array
The data for the language used.
global $DIC
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRequestParameterGiven()

ilBuddySystemGUI::isRequestParameterGiven (   $key,
  $type 
)
protected
Parameters
string$key
int$type
Returns
bool

Definition at line 123 of file class.ilBuddySystemGUI.php.

References $_GET, and $_POST.

Referenced by transitionCommand().

124  {
125  switch($type)
126  {
127  case self::BS_REQUEST_HTTP_POST:
128  return isset($_POST[$key]) && strlen($_POST[$key]);
129  break;
130 
131  case self::BS_REQUEST_HTTP_GET:
132  default:
133  return isset($_GET[$key]) && strlen($_GET[$key]);
134  break;
135  }
136  }
$_GET["client_id"]
$_POST["username"]
+ Here is the caller graph for this function:

◆ linkCommand()

ilBuddySystemGUI::linkCommand ( )
private

Definition at line 162 of file class.ilBuddySystemGUI.php.

References transitionCommand().

163  {
164  $this->transitionCommand('link', 'buddy_request_approved');
165  }
transitionCommand($cmd, $positive_feedback_lng_id, callable $onBeforeExecute=null)
+ Here is the call graph for this function:

◆ requestCommand()

ilBuddySystemGUI::requestCommand ( )
private

Definition at line 141 of file class.ilBuddySystemGUI.php.

References ilObjUser\_lookupPref(), ilBuddySystemRelation\getBuddyUserId(), ilBuddySystemRelation\isUnlinked(), transitionCommand(), and ilUtil\yn2tf().

142  {
143  $this->transitionCommand('request', 'buddy_relation_requested', function(ilBuddySystemRelation $relation) {
144  if($relation->isUnlinked() && !ilUtil::yn2tf(ilObjUser::_lookupPref($relation->getBuddyUserId(), 'bs_allow_to_contact_me')))
145  {
146  throw new ilException("The requested user does not want to get contact requests");
147  }
148  });
149  }
Base class for ILIAS Exception handling.
Class ilBuddySystemRelation.
static _lookupPref($a_usr_id, $a_keyword)
transitionCommand($cmd, $positive_feedback_lng_id, callable $onBeforeExecute=null)
static yn2tf($a_yn)
convert "y"/"n" to true/false
+ Here is the call graph for this function:

◆ transitionAsyncCommand()

ilBuddySystemGUI::transitionAsyncCommand ( )
private

Performs a state transition based on the request action.

Definition at line 213 of file class.ilBuddySystemGUI.php.

References $_POST, ilObjUser\_isAnonymous(), ilObjUser\_lookupLogin(), ilObjUser\_lookupPref(), exit, ilUtil\stripSlashes(), and ilUtil\yn2tf().

214  {
215  if(!$this->ctrl->isAsynch())
216  {
217  throw new RuntimeException('This action only supports AJAX http requests');
218  }
219 
220  if(!isset($_POST['usr_id']) || !is_numeric($_POST['usr_id']))
221  {
222  throw new RuntimeException('Missing "usr_id" parameter');
223  }
224 
225  if(!isset($_POST['action']) || !strlen($_POST['action']))
226  {
227  throw new RuntimeException('Missing "action" parameter');
228  }
229 
230  $response = new stdClass();
231  $response->success = false;
232 
233  try
234  {
235  $usr_id = (int)$_POST['usr_id'];
236  $action = ilUtil::stripSlashes($_POST['action']);
237 
238  if(ilObjUser::_isAnonymous($usr_id))
239  {
240  throw new ilBuddySystemException(sprintf("You cannot perform a state transition for the anonymous user (id: %s)", $usr_id));
241  }
242 
243  if(!strlen(ilObjUser::_lookupLogin($usr_id)))
244  {
245  throw new ilBuddySystemException(sprintf("You cannot perform a state transition for a non existing user (id: %s)", $usr_id));
246  }
247 
248  $relation = $this->buddylist->getRelationByUserId($usr_id);
249 
250  // The ILIAS JF decided to add a new personal setting
251  if($relation->isUnlinked() && !ilUtil::yn2tf(ilObjUser::_lookupPref($relation->getBuddyUserId(), 'bs_allow_to_contact_me')))
252  {
253  throw new ilException("The requested user does not want to get contact requests");
254  }
255 
256  try
257  {
258  $this->buddylist->{$action}($relation);
259  $response->success = true;
260  }
262  {
263  $response->message = sprintf($this->lng->txt($e->getMessage()), ilObjUser::_lookupLogin((int)$usr_id));
264  }
266  {
267  $response->message = sprintf($this->lng->txt($e->getMessage()), ilObjUser::_lookupLogin((int)$usr_id));
268  }
269  catch(Exception $e)
270  {
271  $response->message = $this->lng->txt('buddy_bs_action_not_possible');
272  }
273 
274  $response->state = get_class($relation->getState());
275  $response->state_html = $this->statefactory->getRendererByOwnerAndRelation($this->buddylist->getOwnerId(), $relation)->getHtml();
276  }
277  catch(Exception $e)
278  {
279  $response->message = $this->lng->txt('buddy_bs_action_not_possible');
280  }
281 
282  echo json_encode($response);
283  exit();
284  }
static _lookupLogin($a_user_id)
lookup login
Base class for ILIAS Exception handling.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static _isAnonymous($usr_id)
static _lookupPref($a_usr_id, $a_keyword)
static yn2tf($a_yn)
convert "y"/"n" to true/false
$_POST["username"]
+ Here is the call graph for this function:

◆ transitionCommand()

ilBuddySystemGUI::transitionCommand (   $cmd,
  $positive_feedback_lng_id,
callable  $onBeforeExecute = null 
)
private
Parameters
string$cmd
string$positive_feedback_lng_id
callable | null$onBeforeExecute

Definition at line 172 of file class.ilBuddySystemGUI.php.

References $_GET, ilObjUser\_lookupLogin(), ilBuddyList\getInstanceByGlobalUser(), isRequestParameterGiven(), ilUtil\sendInfo(), and ilUtil\sendSuccess().

Referenced by ignoreCommand(), linkCommand(), and requestCommand().

173  {
174  if(!$this->isRequestParameterGiven('user_id', self::BS_REQUEST_HTTP_GET))
175  {
176  ilUtil::sendInfo($this->lng->txt('buddy_bs_action_not_possible'), true);
177  $this->ctrl->returnToParent($this);
178  }
179 
180  try
181  {
182  require_once 'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
183  $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId((int)$_GET['user_id']);
184 
185  if(null !== $onBeforeExecute)
186  {
187  $onBeforeExecute($relation);
188  }
189 
190  ilBuddyList::getInstanceByGlobalUser()->$cmd($relation);
191  ilUtil::sendSuccess($this->lng->txt($positive_feedback_lng_id), true);
192 
193  }
195  {
196  ilUtil::sendInfo(sprintf($this->lng->txt($e->getMessage()), ilObjUser::_lookupLogin((int)$_GET['user_id'])), true);
197  }
199  {
200  ilUtil::sendInfo(sprintf($this->lng->txt($e->getMessage()), ilObjUser::_lookupLogin((int)$_GET['user_id'])), true);
201  }
202  catch(ilException $e)
203  {
204  ilUtil::sendInfo($this->lng->txt('buddy_bs_action_not_possible'), true);
205  }
206 
207  $this->ctrl->returnToParent($this);
208  }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _lookupLogin($a_user_id)
lookup login
Base class for ILIAS Exception handling.
static getInstanceByGlobalUser()
isRequestParameterGiven($key, $type)
$_GET["client_id"]
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $buddylist

ilBuddySystemGUI::$buddylist
protected

Definition at line 30 of file class.ilBuddySystemGUI.php.

◆ $ctrl

ilBuddySystemGUI::$ctrl
protected

Definition at line 25 of file class.ilBuddySystemGUI.php.

◆ $frontend_initialized

ilBuddySystemGUI::$frontend_initialized = false
staticprotected

Definition at line 20 of file class.ilBuddySystemGUI.php.

◆ $lng

ilBuddySystemGUI::$lng
protected

Definition at line 45 of file class.ilBuddySystemGUI.php.

◆ $statefactory

ilBuddySystemGUI::$statefactory
protected

Definition at line 35 of file class.ilBuddySystemGUI.php.

◆ $user

ilBuddySystemGUI::$user
protected

Definition at line 40 of file class.ilBuddySystemGUI.php.

◆ BS_REQUEST_HTTP_GET

const ilBuddySystemGUI::BS_REQUEST_HTTP_GET = 1

Definition at line 14 of file class.ilBuddySystemGUI.php.

◆ BS_REQUEST_HTTP_POST

const ilBuddySystemGUI::BS_REQUEST_HTTP_POST = 2

Definition at line 15 of file class.ilBuddySystemGUI.php.


The documentation for this class was generated from the following file: