ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilLTIViewGUI Class Reference

class for ILIAS ViewLTI More...

+ Collaboration diagram for ilLTIViewGUI:

Public Member Functions

 __construct ()
 
 init ()
 Init LTI mode for lti authenticated users. More...
 
 executeCommand ()
 
 isActive ()
 
 initGUI ()
 
 getPostData ()
 
 getExternalCss ()
 
 getTitle ()
 
 getTitleForExitPage ()
 
 getShortTitle ()
 
 exitLti ()
 exit LTI session and if defined redirecting to returnUrl ToDo: Standard Template with delos ... More...
 
 logout (bool $force_ilias_logout=false)
 logout ILIAS and destroys Session and ilClientId cookie if no consumer is still open in the LTI User Session More...
 
 getCmdLink (String $cmd)
 

Static Public Member Functions

static getInstance ()
 for compatiblity with ilLTIRouterGUI More...
 

Data Fields

const CHECK_HTTP_REFERER = true
 contstants More...
 
ilLanguage $lng = null
 public variables More...
 

Protected Member Functions

 getContextId ()
 

Private Member Functions

 isLTIUser ()
 get LTI Mode from Users->getAuthMode More...
 
 getSessionValue (string $sess_key)
 
 getCookieValue (string $cookie_key)
 
 removeContextFromSession (string $context_id)
 
 findEffectiveRefId (?string $url=null)
 Find effective ref_id for request. More...
 

Private Attributes

ILIAS DI Container $dic = null
 private variables More...
 
int $user = null
 
ilLogger $log = null
 
string $link_dir = ""
 
int $effectiveRefId = null
 
ILIAS HTTP Wrapper WrapperFactory $wrapper
 
ILIAS Refinery KindlyTo Group $kindlyTo
 
ilLocatorGUI $locator
 

Detailed Description

class for ILIAS ViewLTI

Author
Stefan Schneider <schne.nosp@m.ider.nosp@m.@hrz..nosp@m.uni-.nosp@m.marbu.nosp@m.rg.d.nosp@m.e
Version
$id$

ilLTIViewGUI: ilLTIRouterGUI

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

Constructor & Destructor Documentation

◆ __construct()

ilLTIViewGUI::__construct ( )

Definition at line 60 of file class.ilLTIViewGUI.php.

References $DIC, ilLoggerFactory\getLogger(), ILIAS\Repository\lng(), and ILIAS\Repository\locator().

61  {
62  global $DIC;
63  $this->dic = $DIC;
64  $this->log = ilLoggerFactory::getLogger('ltis');
65  $this->lng = $this->dic->language();
66  $this->lng->loadLanguageModule('lti');
67  $this->wrapper = $DIC->http()->wrapper();
68  $this->kindlyTo = $DIC->refinery()->kindlyTo();
69  $this->locator = $DIC['ilLocator'];
70  }
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilLTIViewGUI::executeCommand ( )
Returns
void

Definition at line 113 of file class.ilLTIViewGUI.php.

References exitLti().

113  : void
114  {
115  global $ilCtrl;
116  $cmd = $ilCtrl->getCmd();
117  switch ($cmd) {
118  case 'exit':
119  $this->exitLti();
120  break;
121  }
122  }
exitLti()
exit LTI session and if defined redirecting to returnUrl ToDo: Standard Template with delos ...
+ Here is the call graph for this function:

◆ exitLti()

ilLTIViewGUI::exitLti ( )

exit LTI session and if defined redirecting to returnUrl ToDo: Standard Template with delos ...

Definition at line 324 of file class.ilLTIViewGUI.php.

References $renderer, ilSession\clear(), getContextId(), getPostData(), ilSession\has(), ILIAS\UI\examples\Symbol\Glyph\Header\header(), ILIAS\Repository\lng(), logout(), and removeContextFromSession().

Referenced by executeCommand().

