ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilBuddySystemGUI Class Reference

Class ilBuddySystemGUI. More...

+ Collaboration diagram for ilBuddySystemGUI:

Public Member Functions

 __construct ()
 ilBuddySystemGUI constructor. More...
 
 executeCommand ()
 

Static Public Member Functions

static initializeFrontend (ilGlobalTemplateInterface $page)
 

Data Fields

const BS_REQUEST_HTTP_GET = 1
 
const BS_REQUEST_HTTP_POST = 2
 

Protected Member Functions

 isRequestParameterGiven (string $key, int $type)
 

Protected Attributes

 $ctrl
 
 $buddyList
 
 $stateFactory
 
 $user
 
 $lng
 
 $http
 

Static Protected Attributes

static $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 ()
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBuddySystemGUI::__construct ( )

ilBuddySystemGUI constructor.

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

42 {
43 global $DIC;
44
45 $this->http = $DIC->http();
46 $this->ctrl = $DIC['ilCtrl'];
47 $this->user = $DIC['ilUser'];
48 $this->lng = $DIC['lng'];
49
50 $this->buddyList = ilBuddyList::getInstanceByGlobalUser();
52
53 $this->lng->loadLanguageModule('buddysystem');
54 }
user()
Definition: user.php:4
static getInstanceByGlobalUser()
static http()
Fetches the global http state from ILIAS.
$DIC
Definition: xapitoken.php:46

References $DIC, ilBuddySystemRelationStateFactory\getInstance(), ilBuddyList\getInstanceByGlobalUser(), ILIAS\FileDelivery\http(), and 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 user().

+ Here is the call graph for this function:

◆ ignoreCommand()

ilBuddySystemGUI::ignoreCommand ( )
private

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

147 : void
148 {
149 $this->transitionCommand('ignore', 'buddy_request_ignored');
150 }
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
Parameters
ilGlobalTemplateInterface$page

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

59 : void
60 {
61 global $DIC;
62
63 if (
64 ilBuddySystem::getInstance()->isEnabled() &&
65 !$DIC->user()->isAnonymous() &&
66 !self::$isFrontendInitialized
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',
75 'ilBuddySystemGUI'
76 ], '', '', true, false);
77 $config->transition_state_cmd = 'transitionAsync';
78 $page->addOnLoadCode("il.BuddySystem.setConfig(" . json_encode($config) . ");");
79
80 $btn_config = new stdClass();
81 $btn_config->bnt_class = 'ilBuddySystemLinkWidget';
82
83 $page->addOnLoadCode("il.BuddySystemButton.setConfig(" . json_encode($btn_config) . ");");
84 $page->addOnLoadCode("il.BuddySystemButton.init();");
85
86 self::$isFrontendInitialized = true;
87 }
88 }
addOnLoadCode($a_code, $a_batch=2)
Add on load code.
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68

References $config, $DIC, 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 return isset($_POST[$key]) && strlen($_POST[$key]);
120 break;
121
123 default:
124 return isset($_GET[$key]) && strlen($_GET[$key]);
125 break;
126 }
127 }
$_GET["client_id"]
$_POST["username"]
$type

References $_GET, $_POST, $type, BS_REQUEST_HTTP_GET, and BS_REQUEST_HTTP_POST.

◆ linkCommand()

ilBuddySystemGUI::linkCommand ( )
private

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

155 : void
156 {
157 $this->transitionCommand('link', 'buddy_request_approved');
158 }

References transitionCommand().

+ Here is the call graph for this function:

◆ redirectToReferer()

ilBuddySystemGUI::redirectToReferer ( )
private

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

273 : void
274 {
275 if (isset($this->http->request()->getServerParams()['HTTP_REFERER'])) {
276 $redirectUrl = $this->http->request()->getServerParams()['HTTP_REFERER'];
277 $urlParts = parse_url($redirectUrl);
278
279 if (isset($urlParts['path'])) {
280 $script = basename($urlParts['path'], '.php');
281 if ($script === 'login') {
282 $this->ctrl->returnToParent($this);
283 } else {
284 $redirectUrl = ltrim(basename($urlParts['path']), '/');
285 if (isset($urlParts['query'])) {
286 $redirectUrl .= '?' . $urlParts['query'];
287 }
288 }
289 }
290
291 if ($redirectUrl !== '') {
292 $this->ctrl->redirectToURL($redirectUrl);
293 }
294 }
295
296 $this->ctrl->returnToParent($this);
297 }

References ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ requestCommand()

ilBuddySystemGUI::requestCommand ( )
private

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

