ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilBuddySystemGUI Class Reference

Class ilBuddySystemGUI. More...

+ Collaboration diagram for ilBuddySystemGUI:

Public Member Functions

 __construct ()
 
 executeCommand ()
 

Static Public Member Functions

static initializeFrontend ()
 

Data Fields

const BS_REQUEST_HTTP_GET = 1
 
const BS_REQUEST_HTTP_POST = 2
 

Protected Member Functions

 isRequestParameterGiven ($key, $type)
 

Protected Attributes

 $ctrl
 
 $buddylist
 
 $statefactory
 
 $user
 
 $lng
 
 $http
 

Static Protected Attributes

static $frontend_initialized = false
 

Private Member Functions

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

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBuddySystemGUI::__construct ( )

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

56 {
57 global $DIC;
58
59 $this->http = $DIC->http();
60 $this->ctrl = $DIC['ilCtrl'];
61 $this->user = $DIC['ilUser'];
62 $this->lng = $DIC['lng'];
63
64 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
65 require_once 'Services/Contact/BuddySystem/classes/states/class.ilBuddySystemRelationStateFactory.php';
66 $this->buddylist = ilBuddyList::getInstanceByGlobalUser();
68
69 $this->lng->loadLanguageModule('buddysystem');
70 }
user()
Definition: user.php:4
static getInstanceByGlobalUser()
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: saml.php:7

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

105 {
106 if ($this->user->isAnonymous()) {
107 throw new RuntimeException('This controller only accepts requests of logged in users');
108 }
109
110 $next_class = $this->ctrl->getNextClass($this);
111 $cmd = $this->ctrl->getCmd();
112
113 switch ($next_class) {
114 default:
115 $cmd .= 'Command';
116 $this->$cmd();
117 break;
118 }
119 }

References user().

+ Here is the call graph for this function:

◆ ignoreCommand()

ilBuddySystemGUI::ignoreCommand ( )
private

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

156 {
157 $this->transitionCommand('ignore', 'buddy_request_ignored');
158 }
transitionCommand($cmd, $positive_feedback_lng_id, callable $onBeforeExecute=null)

References transitionCommand().

+ Here is the call graph for this function:

◆ initializeFrontend()

static ilBuddySystemGUI::initializeFrontend ( )
static

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

76 {
77 global $DIC;
78
79 if (!self::$frontend_initialized) {
80 $DIC->language()->loadLanguageModule('buddysystem');
81
82 require_once 'Services/JSON/classes/class.ilJsonUtil.php';
83
84 $DIC['tpl']->addJavascript('./Services/Contact/BuddySystem/js/buddy_system.js');
85
86 $config = new stdClass();
87 $config->http_post_url = $DIC->ctrl()->getFormActionByClass(array('ilUIPluginRouterGUI', 'ilBuddySystemGUI'), '', '', true, false);
88 $config->transition_state_cmd = 'transitionAsync';
89 $DIC['tpl']->addOnLoadCode("il.BuddySystem.setConfig(" . ilJsonUtil::encode($config) . ");");
90
91 $btn_config = new stdClass();
92 $btn_config->bnt_class = 'ilBuddySystemLinkWidget';
93
94 $DIC['tpl']->addOnLoadCode("il.BuddySystemButton.setConfig(" . ilJsonUtil::encode($btn_config) . ");");
95 $DIC['tpl']->addOnLoadCode("il.BuddySystemButton.init();");
96
97 self::$frontend_initialized = true;
98 }
99 }
static encode($mixed, $suppress_native=false)
$config
Definition: bootstrap.php:15

References $config, $DIC, and ilJsonUtil\encode().

Referenced by ilBuddySystemLinkButton\getHtml(), and ilMainMenuGUI\populateWithBuddySystem().

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

◆ isRequestParameterGiven()

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

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

127 {
128 switch ($type) {
130 return isset($_POST[$key]) && strlen($_POST[$key]);
131 break;
132
134 default:
135 return isset($_GET[$key]) && strlen($_GET[$key]);
136 break;
137 }
138 }
$_GET["client_id"]
$_POST["username"]
$key
Definition: croninfo.php:18
$type

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

Referenced by transitionCommand().

+ Here is the caller graph for this function:

◆ linkCommand()

ilBuddySystemGUI::linkCommand ( )
private

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

164 {
165 $this->transitionCommand('link', 'buddy_request_approved');
166 }

References transitionCommand().

+ Here is the call graph for this function:

◆ redirectToReferer()

ilBuddySystemGUI::redirectToReferer ( )
private

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

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

References ILIAS\FileDelivery\http().

