19declare(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) .
');');
80 $btn_config =
new stdClass();
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) {
119 $body = $this->
http->request()->getParsedBody();
120 return (isset($body[
$key]) && is_string($body[
$key]) && $body[
$key] !==
'');
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);
184 $this->redirectToReferer();
192 if (!$this->
ctrl->isAsynch()) {
193 throw new RuntimeException(
'This action only supports AJAX http requests');
196 if (!$this->isRequestParameterGiven(
'usr_id', self::BS_REQUEST_HTTP_POST)) {
197 throw new RuntimeException(
'Missing "usr_id" parameter');
200 if (!$this->isRequestParameterGiven(
'action', self::BS_REQUEST_HTTP_POST)) {
201 throw new RuntimeException(
'Missing "action" parameter');
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);
241 }
catch (Exception
$e) {
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(),
250 }
catch (Exception
$e) {
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 getInstanceByGlobalUser()
Class ilBuddySystemException.
const BS_REQUEST_HTTP_GET
transitionCommand(string $cmd, string $positiveFeedbackLanguageId, callable $onBeforeExecute=null)
isRequestParameterGiven(string $key, int $type)
transitionAsyncCommand()
Performs a state transition based on the request action.
ilBuddySystemRelationStateFactory $stateFactory
const BS_REQUEST_HTTP_POST
static initializeFrontend(ilGlobalTemplateInterface $page)
static bool $isFrontendInitialized
ilGlobalTemplateInterface $main_tpl
Class ilBuddySystemRelationStateAlreadyGivenException.
Class ilBuddySystemRelationStateFactory.
static getInstance(?ilLanguage $lng=null)
Class ilBuddySystemRelationStateTransitionException.
Class ilBuddySystemRelation.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _isAnonymous(int $usr_id)
static _lookupPref(int $a_usr_id, string $a_keyword)
static _lookupLogin(int $a_user_id)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static yn2tf(string $a_yn)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
addOnLoadCode(string $a_code, int $a_batch=2)
Add on load code.
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
static http()
Fetches the global http state from ILIAS.
Class ChatMainBarProvider \MainMenu\Provider.