4 require_once
'Services/JSON/classes/class.ilJsonUtil.php';
5 require_once
'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemException.php';
50 public function __construct()
63 require_once
'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
64 require_once
'Services/Contact/BuddySystem/classes/states/class.ilBuddySystemRelationStateFactory.php';
65 $this->buddylist = ilBuddyList::getInstanceByGlobalUser();
68 $this->lng->loadLanguageModule(
'buddysystem');
74 public static function initializeFrontend()
83 if(!self::$frontend_initialized)
85 $lng->loadLanguageModule(
'buddysystem');
87 require_once
'Services/JSON/classes/class.ilJsonUtil.php';
89 $tpl->addJavascript(
'./Services/Contact/BuddySystem/js/buddy_system.js');
91 $config =
new stdClass();
92 $config->http_post_url = $ilCtrl->getFormActionByClass(array(
'ilUIPluginRouterGUI',
'ilBuddySystemGUI'),
'',
'',
true,
false);
93 $config->transition_state_cmd =
'transitionAsync';
96 $btn_config =
new stdClass();
97 $btn_config->bnt_class =
'ilBuddySystemLinkWidget';
99 $tpl->addOnLoadCode(
"il.BuddySystemButton.setConfig(".
ilJsonUtil::encode($btn_config).
");");
100 $tpl->addOnLoadCode(
"il.BuddySystemButton.init();");
102 self::$frontend_initialized =
true;
111 if($this->user->isAnonymous())
113 throw new RuntimeException(
'This controller only accepts requests of logged in users');
116 $next_class = $this->ctrl->getNextClass($this);
117 $cmd = $this->ctrl->getCmd();
137 case self::BS_REQUEST_HTTP_POST:
141 case self::BS_REQUEST_HTTP_GET:
143 return isset(
$_GET[$key]) && strlen(
$_GET[$key]);
156 throw new ilException(
"The requested user does not want to get contact requests");
187 $this->ctrl->returnToParent($this);
192 require_once
'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
193 $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId((
int)
$_GET[
'user_id']);
195 if(null !== $onBeforeExecute)
197 $onBeforeExecute($relation);
200 ilBuddyList::getInstanceByGlobalUser()->$cmd($relation);
217 $this->ctrl->returnToParent($this);
223 private function transitionAsyncCommand()
230 if(!$this->ctrl->isAsynch())
235 if(!isset(
$_POST[
'usr_id']) || !is_numeric(
$_POST[
'usr_id']))
240 if(!isset(
$_POST[
'action']) || !strlen(
$_POST[
'action']))
245 $response =
new stdClass();
246 $response->success =
false;
250 $usr_id = (int)
$_POST[
'usr_id'];
255 throw new ilBuddySystemException(sprintf(
"You cannot perform a state transition for the anonymous user (id: %s)", $usr_id));
260 throw new ilBuddySystemException(sprintf(
"You cannot perform a state transition for a non existing user (id: %s)", $usr_id));
263 $relation = $this->buddylist->getRelationByUserId($usr_id);
268 throw new ilException(
"The requested user does not want to get contact requests");
273 $this->buddylist->{$action}($relation);
274 $response->success =
true;
286 $response->message = $lng->txt(
'buddy_bs_action_not_possible');
289 $response->state = get_class($relation->getState());
290 $response->state_html = $this->statefactory->getRendererByOwnerAndRelation($this->buddylist->getOwnerId(), $relation)->getHtml();
294 $response->message =
$lng->txt(
'buddy_bs_action_not_possible');
297 echo json_encode($response);
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.
isRequestParameterGiven($key, $type)
static $frontend_initialized
_lookupPref($a_usr_id, $a_keyword)
const BS_REQUEST_HTTP_POST
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static encode($mixed, $suppress_native=false)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static _isAnonymous($usr_id)
Class ilBuddySystemRelation.
transitionCommand($cmd, $positive_feedback_lng_id, callable $onBeforeExecute=null)
static yn2tf($a_yn)
convert "y"/"n" to true/false
const BS_REQUEST_HTTP_GET