ILIAS  release_8 Revision v8.24
ilBuddySystemGUI Class Reference

Class ilBuddySystemGUI. More...

+ Collaboration diagram for ilBuddySystemGUI:

Public Member Functions

 __construct ()
 
 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 BS_REQUEST_HTTP_GET = 1
 
const BS_REQUEST_HTTP_POST = 2
 
ilGlobalTemplateInterface $main_tpl
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBuddySystemGUI::__construct ( )

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

44 {
45 global $DIC;
46 $this->main_tpl = $DIC->ui()->mainTemplate();
47
48 $this->http = $DIC->http();
49 $this->ctrl = $DIC['ilCtrl'];
50 $this->user = $DIC['ilUser'];
51 $this->lng = $DIC['lng'];
52
53 $this->buddyList = ilBuddyList::getInstanceByGlobalUser();
55
56 $this->lng->loadLanguageModule('buddysystem');
57 }
static getInstanceByGlobalUser()
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.

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

◆ executeCommand()

ilBuddySystemGUI::executeCommand ( )
Exceptions
RuntimeException

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

93 : void
94 {
95 if ($this->user->isAnonymous()) {
96 throw new RuntimeException('This controller only accepts requests of logged in users');
97 }
98
99 $nextClass = $this->ctrl->getNextClass($this);
100 $cmd = $this->ctrl->getCmd();
101
102 switch ($nextClass) {
103 default:
104 $cmd .= 'Command';
105 $this->$cmd();
106 break;
107 }
108 }

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

+ Here is the call graph for this function:

◆ ignoreCommand()

ilBuddySystemGUI::ignoreCommand ( )
private

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

145 : void
146 {
147 $this->transitionCommand('ignore', 'buddy_request_ignored');
148 }
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 59 of file class.ilBuddySystemGUI.php.

59 : void
60 {
61 global $DIC;
62
63 if (
64 !self::$isFrontendInitialized &&
65 ilBuddySystem::getInstance()->isEnabled() &&
66 !$DIC->user()->isAnonymous()
67 ) {
68 $DIC->language()->loadLanguageModule('buddysystem');
69
70 $page->addJavaScript('./Services/Contact/BuddySystem/js/buddy_system.js');
71
72 $config = new stdClass();
73 $config->http_post_url = $DIC->ctrl()->getFormActionByClass([
74 ilUIPluginRouterGUI::class,
75 self::class
76 ], '', '', true, false);
77 $config->transition_state_cmd = 'transitionAsync';
78 $page->addOnLoadCode('il.BuddySystem.setConfig(' . json_encode($config, JSON_THROW_ON_ERROR) . ');');
79
80 $btn_config = new stdClass();
81 $btn_config->bnt_class = 'ilBuddySystemLinkWidget';
82
83 $page->addOnLoadCode('il.BuddySystemButton.setConfig(' . json_encode($btn_config, JSON_THROW_ON_ERROR) . ');');
84 $page->addOnLoadCode('il.BuddySystemButton.init();');
85
86 self::$isFrontendInitialized = true;
87 }
88 }
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.
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85

References $config, $DIC, ilGlobalTemplateInterface\addJavaScript(), ilGlobalTemplateInterface\addOnLoadCode(), and ilBuddySystem\getInstance().

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
Parameters
string$key
int$type
Returns
bool

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

115 : bool
116 {
117 switch ($type) {
119 $body = $this->http->request()->getParsedBody();
120 return (isset($body[$key]) && is_string($body[$key]) && $body[$key] !== '');
121
123 default:
124 $query = $this->http->request()->getQueryParams();
125 return (isset($query[$key]) && is_string($query[$key]) && $query[$key] !== '');
126 }
127 }
string $key
Consumer key/client ID value.
Definition: System.php:193
$query
$type

References ILIAS\LTI\ToolProvider\$key, $query, $type, 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 150 of file class.ilBuddySystemGUI.php.

150 : void
151 {
152 $this->transitionCommand('link', 'buddy_request_approved');
153 }

References transitionCommand().

+ Here is the call graph for this function:

◆ redirectToReferer()

ilBuddySystemGUI::redirectToReferer ( )
private

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

263 : void
264 {
265 if (isset($this->http->request()->getServerParams()['HTTP_REFERER'])) {
266 $redirectUrl = $this->http->request()->getServerParams()['HTTP_REFERER'];
267 $urlParts = parse_url($redirectUrl);
268
269 if (isset($urlParts['path'])) {
270 $script = basename($urlParts['path'], '.php');
271 if ($script === 'login') {
272 $this->ctrl->returnToParent($this);
273 } else {
274 $redirectUrl = ltrim(basename($urlParts['path']), '/');
275 if (isset($urlParts['query'])) {
276 $redirectUrl .= '?' . $urlParts['query'];
277 }
278 }
279 }
280
281 if ($redirectUrl !== '') {
282 $this->ctrl->redirectToURL($redirectUrl);
283 }
284 }
285
286 $this->ctrl->returnToParent($this);
287 }

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

+ Here is the call graph for this function:

◆ requestCommand()

ilBuddySystemGUI::requestCommand ( )
private

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

