19declare(strict_types=1);
52 $this->main_tpl =
$DIC->ui()->mainTemplate();
54 $this->
http = $DIC->http();
55 $this->
ctrl = $DIC[
'ilCtrl'];
56 $this->
user = $DIC[
'ilUser'];
57 $this->
lng = $DIC[
'lng'];
58 $this->ui_factory =
$DIC->ui()->factory();
59 $this->ui_renderer =
$DIC->ui()->renderer();
64 $this->
lng->loadLanguageModule(
'buddysystem');
72 !self::$isFrontendInitialized &&
74 !
$DIC->user()->isAnonymous()
76 $DIC->language()->loadLanguageModule(
'buddysystem');
81 $config =
new stdClass();
82 $config->async_get_unlink_modal_confirmation_html =
$DIC->ctrl()->getLinkTargetByClass([
83 ilUIPluginRouterGUI::class,
85 ],
'asyncGetUnlinkModalConfirmationHtml',
'',
true,
false);
87 $config->http_post_url =
$DIC->ctrl()->getFormActionByClass([
88 ilUIPluginRouterGUI::class,
90 ],
'',
'',
true,
false);
91 $config->transition_state_cmd =
'transitionAsync';
92 $page->
addOnLoadCode(
'il.BuddySystem.setConfig(' . json_encode($config, JSON_THROW_ON_ERROR) .
');');
94 $btn_config =
new stdClass();
97 $page->
addOnLoadCode(
'il.BuddySystemButton.setConfig(' . json_encode($btn_config, JSON_THROW_ON_ERROR) .
');');
100 self::$isFrontendInitialized =
true;
107 $confirmation_modal = $this
111 $this->
lng->txt(
'confirmation'),
112 $this->lng->txt(
'buddy_confirm_unlink'),
115 ->withActionButtonLabel($this->
lng->txt(
'confirm'))
116 ->withAdditionalOnLoadCode(
function (
$id) use (&$modal_id) {
121 $this->
http->saveResponse(
122 $this->
http->response()->withBody(
125 'html' => $this->ui_renderer->renderAsync($confirmation_modal),
127 'close' => $confirmation_modal->getCloseSignal()->getId()
129 'modalId' => $modal_id
130 ], JSON_THROW_ON_ERROR)
132 )->withHeader(ResponseHeader::CONTENT_TYPE,
'application/json')
134 $this->
http->sendResponse();
135 $this->
http->close();
143 if ($this->
user->isAnonymous()) {
144 throw new RuntimeException(
'This controller only accepts requests of logged in users');
147 $this->{$this->
ctrl->getCmd() .
'Command'}();
154 $body = $this->
http->request()->getParsedBody();
155 return (isset($body[$key]) && is_string($body[$key]) && $body[$key] !==
'');
159 $query = $this->
http->request()->getQueryParams();
160 return (isset($query[$key]) && is_string($query[$key]) && $query[$key] !==
'');
168 'buddy_relation_requested',
174 throw new ilException(
'The requested user does not want to get contact requests');
192 string $positiveFeedbackLanguageId,
193 ?callable $onBeforeExecute =
null
196 $this->main_tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'buddy_bs_action_not_possible'),
true);
197 $this->
ctrl->returnToParent($this);
200 $usrId = (
int) $this->
http->request()->getQueryParams()[
'user_id'];
204 if (
null !== $onBeforeExecute) {
209 $this->main_tpl->setOnScreenMessage(
'success', $this->
lng->txt($positiveFeedbackLanguageId),
true);
211 $this->main_tpl->setOnScreenMessage(
'info', sprintf(
212 $this->
lng->txt($e->getMessage()),
215 }
catch (Exception) {
216 $this->main_tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'buddy_bs_action_not_possible'),
true);
219 $this->redirectToReferer();
227 if (!$this->
ctrl->isAsynch()) {
228 throw new RuntimeException(
'This action only supports AJAX http requests');
231 if (!$this->isRequestParameterGiven(
'usr_id', self::BS_REQUEST_HTTP_POST)) {
232 throw new RuntimeException(
'Missing "usr_id" parameter');
235 if (!$this->isRequestParameterGiven(
'action', self::BS_REQUEST_HTTP_POST)) {
236 throw new RuntimeException(
'Missing "action" parameter');
243 $usr_id = (
int) $this->
http->request()->getParsedBody()[
'usr_id'];
248 'You cannot perform a state transition for the anonymous user (id: %s)',
256 'You cannot perform a state transition for a non existing user (id: %s)',
261 $relation = $this->buddyList->getRelationByUserId($usr_id);
268 throw new ilException(
'The requested user does not want to get contact requests');
275 $response->message = sprintf($this->
lng->txt($e->getMessage()), $login);
276 }
catch (Exception) {
277 $response->message = $this->
lng->txt(
'buddy_bs_action_not_possible');
281 $response->state_html = $this->stateFactory->getStateButtonRendererByOwnerAndRelation(
282 $this->buddyList->getOwnerId(),
285 }
catch (Exception) {
286 $response->message = $this->
lng->txt(
'buddy_bs_action_not_possible');
289 $this->
http->saveResponse(
290 $this->
http->response()
291 ->withAddedHeader(
'Content-Type',
'application/json')
292 ->withBody(
ILIAS\Filesystem\Stream\Streams::ofString(json_encode(
$response, JSON_THROW_ON_ERROR)))
294 $this->
http->sendResponse();
295 $this->
http->close();
300 if (isset($this->
http->request()->getServerParams()[
'HTTP_REFERER'])) {
301 $redirectUrl = $this->
http->request()->getServerParams()[
'HTTP_REFERER'];
302 $urlParts = parse_url($redirectUrl);
304 if (isset($urlParts[
'path'])) {
305 $script = basename($urlParts[
'path'],
'.php');
306 if ($script ===
'login') {
307 $this->
ctrl->returnToParent($this);
309 $redirectUrl = ltrim(basename($urlParts[
'path']),
'/');
310 if (isset($urlParts[
'query'])) {
311 $redirectUrl .=
'?' . $urlParts[
'query'];
316 if ($redirectUrl !==
'') {
317 $this->
ctrl->redirectToURL($redirectUrl);
321 $this->
ctrl->returnToParent($this);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Builds a Color from either hex- or rgb values.
Stream factory which enables the user to create streams without the knowledge of the concrete class.
static getInstanceByGlobalUser(?ilObjUser $user=null)
Class ilBuddySystemException.
asyncGetUnlinkModalConfirmationHtmlCommand()
transitionCommand(string $cmd, string $positiveFeedbackLanguageId, ?callable $onBeforeExecute=null)
isRequestParameterGiven(string $key, int $type)
readonly ilGlobalTemplateInterface $main_tpl
transitionAsyncCommand()
Performs a state transition based on the request action.
ilBuddySystemRelationStateFactory $stateFactory
const int BS_REQUEST_HTTP_POST
const int BS_REQUEST_HTTP_GET
static initializeFrontend(ilGlobalTemplateInterface $page)
static bool $isFrontendInitialized
Class ilBuddySystemRelationStateAlreadyGivenException.
Class ilBuddySystemRelationStateFactory.
static getInstance(?ilLanguage $lng=null)
Class ilBuddySystemRelationStateTransitionException.
Class ilBuddySystemRelation.
Base class for ILIAS Exception handling.
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)
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.
An entity that renders components to a string output.
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.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))