132 : void
133 {
134 $this->transitionCommand('request', 'buddy_relation_requested', function (ilBuddySystemRelation $relation) {
135 if (
136 $relation->isUnlinked() &&
137 !ilUtil::yn2tf(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 }
Class ilBuddySystemRelation.
static _lookupPref($a_usr_id, $a_keyword)
static yn2tf($a_yn)
convert "y"/"n" to true/false

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

204 : void
205 {
206 if (!$this->ctrl->isAsynch()) {
207 throw new RuntimeException('This action only supports AJAX http requests');
208 }
209
210 if (!isset($_POST['usr_id']) || !is_numeric($_POST['usr_id'])) {
211 throw new RuntimeException('Missing "usr_id" parameter');
212 }
213
214 if (!isset($_POST['action']) || !strlen($_POST['action'])) {
215 throw new RuntimeException('Missing "action" parameter');
216 }
217
218 $response = new stdClass();
219 $response->success = false;
220
221 try {
222 $usr_id = (int) $_POST['usr_id'];
223 $action = ilUtil::stripSlashes($_POST['action']);
224
225 if (ilObjUser::_isAnonymous($usr_id)) {
226 throw new ilBuddySystemException(sprintf(
227 "You cannot perform a state transition for the anonymous user (id: %s)",
228 $usr_id
229 ));
230 }
231
232 if (!strlen(ilObjUser::_lookupLogin($usr_id))) {
233 throw new ilBuddySystemException(sprintf(
234 "You cannot perform a state transition for a non existing user (id: %s)",
235 $usr_id
236 ));
237 }
238
239 $relation = $this->buddyList->getRelationByUserId($usr_id);
240
241 // The ILIAS JF decided to add a new personal setting
242 if (
243 $relation->isUnlinked() &&
244 !ilUtil::yn2tf(ilObjUser::_lookupPref($relation->getBuddyUsrId(), 'bs_allow_to_contact_me'))
245 ) {
246 throw new ilException("The requested user does not want to get contact requests");
247 }
248
249 try {
250 $this->buddyList->{$action}($relation);
251 $response->success = true;
253 $response->message = sprintf($this->lng->txt($e->getMessage()), ilObjUser::_lookupLogin((int) $usr_id));
255 $response->message = sprintf($this->lng->txt($e->getMessage()), ilObjUser::_lookupLogin((int) $usr_id));
256 } catch (Exception $e) {
257 $response->message = $this->lng->txt('buddy_bs_action_not_possible');
258 }
259
260 $response->state = get_class($relation->getState());
261 $response->state_html = $this->stateFactory->getStateButtonRendererByOwnerAndRelation(
262 $this->buddyList->getOwnerId(),
263 $relation
264 )->getHtml();
265 } catch (Exception $e) {
266 $response->message = $this->lng->txt('buddy_bs_action_not_possible');
267 }
268
269 echo json_encode($response);
270 exit();
271 }
Class ilBuddySystemException.
Base class for ILIAS Exception handling.
static _lookupLogin($a_user_id)
lookup login
static _isAnonymous($usr_id)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
exit
Definition: login.php:29
$response

References $_POST, Vendor\Package\$e, $response, ilObjUser\_isAnonymous(), ilObjUser\_lookupLogin(), ilObjUser\_lookupPref(), ilUtil\stripSlashes(), and ilUtil\yn2tf().

+ Here is the call graph for this function:

◆ transitionCommand()

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

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

169 : void {
170 if (!$this->isRequestParameterGiven('user_id', self::BS_REQUEST_HTTP_GET)) {
171 ilUtil::sendInfo($this->lng->txt('buddy_bs_action_not_possible'), true);
172 $this->ctrl->returnToParent($this);
173 }
174
175 try {
176 $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId((int) $_GET['user_id']);
177
178 if (null !== $onBeforeExecute) {
179 $onBeforeExecute($relation);
180 }
181
182 ilBuddyList::getInstanceByGlobalUser()->{$cmd}($relation);
183 ilUtil::sendSuccess($this->lng->txt($positiveFeedbackLanguageId), true);
185 ilUtil::sendInfo(sprintf(
186 $this->lng->txt($e->getMessage()),
187 ilObjUser::_lookupLogin((int) $_GET['user_id'])
188 ), true);
190 ilUtil::sendInfo(sprintf(
191 $this->lng->txt($e->getMessage()),
192 ilObjUser::_lookupLogin((int) $_GET['user_id'])
193 ), true);
194 } catch (ilException $e) {
195 ilUtil::sendInfo($this->lng->txt('buddy_bs_action_not_possible'), true);
196 }
197
198 $this->redirectToReferer();
199 }
isRequestParameterGiven(string $key, int $type)
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.

References ilUtil\sendInfo().

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

ilBuddySystemGUI::$buddyList
protected

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

◆ $ctrl

ilBuddySystemGUI::$ctrl
protected

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

◆ $http

ilBuddySystemGUI::$http
protected

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

◆ $isFrontendInitialized

ilBuddySystemGUI::$isFrontendInitialized = false
staticprotected

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

◆ $lng

ilBuddySystemGUI::$lng
protected

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

◆ $stateFactory

ilBuddySystemGUI::$stateFactory
protected

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

◆ $user

ilBuddySystemGUI::$user
protected

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

◆ BS_REQUEST_HTTP_GET

const ilBuddySystemGUI::BS_REQUEST_HTTP_GET = 1

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

Referenced by isRequestParameterGiven().

◆ BS_REQUEST_HTTP_POST

const ilBuddySystemGUI::BS_REQUEST_HTTP_POST = 2

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

Referenced by isRequestParameterGiven().


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