Referenced by transitionCommand().

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

◆ requestCommand()

ilBuddySystemGUI::requestCommand ( )
private

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

144 {
145 $this->transitionCommand('request', 'buddy_relation_requested', function (ilBuddySystemRelation $relation) {
146 if ($relation->isUnlinked() && !ilUtil::yn2tf(ilObjUser::_lookupPref($relation->getBuddyUserId(), 'bs_allow_to_contact_me'))) {
147 throw new ilException("The requested user does not want to get contact requests");
148 }
149 });
150 }
Class ilBuddySystemRelation.
static _lookupPref($a_usr_id, $a_keyword)
static yn2tf($a_yn)
convert "y"/"n" to true/false

References ilObjUser\_lookupPref(), ilBuddySystemRelation\getBuddyUserId(), 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.

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'];
224
225 if (ilObjUser::_isAnonymous($usr_id)) {
226 throw new ilBuddySystemException(sprintf("You cannot perform a state transition for the anonymous user (id: %s)", $usr_id));
227 }
228
229 if (!strlen(ilObjUser::_lookupLogin($usr_id))) {
230 throw new ilBuddySystemException(sprintf("You cannot perform a state transition for a non existing user (id: %s)", $usr_id));
231 }
232
233 $relation = $this->buddylist->getRelationByUserId($usr_id);
234
235 // The ILIAS JF decided to add a new personal setting
236 if ($relation->isUnlinked() && !ilUtil::yn2tf(ilObjUser::_lookupPref($relation->getBuddyUserId(), 'bs_allow_to_contact_me'))) {
237 throw new ilException("The requested user does not want to get contact requests");
238 }
239
240 try {
241 $this->buddylist->{$action}($relation);
242 $response->success = true;
244 $response->message = sprintf($this->lng->txt($e->getMessage()), ilObjUser::_lookupLogin((int) $usr_id));
246 $response->message = sprintf($this->lng->txt($e->getMessage()), ilObjUser::_lookupLogin((int) $usr_id));
247 } catch (Exception $e) {
248 $response->message = $this->lng->txt('buddy_bs_action_not_possible');
249 }
250
251 $response->state = get_class($relation->getState());
252 $response->state_html = $this->statefactory->getRendererByOwnerAndRelation($this->buddylist->getOwnerId(), $relation)->getHtml();
253 } catch (Exception $e) {
254 $response->message = $this->lng->txt('buddy_bs_action_not_possible');
255 }
256
257 echo json_encode($response);
258 exit();
259 }
exit
Definition: backend.php:16
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
$action
$response

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

+ Here is the call graph for this function:

◆ transitionCommand()

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

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

174 {
175 if (!$this->isRequestParameterGiven('user_id', self::BS_REQUEST_HTTP_GET)) {
176 ilUtil::sendInfo($this->lng->txt('buddy_bs_action_not_possible'), true);
177 $this->ctrl->returnToParent($this);
178 }
179
180 try {
181 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
182 $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId((int) $_GET['user_id']);
183
184 if (null !== $onBeforeExecute) {
185 $onBeforeExecute($relation);
186 }
187
188 ilBuddyList::getInstanceByGlobalUser()->$cmd($relation);
189 ilUtil::sendSuccess($this->lng->txt($positive_feedback_lng_id), true);
191 ilUtil::sendInfo(sprintf($this->lng->txt($e->getMessage()), ilObjUser::_lookupLogin((int) $_GET['user_id'])), true);
193 ilUtil::sendInfo(sprintf($this->lng->txt($e->getMessage()), ilObjUser::_lookupLogin((int) $_GET['user_id'])), true);
194 } catch (ilException $e) {
195 ilUtil::sendInfo($this->lng->txt('buddy_bs_action_not_possible'), true);
196 }
197
198 $this->redirectToReferer();
199 }
isRequestParameterGiven($key, $type)
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.

References $_GET, ilObjUser\_lookupLogin(), ilBuddyList\getInstanceByGlobalUser(), isRequestParameterGiven(), redirectToReferer(), and 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 30 of file class.ilBuddySystemGUI.php.

◆ $ctrl

ilBuddySystemGUI::$ctrl
protected

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

◆ $frontend_initialized

ilBuddySystemGUI::$frontend_initialized = false
staticprotected

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

◆ $http

ilBuddySystemGUI::$http
protected

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

◆ $lng

ilBuddySystemGUI::$lng
protected

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

◆ $statefactory

ilBuddySystemGUI::$statefactory
protected

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

◆ $user

ilBuddySystemGUI::$user
protected

Definition at line 40 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: