4require_once 
'Services/JSON/classes/class.ilJsonUtil.php';
 
    5require_once 
'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemException.php';
 
   59        $this->
http = $DIC->http();
 
   60        $this->ctrl = 
$DIC[
'ilCtrl'];
 
   61        $this->
user = $DIC[
'ilUser'];
 
   62        $this->lng = 
$DIC[
'lng'];
 
   64        require_once 
'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
 
   65        require_once 
'Services/Contact/BuddySystem/classes/states/class.ilBuddySystemRelationStateFactory.php';
 
   69        $this->lng->loadLanguageModule(
'buddysystem');
 
   79        if (!self::$frontend_initialized) {
 
   80            $DIC->language()->loadLanguageModule(
'buddysystem');
 
   82            require_once 
'Services/JSON/classes/class.ilJsonUtil.php';
 
   84            $DIC[
'tpl']->addJavascript(
'./Services/Contact/BuddySystem/js/buddy_system.js');
 
   87            $config->http_post_url = 
$DIC->ctrl()->getFormActionByClass(array(
'ilUIPluginRouterGUI', 
'ilBuddySystemGUI'), 
'', 
'', 
true, 
false);
 
   88            $config->transition_state_cmd = 
'transitionAsync';
 
   91            $btn_config = 
new stdClass();
 
   92            $btn_config->bnt_class = 
'ilBuddySystemLinkWidget';
 
   95            $DIC[
'tpl']->addOnLoadCode(
"il.BuddySystemButton.init();");
 
   97            self::$frontend_initialized = 
true;
 
  106        if ($this->
user->isAnonymous()) {
 
  107            throw new RuntimeException(
'This controller only accepts requests of logged in users');
 
  110        $next_class = $this->ctrl->getNextClass($this);
 
  111        $cmd = $this->ctrl->getCmd();
 
  113        switch ($next_class) {
 
  147                throw new ilException(
"The requested user does not want to get contact requests");
 
  173    private function transitionCommand($cmd, $positive_feedback_lng_id, callable $onBeforeExecute = 
null)
 
  177            $this->ctrl->returnToParent($this);
 
  181            require_once 
'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
 
  184            if (
null !== $onBeforeExecute) {
 
  185                $onBeforeExecute($relation);
 
  189            ilUtil::sendSuccess($this->lng->txt($positive_feedback_lng_id), 
true);
 
  206        if (!$this->ctrl->isAsynch()) {
 
  207            throw new RuntimeException(
'This action only supports AJAX http requests');
 
  210        if (!isset(
$_POST[
'usr_id']) || !is_numeric(
$_POST[
'usr_id'])) {
 
  211            throw new RuntimeException(
'Missing "usr_id" parameter');
 
  214        if (!isset(
$_POST[
'action']) || !strlen(
$_POST[
'action'])) {
 
  215            throw new RuntimeException(
'Missing "action" parameter');
 
  222            $usr_id = (int) 
$_POST[
'usr_id'];
 
  226                throw new ilBuddySystemException(sprintf(
"You cannot perform a state transition for the anonymous user (id: %s)", $usr_id));
 
  230                throw new ilBuddySystemException(sprintf(
"You cannot perform a state transition for a non existing user (id: %s)", $usr_id));
 
  233            $relation = $this->buddylist->getRelationByUserId($usr_id);
 
  237                throw new ilException(
"The requested user does not want to get contact requests");
 
  241                $this->buddylist->{
$action}($relation);
 
  247            } 
catch (Exception $e) {
 
  248                $response->message = $this->lng->txt(
'buddy_bs_action_not_possible');
 
  251            $response->state = get_class($relation->getState());
 
  252            $response->state_html = $this->statefactory->getRendererByOwnerAndRelation($this->buddylist->getOwnerId(), $relation)->getHtml();
 
  253        } 
catch (Exception $e) {
 
  254            $response->message = $this->lng->txt(
'buddy_bs_action_not_possible');
 
  263        if (isset($this->
http->request()->getServerParams()[
'HTTP_REFERER'])) {
 
  264            $redirectUrl = $this->
http->request()->getServerParams()[
'HTTP_REFERER'];
 
  265            $urlParts = parse_url($redirectUrl);
 
  267            if (isset($urlParts[
'path'])) {
 
  268                $script = basename($urlParts[
'path'], 
'.php');
 
  269                if ($script === 
'login') {
 
  270                    $this->ctrl->returnToParent($this);
 
  272                    $redirectUrl = ltrim(basename($urlParts[
'path']), 
'/');
 
  273                    if (isset($urlParts[
'query'])) {
 
  274                        $redirectUrl .= 
'?' . $urlParts[
'query'];
 
  278            $this->ctrl->redirectToURL($redirectUrl);
 
  281        $this->ctrl->returnToParent($this);
 
An exception for terminatinating execution or to throw for unit testing.
static getInstanceByGlobalUser()
transitionCommand($cmd, $positive_feedback_lng_id, callable $onBeforeExecute=null)
const BS_REQUEST_HTTP_GET
static $frontend_initialized
static initializeFrontend()
transitionAsyncCommand()
Performs a state transition based on the request action.
isRequestParameterGiven($key, $type)
const BS_REQUEST_HTTP_POST
Class ilBuddySystemRelation.
Base class for ILIAS Exception handling.
static encode($mixed, $suppress_native=false)
static _lookupPref($a_usr_id, $a_keyword)
static _lookupLogin($a_user_id)
lookup login
static _isAnonymous($usr_id)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static yn2tf($a_yn)
convert "y"/"n" to true/false
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static http()
Fetches the global http state from ILIAS.