ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ilBuddySystemGUI Class Reference

Class ilBuddySystemGUI. More...

+ Collaboration diagram for ilBuddySystemGUI:

Public Member Functions

 __construct ()
 
 asyncGetUnlinkModalConfirmationHtmlCommand ()
 
 executeCommand ()
 

Static Public Member Functions

static initializeFrontend (ilGlobalTemplateInterface $page)
 

Protected Member Functions

 isRequestParameterGiven (string $key, int $type)
 

Protected Attributes

ilCtrlInterface $ctrl
 
ilBuddyList $buddyList
 
ilBuddySystemRelationStateFactory $stateFactory
 
ilObjUser $user
 
ilLanguage $lng
 
Services $http
 

Static Protected Attributes

static bool $isFrontendInitialized = false
 

Private Member Functions

 requestCommand ()
 
 ignoreCommand ()
 
 linkCommand ()
 
 transitionCommand (string $cmd, string $positiveFeedbackLanguageId, ?callable $onBeforeExecute=null)
 
 transitionAsyncCommand ()
 Performs a state transition based on the request action. More...
 
 redirectToReferer ()
 

Private Attributes

const int BS_REQUEST_HTTP_GET = 1
 
const int BS_REQUEST_HTTP_POST = 2
 
readonly ilGlobalTemplateInterface $main_tpl
 
UIFactory $ui_factory
 
UIRenderer $ui_renderer
 

Detailed Description

Class ilBuddySystemGUI.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de @ilCtrl_isCalledBy ilBuddySystemGUI: ilUIPluginRouterGUI, ILIAS\User\Profile\PublicProfileGUI

Definition at line 32 of file class.ilBuddySystemGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilBuddySystemGUI::__construct ( )

Definition at line 49 of file class.ilBuddySystemGUI.php.