324  : void
325  {
326  $this->log->info("exitLTI");
327  $force_ilias_logout = false;
328  $context_id = $this->getContextId();
329  if ($context_id == 0) {
330  $this->log->warning("could not find any valid context_id!");
331  $force_ilias_logout = true;
332  }
333  $post_data = $this->getPostData();
334 
335  $return_url = '';
336  if (isset($post_data['launch_presentation_return_url'])) {
337  $return_url = $post_data['launch_presentation_return_url'];
338  }
339  $this->removeContextFromSession((string) $context_id);
340 
341  if (ilSession::has('lti_' . $context_id . '_post_data')) {
342  ilSession::clear('lti_' . $context_id . '_post_data');
343  $this->log->debug('unset SESSION["' . 'lti_' . $context_id . '_post_data"]');
344  }
345 
346  if (!isset($return_url) || $return_url === '') {
347  $cc = $this->dic->globalScreen()->tool()->context()->current();
348  $cc->addAdditionalData(LtiViewLayoutProvider::GS_EXIT_LTI, true);
349  $ui_factory = $this->dic->ui()->factory();
350  $renderer = $this->dic->ui()->renderer();
351  $content = [
352  $ui_factory->messageBox()->info($this->lng->txt('lti_exited_info'))
353  ];
354  $tpl = $this->dic["tpl"];
355  $tpl->setContent($renderer->render($content));
356  $this->logout($force_ilias_logout);
357  $tpl->printToStdout();
358  } else {
359  $this->logout($force_ilias_logout);
360  header('Location: ' . $return_url);
361  }
362  }
$renderer
logout(bool $force_ilias_logout=false)
logout ILIAS and destroys Session and ilClientId cookie if no consumer is still open in the LTI User ...
removeContextFromSession(string $context_id)
static has($a_var)
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29
static clear(string $a_var)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findEffectiveRefId()

ilLTIViewGUI::findEffectiveRefId ( ?string  $url = null)
private

Find effective ref_id for request.

Parameters
string | null$url

Definition at line 434 of file class.ilLTIViewGUI.php.

References $url, ilSession\get(), ilSession\has(), ILIAS\Repository\int(), null, and ilSession\set().

Referenced by getContextId().

434  : void
435  {
436  $query = [];
437  if ($url === null) {
438  if ($this->wrapper->query()->has('ref_id')) {
439  $query['ref_id'] = $this->wrapper->query()->retrieve('ref_id', $this->kindlyTo->string());
440  }
441  if ($this->wrapper->query()->has('target')) {
442  $query['target'] = $this->wrapper->query()->retrieve('target', $this->kindlyTo->string());
443  }
444  } else {
445  parse_str((string) parse_url($url, PHP_URL_QUERY), $query);
446  }
447  if (isset($query['ref_id']) && (int) $query['ref_id']) {
448  $this->effectiveRefId = (int) $query['ref_id'];
449  return;
450  }
451  if (ilSession::has('lti_init_target') && ilSession::get('lti_init_target') != "") {
452  $target_arr = explode('_', ilSession::get('lti_init_target'));
453  ilSession::set('lti_init_target', "");
454  } else {
455  if (isset($query['target'])) {
456  $target_arr = explode('_', (string) $query['target']);
457  }
458  }
459  if (isset($target_arr[1]) and (int) $target_arr[1]) {
460  $this->effectiveRefId = (int) $target_arr[1];
461  }
462  }
static get(string $a_var)
$url
Definition: shib_logout.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static has($a_var)
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCmdLink()

ilLTIViewGUI::getCmdLink ( String  $cmd)
Parameters
String$cmd
Returns
String
Exceptions
ilCtrlException

Definition at line 394 of file class.ilLTIViewGUI.php.

References getContextId().

394  : String
395  {
396  global $ilCtrl;
397  $lti_context_id = $this->getContextId();
398  $lti_context_id_param = ($lti_context_id != '') ? "&lti_context_id=" . $lti_context_id : '';
399  $targetScript = "";
400  return $this->link_dir . $targetScript . $this->dic->ctrl()->getLinkTargetByClass(array('illtiroutergui',strtolower(get_class($this))), $cmd) . "&baseClass=illtiroutergui" . $lti_context_id_param;
401  }
+ Here is the call graph for this function:

◆ getContextId()

ilLTIViewGUI::getContextId ( )
protected
Returns
int|null

Definition at line 153 of file class.ilLTIViewGUI.php.

References $_SERVER, $DIC, $effectiveRefId, $path, $ref_id, ilObject\_lookupType(), CHECK_HTTP_REFERER, findEffectiveRefId(), ilSession\get(), ilSession\has(), ILIAS\Repository\int(), ILIAS\Repository\locator(), null, and ilUtil\redirect().

Referenced by exitLti(), getCmdLink(), and getPostData().

153  : ?int
154  {
155  global $DIC;
156 
157  // forced lti_context_id for example request command in exitLTI
158  if ($this->wrapper->query()->has('lti_context_id') &&
159  $this->wrapper->query()->retrieve('lti_context_id', $this->kindlyTo->string()) !== '') {
160  $contextId = (int) $this->wrapper->query()->retrieve('lti_context_id', $this->kindlyTo->int());
161  $this->log->debug("find context_id by GET param: " . (string) $contextId);
162  return $contextId;
163  }
164 
165  $this->findEffectiveRefId();
167  // ???
168  if (empty($ref_id)) {
169  return 0;
170  }
171 
172  $this->log->debug("Effective ref_id: " . $ref_id);
173  // context_id = ref_id in request
174  if (ilSession::has('lti_' . $ref_id . '_post_data')) {
175  $this->log->debug("lti context session exists for " . $ref_id);
176  // return $ref_id;
177  }
178  // sub item request
179  $this->log->debug("ref_id not exists as context_id, walking tree backwards to find a valid context_id");
180  $locator_items = $this->locator->getItems();
181  if (is_array($locator_items) && count($locator_items) > 0) {
182  for ($i = count($locator_items) - 1;$i >= 0;$i--) {
183  if (ilSession::has('lti_' . $locator_items[$i]['ref_id'] . '_post_data')) {
184  $this->log->debug("found valid ref_id in locator: " . $locator_items[$i]['ref_id']);
185  return $locator_items[$i]['ref_id'];
186  }
187  }
188  }
189  $this->log->warning("no valid context_id found for ref_id request: " . $ref_id);
190 
193  $obj_type = ilObject::_lookupType($ref_id, true);
194  $context_id = 0;
195  $referer = 0;
196 
197  // first try to get real http referer
198  if (isset($_SERVER['HTTP_REFERER'])) {
199  $this->findEffectiveRefId($_SERVER['HTTP_REFERER']);
200  } else { // only fallback and not reliable on multiple browser LTi contexts
201  if (ilSession::has('referer_ref_id')) {
202  $this->effectiveRefId = ilSession::get('referer_ref_id');
203  }
204  }
205 
206  $referrer = (int) $this->effectiveRefId;
207 
208  if ($referer > 0) {
209  if (ilSession::has('lti_' . $referer . '_post_data')) {
210  $ref_id = $referer;
211  $context_id = $referer;
212  $obj_type = ilObject::_lookupType($ref_id, true);
213  $this->log->debug("referer obj_type: " . $obj_type);
214  } else {
215  $this->log->debug("search tree of referer...");
216  if ($this->dic->repositoryTree()->isInTree($referer)) {
217  $path = $this->dic->repositoryTree()->getPathId($referer);
218  for ($i = count($path) - 1;$i >= 0;$i--) {
219  if (ilSession::has('lti_' . $path[$i] . '_post_data')) {
220  // redirect to referer, because it is valid
221  $ref_id = $referer;
222  $context_id = $path[$i];
223  $obj_type = ilObject::_lookupType($ref_id, true);
224  break;
225  }
226  }
227  }
228  }
229  }
230  if ($ref_id > 0 && $obj_type != '') {
231  if (
232  (
233  $this->wrapper->query()->has('baseClass') &&
234  $this->wrapper->query()->retrieve('baseClass', $this->kindlyTo->string()) === 'ilDashboardGUI'
235  )
236  &&
237  (
238  $this->wrapper->query()->has('cmdClass') &&
239  $this->wrapper->query()->retrieve('cmdClass', $this->kindlyTo->string()) === 'ilpersonalprofilegui'
240  )
241  ) {
242  return $context_id;
243  }
244  // $this->dic->ui()->mainTemplate()->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
245  $redirect = $this->link_dir . "goto.php?target=" . $obj_type . "_" . $ref_id . "&lti_context_id=" . $context_id;
246  $this->log->debug("redirect: " . $redirect);
247  ilUtil::redirect($redirect);
248  }
249  }
250  $lti_context_ids = ilSession::get('lti_context_ids');
251  if (is_array($lti_context_ids) && count($lti_context_ids) > 0) {
252  if (count($lti_context_ids) == 1) {
253  $this->log->debug("using context_id from only LTI session");
254  return $lti_context_ids[0];
255  } else {
256  $this->log->warning("Multiple LTI sessions exists. The context_id can not be clearly detected");
257  }
258  }
259  return null;
260  }
static get(string $a_var)
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
global $DIC
Definition: shib_login.php:22
static has($a_var)
static redirect(string $a_script)
const CHECK_HTTP_REFERER
contstants
static _lookupType(int $id, bool $reference=false)
findEffectiveRefId(?string $url=null)
Find effective ref_id for request.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCookieValue()

ilLTIViewGUI::getCookieValue ( string  $cookie_key)
private

Definition at line 412 of file class.ilLTIViewGUI.php.

412  : string
413  {
414  if ($this->dic->wrapper->cookie()->has($cookie_key) && $this->dic->wrapper->cookie()->retrieve($cookie_key, $this->dic->refinery()->kindlyTo()->string() != '')) {
415  return $this->dic->wrapper->cookie()->retrieve($cookie_key, $this->dic->refinery()->kindlyTo()->string());
416  } else {
417  return '';
418  }
419  }

◆ getExternalCss()

ilLTIViewGUI::getExternalCss ( )
Returns
string

Definition at line 283 of file class.ilLTIViewGUI.php.

References getPostData(), and null.

283  : string
284  {
285  $post_data = $this->getPostData();
286  if ($post_data !== null) {
287  return (isset($post_data['launch_presentation_css_url'])) ? $post_data['launch_presentation_css_url'] : '';
288  }
289  return '';
290  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

◆ getInstance()

static ilLTIViewGUI::getInstance ( )
static

for compatiblity with ilLTIRouterGUI

Returns
mixed

Definition at line 89 of file class.ilLTIViewGUI.php.

References $DIC.

90  {
91  global $DIC;
92  return $DIC["lti"];
93  }
global $DIC
Definition: shib_login.php:22

◆ getPostData()

ilLTIViewGUI::getPostData ( )
Returns
array|null

Definition at line 265 of file class.ilLTIViewGUI.php.

References ilSession\get(), getContextId(), and null.

Referenced by exitLti(), getExternalCss(), and getTitle().

265  : ?array
266  {
267  $context_id = $this->getContextId();
268  if ($context_id == 0) {
269  $this->log->warning("could not find any valid context_id!");
270  return null;
271  }
272  $post_data = ilSession::get('lti_' . $context_id . '_post_data');
273  if (!is_array($post_data)) {
274  $this->log->warning("no session post_data: " . "lti_" . $context_id . "_post_data");
275  return null;
276  }
277  return $post_data;
278  }
static get(string $a_var)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSessionValue()

ilLTIViewGUI::getSessionValue ( string  $sess_key)
private

Definition at line 403 of file class.ilLTIViewGUI.php.

References ilSession\get(), and ilSession\has().

403  : string
404  {
405  if (ilSession::has($sess_key) && ilSession::get($sess_key) != '') {
406  return ilSession::get($sess_key);
407  } else {
408  return '';
409  }
410  }
static get(string $a_var)
static has($a_var)
+ Here is the call graph for this function:

◆ getShortTitle()

ilLTIViewGUI::getShortTitle ( )
Returns
string

Definition at line 315 of file class.ilLTIViewGUI.php.

References ILIAS\Repository\lng().

315  : string
316  {
317  return $this->lng->txt('lti_mode');
318  }
+ Here is the call graph for this function:

◆ getTitle()

ilLTIViewGUI::getTitle ( )
Returns
string

Definition at line 295 of file class.ilLTIViewGUI.php.

References getPostData(), and null.

295  : string
296  {
297  $post_data = $this->getPostData();
298  if ($post_data !== null) {
299  return (isset($post_data['resource_link_title'])) ? "LTI - " . $post_data['resource_link_title'] : "LTI";
300  }
301  return "LTI";
302  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

◆ getTitleForExitPage()

ilLTIViewGUI::getTitleForExitPage ( )
Returns
string

Definition at line 307 of file class.ilLTIViewGUI.php.

References ILIAS\Repository\lng().

307  : string
308  {
309  return $this->lng->txt('lti_exited');
310  }
+ Here is the call graph for this function:

◆ init()

ilLTIViewGUI::init ( )

Init LTI mode for lti authenticated users.

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

References $context, initGUI(), and isLTIUser().

75  : void
76  {
77  $this->link_dir = (defined("ILIAS_MODULE")) ? "../" : "";
78  if ($this->isLTIUser()) {
79  $context = $this->dic->globalScreen()->tool()->context();
80  $context->claim()->lti();
81  $this->initGUI();
82  }
83  }
$context
Definition: webdav.php:31
isLTIUser()
get LTI Mode from Users->getAuthMode
+ Here is the call graph for this function:

◆ initGUI()

ilLTIViewGUI::initGUI ( )
Returns
void

Definition at line 135 of file class.ilLTIViewGUI.php.

Referenced by init().

135  : void
136  {
137  $this->log->debug("initGUI");
138  $baseclass = '';
139  if ($this->wrapper->query()->has('baseClass')) {
140  $baseclass = strtolower($this->wrapper->query()->retrieve('baseClass', $this->kindlyTo->string()));
141  }
142  if ($this->wrapper->query()->has('cmdClass')) {
143  $cmdclass = strtolower($this->wrapper->query()->retrieve('cmdClass', $this->kindlyTo->string()));
144  }
145  if ($baseclass == 'illtiroutergui') {
146  return;
147  }
148  }
+ Here is the caller graph for this function:

◆ isActive()

ilLTIViewGUI::isActive ( )
Returns
bool

Definition at line 127 of file class.ilLTIViewGUI.php.

References isLTIUser().

127  : bool
128  {
129  return $this->isLTIUser();
130  }
isLTIUser()
get LTI Mode from Users->getAuthMode
+ Here is the call graph for this function:

◆ isLTIUser()

ilLTIViewGUI::isLTIUser ( )
private

get LTI Mode from Users->getAuthMode

Returns
bool

Definition at line 99 of file class.ilLTIViewGUI.php.

References null.

Referenced by init(), and isActive().

99  : bool
100  {
101  if (!$this->dic->user() instanceof ilObjUser) {
102  return false;
103  }
104  if ($this->dic->user()->getAuthMode() == null) {
105  return false;
106  }
107  return (strpos($this->dic->user()->getAuthMode(), 'lti_') === 0);
108  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ logout()

ilLTIViewGUI::logout ( bool  $force_ilias_logout = false)

logout ILIAS and destroys Session and ilClientId cookie if no consumer is still open in the LTI User Session

Definition at line 367 of file class.ilLTIViewGUI.php.

References ilAuthUtils\AUTH_LOCAL, ilSession\get(), and ilUtil\setCookie().

Referenced by exitLti().

367  : void
368  {
369  if ($force_ilias_logout) {
370  $this->log->warning("forcing logout ilias session, maybe a broken LTI context");
371  } else {
372  if (is_array(ilSession::get('lti_context_ids')) && count(ilSession::get('lti_context_ids')) > 0) {
373  $this->log->debug("there is another valid consumer session: ilias session logout refused.");
374  return;
375  }
376  }
377  $this->log->info("logout");
378  $this->dic->user()->setAuthMode((string) ilAuthUtils::AUTH_LOCAL);
379  //ilSession::setClosingContext(ilSession::SESSION_CLOSE_USER); // needed?
380  $auth = $this->dic['ilAuthSession'];
381  //$auth->logout(); // needed?
382  // $auth->setExpired($auth::SESSION_AUTH_EXPIRED, ilAuthStatus::STATUS_UNDEFINED);
383  $auth->setExpired(true);
384  session_destroy();
385  ilUtil::setCookie("ilClientId", "");
386  ilUtil::setCookie("PHPSESSID", "");
387  }
static get(string $a_var)
static setCookie(string $a_cookie_name, string $a_cookie_value='', bool $a_also_set_super_global=true, bool $a_set_cookie_invalid=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeContextFromSession()

ilLTIViewGUI::removeContextFromSession ( string  $context_id)
private

Definition at line 421 of file class.ilLTIViewGUI.php.

References ilSession\get(), and ilSession\set().

Referenced by exitLti().

421  : void
422  {
423  $lti_context_ids = ilSession::get('lti_context_ids');
424  if (is_array($lti_context_ids) && in_array($context_id, $lti_context_ids)) {
425  array_splice($lti_context_ids, array_search($context_id, $lti_context_ids), 1);
426  ilSession::set('lti_context_ids', $lti_context_ids);
427  }
428  }
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $dic

ILIAS DI Container ilLTIViewGUI::$dic = null
private

private variables

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

◆ $effectiveRefId

int ilLTIViewGUI::$effectiveRefId = null
private

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

Referenced by getContextId().

◆ $kindlyTo

ILIAS Refinery KindlyTo Group ilLTIViewGUI::$kindlyTo
private

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

◆ $link_dir

string ilLTIViewGUI::$link_dir = ""
private

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

◆ $lng

ilLanguage ilLTIViewGUI::$lng = null

public variables

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

◆ $locator

ilLocatorGUI ilLTIViewGUI::$locator
private

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

◆ $log

ilLogger ilLTIViewGUI::$log = null
private

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

◆ $user

int ilLTIViewGUI::$user = null
private

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

◆ $wrapper

ILIAS HTTP Wrapper WrapperFactory ilLTIViewGUI::$wrapper
private

Definition at line 48 of file class.ilLTIViewGUI.php.

◆ CHECK_HTTP_REFERER

const ilLTIViewGUI::CHECK_HTTP_REFERER = true

contstants

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

Referenced by getContextId().


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