129 : void
130 {
131 $this->transitionCommand(
132 'request',
133 'buddy_relation_requested',
134 static function (ilBuddySystemRelation $relation): void {
135 if (
136 $relation->isUnlinked() &&
137 !ilUtil::yn2tf((string) ilObjUser::_lookupPref($relation->getBuddyUsrId(), 'bs_allow_to_contact_me'))
138 ) {
139 throw new ilException('The requested user does not want to get contact requests');
140 }
141 }
142 );
143 }
Class ilBuddySystemRelation.
static _lookupPref(int $a_usr_id, string $a_keyword)
static yn2tf(string $a_yn)

References ilObjUser\_lookupPref(), ilBuddySystemRelation\getBuddyUsrId(), ilBuddySystemRelation\isUnlinked(), 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 190 of file class.ilBuddySystemGUI.php.

190 : void
191 {
192 if (!$this->ctrl->isAsynch()) {
193 throw new RuntimeException('This action only supports AJAX http requests');
194 }
195
196 if (!$this->isRequestParameterGiven('usr_id', self::BS_REQUEST_HTTP_POST)) {
197 throw new RuntimeException('Missing "usr_id" parameter');
198 }
199
200 if (!$this->isRequestParameterGiven('action', self::BS_REQUEST_HTTP_POST)) {
201 throw new RuntimeException('Missing "action" parameter');
202 }
203
204 $response = new stdClass();
205 $response->success = false;
206
207 try {
208 $usr_id = (int) $this->http->request()->getParsedBody()['usr_id'];
209 $action = ilUtil::stripSlashes($this->http->request()->getParsedBody()['action']);
210
211 if (ilObjUser::_isAnonymous($usr_id)) {
212 throw new ilBuddySystemException(sprintf(
213 'You cannot perform a state transition for the anonymous user (id: %s)',
214 $usr_id
215 ));
216 }
217
218 $login = ilObjUser::_lookupLogin($usr_id);
219 if ($login === '') {
220 throw new ilBuddySystemException(sprintf(
221 'You cannot perform a state transition for a non existing user (id: %s)',
222 $usr_id
223 ));
224 }
225
226 $relation = $this->buddyList->getRelationByUserId($usr_id);
227
228 // The ILIAS JF decided to add a new personal setting
229 if (
230 $relation->isUnlinked() &&
231 !ilUtil::yn2tf((string) ilObjUser::_lookupPref($relation->getBuddyUsrId(), 'bs_allow_to_contact_me'))
232 ) {
233 throw new ilException('The requested user does not want to get contact requests');
234 }
235
236 try {
237 $this->buddyList->{$action}($relation);
238 $response->success = true;
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');
243 }
244
245 $response->state = get_class($relation->getState());
246 $response->state_html = $this->stateFactory->getStateButtonRendererByOwnerAndRelation(
247 $this->buddyList->getOwnerId(),
248 $relation
249 )->getHtml();
250 } catch (Exception $e) {
251 $response->message = $this->lng->txt('buddy_bs_action_not_possible');
252 }
253
254 $this->http->saveResponse(
255 $this->http->response()
256 ->withAddedHeader('Content-Type', 'application/json')
257 ->withBody(ILIAS\Filesystem\Stream\Streams::ofString(json_encode($response, JSON_THROW_ON_ERROR)))
258 );
259 $this->http->sendResponse();
260 $this->http->close();
261 }
Class ilBuddySystemException.
isRequestParameterGiven(string $key, int $type)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _isAnonymous(int $usr_id)
static _lookupLogin(int $a_user_id)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
Class ChatMainBarProvider \MainMenu\Provider.
$response

References Vendor\Package\$e, $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 155 of file class.ilBuddySystemGUI.php.

159 : void {
160 if (!$this->isRequestParameterGiven('user_id', self::BS_REQUEST_HTTP_GET)) {
161 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('buddy_bs_action_not_possible'), true);
162 $this->ctrl->returnToParent($this);
163 }
164
165 $usrId = (int) $this->http->request()->getQueryParams()['user_id'];
166 try {
167 $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId($usrId);
168
169 if (null !== $onBeforeExecute) {
170 $onBeforeExecute($relation);
171 }
172
173 ilBuddyList::getInstanceByGlobalUser()->{$cmd}($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()),
179 ), true);
180 } catch (ilException $e) {
181 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('buddy_bs_action_not_possible'), true);
182 }
183
184 $this->redirectToReferer();
185 }

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 36 of file class.ilBuddySystemGUI.php.

◆ $ctrl

ilCtrlInterface ilBuddySystemGUI::$ctrl
protected

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

◆ $http

Services ilBuddySystemGUI::$http
protected

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

◆ $isFrontendInitialized

bool ilBuddySystemGUI::$isFrontendInitialized = false
staticprotected

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

◆ $lng

ilLanguage ilBuddySystemGUI::$lng
protected

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

◆ $main_tpl

ilGlobalTemplateInterface ilBuddySystemGUI::$main_tpl
private

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

◆ $stateFactory

ilBuddySystemRelationStateFactory ilBuddySystemGUI::$stateFactory
protected

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

◆ $user

ilObjUser ilBuddySystemGUI::$user
protected

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

◆ BS_REQUEST_HTTP_GET

const ilBuddySystemGUI::BS_REQUEST_HTTP_GET = 1
private

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

Referenced by isRequestParameterGiven().

◆ BS_REQUEST_HTTP_POST

const ilBuddySystemGUI::BS_REQUEST_HTTP_POST = 2
private

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

Referenced by isRequestParameterGiven().


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