50 {
51 global $DIC;
52 $this->main_tpl = $DIC->ui()->mainTemplate();
53
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();
60
61 $this->buddyList = ilBuddyList::getInstanceByGlobalUser();
63
64 $this->lng->loadLanguageModule('buddysystem');
65 }
static getInstanceByGlobalUser(?ilObjUser $user=null)
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\Repository\ctrl(), ilBuddySystemRelationStateFactory\getInstance(), ilBuddyList\getInstanceByGlobalUser(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ asyncGetUnlinkModalConfirmationHtmlCommand()

ilBuddySystemGUI::asyncGetUnlinkModalConfirmationHtmlCommand ( )

Definition at line 104 of file class.ilBuddySystemGUI.php.

104 : never
105 {
106 $modal_id = null;
107 $confirmation_modal = $this
108 ->ui_factory
109 ->modal()
110 ->interruptive(
111 $this->lng->txt('confirmation'),
112 $this->lng->txt('buddy_confirm_unlink'),
113 ''
114 )
115 ->withActionButtonLabel($this->lng->txt('confirm'))
116 ->withAdditionalOnLoadCode(function ($id) use (&$modal_id) {
117 $modal_id = $id;
118 return '';
119 });
120
121 $this->http->saveResponse(
122 $this->http->response()->withBody(
123 Streams::ofString(
124 json_encode([
125 'html' => $this->ui_renderer->renderAsync($confirmation_modal),
126 'signals' => [
127 'close' => $confirmation_modal->getCloseSignal()->getId()
128 ],
129 'modalId' => $modal_id
130 ], JSON_THROW_ON_ERROR)
131 )
132 )->withHeader(ResponseHeader::CONTENT_TYPE, 'application/json')
133 );
134 $this->http->sendResponse();
135 $this->http->close();
136 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id, ILIAS\FileDelivery\http(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ executeCommand()

ilBuddySystemGUI::executeCommand ( )
Exceptions
RuntimeException

Definition at line 141 of file class.ilBuddySystemGUI.php.

141 : void
142 {
143 if ($this->user->isAnonymous()) {
144 throw new RuntimeException('This controller only accepts requests of logged in users');
145 }
146
147 $this->{$this->ctrl->getCmd() . 'Command'}();
148 }

References ILIAS\Repository\ctrl(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ ignoreCommand()

ilBuddySystemGUI::ignoreCommand ( )
private

Definition at line 180 of file class.ilBuddySystemGUI.php.

180 : void
181 {
182 $this->transitionCommand('ignore', 'buddy_request_ignored');
183 }
transitionCommand(string $cmd, string $positiveFeedbackLanguageId, ?callable $onBeforeExecute=null)

References transitionCommand().

+ Here is the call graph for this function:

◆ initializeFrontend()

static ilBuddySystemGUI::initializeFrontend ( ilGlobalTemplateInterface  $page)
static

Definition at line 67 of file class.ilBuddySystemGUI.php.

67 : void
68 {
69 global $DIC;
70
71 if (
72 !self::$isFrontendInitialized &&
73 ilBuddySystem::getInstance()->isEnabled() &&
74 !$DIC->user()->isAnonymous()
75 ) {
76 $DIC->language()->loadLanguageModule('buddysystem');
77
78 $page->addJavaScript('./assets/js/buddy_system.js');
79 $page->addJavaScript('./assets/js/modal.min.js');
80
81 $config = new stdClass();
82 $config->async_get_unlink_modal_confirmation_html = $DIC->ctrl()->getLinkTargetByClass([
83 ilUIPluginRouterGUI::class,
84 self::class
85 ], 'asyncGetUnlinkModalConfirmationHtml', '', true, false);
86
87 $config->http_post_url = $DIC->ctrl()->getFormActionByClass([
88 ilUIPluginRouterGUI::class,
89 self::class
90 ], '', '', true, false);
91 $config->transition_state_cmd = 'transitionAsync';
92 $page->addOnLoadCode('il.BuddySystem.setConfig(' . json_encode($config, JSON_THROW_ON_ERROR) . ');');
93
94 $btn_config = new stdClass();
95 $btn_config->bnt_class = ilBuddySystemLinkButtonType::ROOT_CSS_CLASS;
96
97 $page->addOnLoadCode('il.BuddySystemButton.setConfig(' . json_encode($btn_config, JSON_THROW_ON_ERROR) . ');');
98 $page->addOnLoadCode('il.BuddySystemButton.init();');
99
100 self::$isFrontendInitialized = true;
101 }
102 }
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.

References $DIC, ILIAS\UICore\GlobalTemplate\addJavaScript(), ILIAS\UICore\GlobalTemplate\addOnLoadCode(), ilBuddySystem\getInstance(), and ilBuddySystemLinkButtonType\ROOT_CSS_CLASS.

Referenced by ilGlobalPageTemplate\prepareBasicJS().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRequestParameterGiven()

ilBuddySystemGUI::isRequestParameterGiven ( string  $key,
int  $type 
)
protected

Definition at line 150 of file class.ilBuddySystemGUI.php.

150 : bool
151 {
152 switch ($type) {
154 $body = $this->http->request()->getParsedBody();
155 return (isset($body[$key]) && is_string($body[$key]) && $body[$key] !== '');
156
158 default:
159 $query = $this->http->request()->getQueryParams();
160 return (isset($query[$key]) && is_string($query[$key]) && $query[$key] !== '');
161 }
162 }

References BS_REQUEST_HTTP_GET, BS_REQUEST_HTTP_POST, and ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ linkCommand()

ilBuddySystemGUI::linkCommand ( )
private

Definition at line 185 of file class.ilBuddySystemGUI.php.

185 : void
186 {
187 $this->transitionCommand('link', 'buddy_request_approved');
188 }

References transitionCommand().

+ Here is the call graph for this function:

◆ redirectToReferer()

ilBuddySystemGUI::redirectToReferer ( )
private

Definition at line 298 of file class.ilBuddySystemGUI.php.

298 : void
299 {
300 if (isset($this->http->request()->getServerParams()['HTTP_REFERER'])) {
301 $redirectUrl = $this->http->request()->getServerParams()['HTTP_REFERER'];
302 $urlParts = parse_url($redirectUrl);
303
304 if (isset($urlParts['path'])) {
305 $script = basename($urlParts['path'], '.php');
306 if ($script === 'login') {
307 $this->ctrl->returnToParent($this);
308 } else {
309 $redirectUrl = ltrim(basename($urlParts['path']), '/');
310 if (isset($urlParts['query'])) {
311 $redirectUrl .= '?' . $urlParts['query'];
312 }
313 }
314 }
315
316 if ($redirectUrl !== '') {
317 $this->ctrl->redirectToURL($redirectUrl);
318 }
319 }
320
321 $this->ctrl->returnToParent($this);
322 }

References ILIAS\Repository\ctrl(), and ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ requestCommand()

ilBuddySystemGUI::requestCommand ( )
private

Definition at line 164 of file class.ilBuddySystemGUI.php.

164 : void
165 {
166 $this->transitionCommand(
167 'request',
168 'buddy_relation_requested',
169 static function (ilBuddySystemRelation $relation): void {
170 if (
171 $relation->isUnlinked() &&
172 !ilUtil::yn2tf((string) ilObjUser::_lookupPref($relation->getBuddyUsrId(), 'bs_allow_to_contact_me'))
173 ) {
174 throw new ilException('The requested user does not want to get contact requests');
175 }
176 }
177 );
178 }
$relation
Class ilBuddySystemRelation.
static _lookupPref(int $a_usr_id, string $a_keyword)
static yn2tf(string $a_yn)

References $relation, ilObjUser\_lookupPref(), transitionCommand(), and ilUtil\yn2tf().

+ Here is the call graph for this function:

◆ transitionAsyncCommand()

ilBuddySystemGUI::transitionAsyncCommand ( )
private

Performs a state transition based on the request action.

Definition at line 225 of file class.ilBuddySystemGUI.php.

225 : void
226 {
227 if (!$this->ctrl->isAsynch()) {
228 throw new RuntimeException('This action only supports AJAX http requests');
229 }
230
231 if (!$this->isRequestParameterGiven('usr_id', self::BS_REQUEST_HTTP_POST)) {
232 throw new RuntimeException('Missing "usr_id" parameter');
233 }
234
235 if (!$this->isRequestParameterGiven('action', self::BS_REQUEST_HTTP_POST)) {
236 throw new RuntimeException('Missing "action" parameter');
237 }
238
239 $response = new stdClass();
240 $response->success = false;
241
242 try {
243 $usr_id = (int) $this->http->request()->getParsedBody()['usr_id'];
244 $action = ilUtil::stripSlashes($this->http->request()->getParsedBody()['action']);
245
246 if (ilObjUser::_isAnonymous($usr_id)) {
247 throw new ilBuddySystemException(sprintf(
248 'You cannot perform a state transition for the anonymous user (id: %s)',
249 $usr_id
250 ));
251 }
252
253 $login = ilObjUser::_lookupLogin($usr_id);
254 if ($login === '') {
255 throw new ilBuddySystemException(sprintf(
256 'You cannot perform a state transition for a non existing user (id: %s)',
257 $usr_id
258 ));
259 }
260
261 $relation = $this->buddyList->getRelationByUserId($usr_id);
262
263 // The ILIAS JF decided to add a new personal setting
264 if (
265 $relation->isUnlinked() &&
266 !ilUtil::yn2tf((string) ilObjUser::_lookupPref($relation->getBuddyUsrId(), 'bs_allow_to_contact_me'))
267 ) {
268 throw new ilException('The requested user does not want to get contact requests');
269 }
270
271 try {
272 $this->buddyList->{$action}($relation);
273 $response->success = true;
275 $response->message = sprintf($this->lng->txt($e->getMessage()), $login);
276 } catch (Exception) {
277 $response->message = $this->lng->txt('buddy_bs_action_not_possible');
278 }
279
280 $response->state = $relation->getState()::class;
281 $response->state_html = $this->stateFactory->getStateButtonRendererByOwnerAndRelation(
282 $this->buddyList->getOwnerId(),
284 )->getHtml();
285 } catch (Exception) {
286 $response->message = $this->lng->txt('buddy_bs_action_not_possible');
287 }
288
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)))
293 );
294 $this->http->sendResponse();
295 $this->http->close();
296 }
Class ilBuddySystemException.
isRequestParameterGiven(string $key, int $type)
Base class for ILIAS Exception handling.
static _isAnonymous(int $usr_id)
static _lookupLogin(int $a_user_id)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$response
Definition: xapitoken.php:90

References Vendor\Package\$e, $relation, $response, ilObjUser\_isAnonymous(), ilObjUser\_lookupLogin(), ilObjUser\_lookupPref(), ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\int(), ILIAS\Repository\lng(), ilUtil\stripSlashes(), and ilUtil\yn2tf().

+ Here is the call graph for this function:

◆ transitionCommand()

ilBuddySystemGUI::transitionCommand ( string  $cmd,
string  $positiveFeedbackLanguageId,
?callable  $onBeforeExecute = null 
)
private

Definition at line 190 of file class.ilBuddySystemGUI.php.

194 : void {
195 if (!$this->isRequestParameterGiven('user_id', self::BS_REQUEST_HTTP_GET)) {
196 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('buddy_bs_action_not_possible'), true);
197 $this->ctrl->returnToParent($this);
198 }
199
200 $usrId = (int) $this->http->request()->getQueryParams()['user_id'];
201 try {
202 $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId($usrId);
203
204 if (null !== $onBeforeExecute) {
205 $onBeforeExecute($relation);
206 }
207
209 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt($positiveFeedbackLanguageId), true);
211 $this->main_tpl->setOnScreenMessage('info', sprintf(
212 $this->lng->txt($e->getMessage()),
214 ), true);
215 } catch (Exception) {
216 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('buddy_bs_action_not_possible'), true);
217 }
218
219 $this->redirectToReferer();
220 }

References ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

Referenced by ignoreCommand(), linkCommand(), and requestCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $buddyList

ilBuddyList ilBuddySystemGUI::$buddyList
protected

Definition at line 40 of file class.ilBuddySystemGUI.php.

◆ $ctrl

ilCtrlInterface ilBuddySystemGUI::$ctrl
protected

Definition at line 39 of file class.ilBuddySystemGUI.php.

◆ $http

Services ilBuddySystemGUI::$http
protected

Definition at line 44 of file class.ilBuddySystemGUI.php.

◆ $isFrontendInitialized

bool ilBuddySystemGUI::$isFrontendInitialized = false
staticprotected

Definition at line 37 of file class.ilBuddySystemGUI.php.

◆ $lng

ilLanguage ilBuddySystemGUI::$lng
protected

Definition at line 43 of file class.ilBuddySystemGUI.php.

◆ $main_tpl

readonly ilGlobalTemplateInterface ilBuddySystemGUI::$main_tpl
private

Definition at line 45 of file class.ilBuddySystemGUI.php.

◆ $stateFactory

ilBuddySystemRelationStateFactory ilBuddySystemGUI::$stateFactory
protected

Definition at line 41 of file class.ilBuddySystemGUI.php.

◆ $ui_factory

UIFactory ilBuddySystemGUI::$ui_factory
private

Definition at line 46 of file class.ilBuddySystemGUI.php.

◆ $ui_renderer

UIRenderer ilBuddySystemGUI::$ui_renderer
private

Definition at line 47 of file class.ilBuddySystemGUI.php.

◆ $user

ilObjUser ilBuddySystemGUI::$user
protected

Definition at line 42 of file class.ilBuddySystemGUI.php.

◆ BS_REQUEST_HTTP_GET

const int ilBuddySystemGUI::BS_REQUEST_HTTP_GET = 1
private

Definition at line 34 of file class.ilBuddySystemGUI.php.

Referenced by isRequestParameterGiven().

◆ BS_REQUEST_HTTP_POST

const int ilBuddySystemGUI::BS_REQUEST_HTTP_POST = 2
private

Definition at line 35 of file class.ilBuddySystemGUI.php.

Referenced by isRequestParameterGiven().


The documentation for this class was generated from the following file: