19 declare(strict_types=1);
46 $this->main_tpl = $DIC->ui()->mainTemplate();
48 $this->
http = $DIC->http();
49 $this->
ctrl = $DIC[
'ilCtrl'];
50 $this->
user = $DIC[
'ilUser'];
51 $this->
lng = $DIC[
'lng'];
56 $this->
lng->loadLanguageModule(
'buddysystem');
64 !self::$isFrontendInitialized &&
66 !$DIC->user()->isAnonymous()
68 $DIC->language()->loadLanguageModule(
'buddysystem');
70 $page->
addJavaScript(
'./Services/Contact/BuddySystem/js/buddy_system.js');
73 $config->http_post_url = $DIC->ctrl()->getFormActionByClass([
74 ilUIPluginRouterGUI::class,
76 ],
'',
'',
true,
false);
77 $config->transition_state_cmd =
'transitionAsync';
78 $page->
addOnLoadCode(
'il.BuddySystem.setConfig(' . json_encode(
$config, JSON_THROW_ON_ERROR) .
');');
81 $btn_config->bnt_class =
'ilBuddySystemLinkWidget';
83 $page->
addOnLoadCode(
'il.BuddySystemButton.setConfig(' . json_encode($btn_config, JSON_THROW_ON_ERROR) .
');');
86 self::$isFrontendInitialized =
true;
95 if ($this->
user->isAnonymous()) {
96 throw new RuntimeException(
'This controller only accepts requests of logged in users');
99 $nextClass = $this->
ctrl->getNextClass($this);
100 $cmd = $this->
ctrl->getCmd();
102 switch ($nextClass) {
118 case self::BS_REQUEST_HTTP_POST:
119 $body = $this->
http->request()->getParsedBody();
120 return (isset($body[$key]) && is_string($body[$key]) && $body[$key] !==
'');
122 case self::BS_REQUEST_HTTP_GET:
124 $query = $this->
http->request()->getQueryParams();
133 'buddy_relation_requested',
139 throw new ilException(
'The requested user does not want to get contact requests');
157 string $positiveFeedbackLanguageId,
158 callable $onBeforeExecute = null
161 $this->main_tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'buddy_bs_action_not_possible'),
true);
162 $this->
ctrl->returnToParent($this);
165 $usrId = (
int) $this->
http->request()->getQueryParams()[
'user_id'];
169 if (null !== $onBeforeExecute) {
170 $onBeforeExecute($relation);
174 $this->main_tpl->setOnScreenMessage(
'success', $this->
lng->txt($positiveFeedbackLanguageId),
true);
176 $this->main_tpl->setOnScreenMessage(
'info', sprintf(
177 $this->
lng->txt($e->getMessage()),
181 $this->main_tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'buddy_bs_action_not_possible'),
true);
192 if (!$this->
ctrl->isAsynch()) {
208 $usr_id = (
int) $this->
http->request()->getParsedBody()[
'usr_id'];
213 'You cannot perform a state transition for the anonymous user (id: %s)',
221 'You cannot perform a state transition for a non existing user (id: %s)',
226 $relation = $this->buddyList->getRelationByUserId($usr_id);
230 $relation->isUnlinked() &&
233 throw new ilException(
'The requested user does not want to get contact requests');
237 $this->buddyList->{$action}($relation);
240 $response->message = sprintf($this->
lng->txt($e->getMessage()), $login);
242 $response->message = $this->
lng->txt(
'buddy_bs_action_not_possible');
245 $response->state = get_class($relation->getState());
246 $response->state_html = $this->stateFactory->getStateButtonRendererByOwnerAndRelation(
247 $this->buddyList->getOwnerId(),
251 $response->message = $this->
lng->txt(
'buddy_bs_action_not_possible');
254 $this->
http->saveResponse(
255 $this->
http->response()
256 ->withAddedHeader(
'Content-Type',
'application/json')
259 $this->
http->sendResponse();
260 $this->
http->close();
265 if (isset($this->
http->request()->getServerParams()[
'HTTP_REFERER'])) {
266 $redirectUrl = $this->
http->request()->getServerParams()[
'HTTP_REFERER'];
267 $urlParts = parse_url($redirectUrl);
269 if (isset($urlParts[
'path'])) {
270 $script = basename($urlParts[
'path'],
'.php');
271 if ($script ===
'login') {
272 $this->
ctrl->returnToParent($this);
274 $redirectUrl = ltrim(basename($urlParts[
'path']),
'/');
275 if (isset($urlParts[
'query'])) {
276 $redirectUrl .=
'?' . $urlParts[
'query'];
281 if ($redirectUrl !==
'') {
282 $this->
ctrl->redirectToURL($redirectUrl);
286 $this->
ctrl->returnToParent($this);
static getInstance(?ilLanguage $lng=null)
static getInstanceByGlobalUser()
Class ilBuddySystemRelationStateFactory.
ilBuddySystemRelationStateFactory $stateFactory
Class ChatMainBarProvider .
ilGlobalTemplateInterface $main_tpl
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static _lookupPref(int $a_usr_id, string $a_keyword)
Class ilBuddySystemException.
Class ilBuddySystemRelationStateTransitionException.
const BS_REQUEST_HTTP_POST
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.
Class ilBuddySystemRelationStateAlreadyGivenException.
static initializeFrontend(ilGlobalTemplateInterface $page)
addOnLoadCode(string $a_code, int $a_batch=2)
Add on load code.
static _isAnonymous(int $usr_id)
transitionAsyncCommand()
Performs a state transition based on the request action.
transitionCommand(string $cmd, string $positiveFeedbackLanguageId, callable $onBeforeExecute=null)
static yn2tf(string $a_yn)
const BS_REQUEST_HTTP_GET
Class FlySystemFileAccessTest disabled disabled disabled.
static bool $isFrontendInitialized
isRequestParameterGiven(string $key, int $type)
static _lookupLogin(int $a_user_id)