ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables 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 ()
 
 getContextId ()
 
 getPostData ()
 
 getExternalCss ()
 
 getTitle ()
 
 getTitleForExitPage ()
 
 getShortTitle ()
 
 exitLti ()
 exit LTI session and if defined redirecting to returnUrl ToDo: Standard Template with delos ... More...
 
 logout ($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...
 
 $lng = null
 public variables More...
 

Private Member Functions

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

Private Attributes

 $dic = null
 private variables More...
 
 $user = null
 
 $log = null
 
 $link_dir = ""
 

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 35 of file class.ilLTIViewGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilLTIViewGUI::__construct ( )

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

References $DIC.

56  {
57  global $DIC;
58  $this->dic = $DIC;
59  $this->log = $this->dic->logger()->lti();
60  $this->lng = $this->dic->language();
61  $this->lng->loadLanguageModule('lti');
62  }
$DIC
Definition: xapitoken.php:46

Member Function Documentation

◆ executeCommand()

ilLTIViewGUI::executeCommand ( )

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

References $ilCtrl, and exitLti().

100  {
101  global $ilCtrl;
102  $cmd = $ilCtrl->getCmd();
103  switch ($cmd) {
104  case 'exit':
105  $this->exitLti();
106  break;
107  }
108  }
global $ilCtrl
Definition: ilias.php:18
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 266 of file class.ilLTIViewGUI.php.

References $_SESSION, $tpl, getContextId(), getPostData(), logout(), and removeContextFromSession().

Referenced by executeCommand().

267  {
268  $this->dic->logger()->lti()->info("exitLTI");
269  $force_ilias_logout = false;
270  $context_id = $this->getContextId();
271  if ($context_id == '') {
272  $this->log->warning("could not find any valid context_id!");
273  $force_ilias_logout = true;
274  }
275  $post_data = $this->getPostData();
276  $return_url = ($post_data !== null) ? $post_data['launch_presentation_return_url'] : '';
277  $this->removeContextFromSession($context_id);
278 
279  if (isset($_SESSION['lti_' . $context_id . '_post_data'])) {
280  unset($_SESSION['lti_' . $context_id . '_post_data']);
281  $this->dic->logger()->lti()->debug('unset SESSION["' . 'lti_' . $context_id . '_post_data"]');
282  }
283  if (!isset($return_url) || $return_url === '') {
284  $cc = $this->dic->globalScreen()->tool()->context()->current();
285  $cc->addAdditionalData(LtiViewLayoutProvider::GS_EXIT_LTI, true);
286  $ui_factory = $this->dic->ui()->factory();
287  $renderer = $this->dic->ui()->renderer();
288  $content = [
289  $ui_factory->messageBox()->info($this->lng->txt('lti_exited_info'))
290  ];
291  $tpl = $this->dic["tpl"];
292  $tpl->setContent($renderer->render($content));
293  $this->logout($force_ilias_logout);
294  $tpl->printToStdout();
295  } else {
296  $this->logout($force_ilias_logout);
297  header('Location: ' . $return_url);
298  }
299  }
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$_SESSION["AccountId"]
removeContextFromSession($context_id)
logout($force_ilias_logout=false)
logout ILIAS and destroys Session and ilClientId cookie if no consumer is still open in the LTI User ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findEffectiveRefId()

ilLTIViewGUI::findEffectiveRefId (   $url = null)
private

Find effective ref_id for request.

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

References $_GET, $query, $target_arr, and $url.

Referenced by getContextId().

367  {
368  if ($url === null) {
369  $query = $_GET;
370  }
371  else {
372  parse_str(parse_url($url, PHP_URL_QUERY),$query);
373  }
374  if ((int) $query['ref_id']) {
375  return (int) $query['ref_id'];
376  }
377  $target_arr = explode('_', (string) $query['target']);
378  if (isset($target_arr[1]) and (int) $target_arr[1]) {
379  return (int) $target_arr[1];
380  }
381  return '';
382  }
$target_arr
Definition: goto.php:47
$_GET["client_id"]
$query
$url
+ Here is the caller graph for this function:

◆ getCmdLink()

ilLTIViewGUI::getCmdLink ( String  $cmd)

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

References $ilCtrl, and getContextId().

327  : String
328  {
329  global $ilCtrl;
330  $lti_context_id = $this->getContextId();
331  $lti_context_id_param = ($lti_context_id != '') ? "&lti_context_id=".$lti_context_id : '';
332  $targetScript = ($ilCtrl->getTargetScript() !== 'ilias.php') ? "ilias.php" : "";
333  return $this->link_dir.$targetScript.$ilCtrl->getLinkTargetByClass(array('illtiroutergui',strtolower(get_class($this))),$cmd)."&baseClass=illtiroutergui".$lti_context_id_param;
334  }
global $ilCtrl
Definition: ilias.php:18
+ Here is the call graph for this function:

◆ getContextId()

ilLTIViewGUI::getContextId ( )

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

References $_GET, $_SERVER, $_SESSION, $i, ilObject\_lookupType(), CHECK_HTTP_REFERER, findEffectiveRefId(), ilUtil\redirect(), and ilUtil\sendFailure().

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

128  {
129  global $ilLocator;
130 
131  // forced lti_context_id for example request command in exitLTI
132  if (isset($_GET['lti_context_id']) && $_GET['lti_context_id'] !== '') {
133  $this->log->debug("find context_id by GET param: " . $_GET['lti_context_id']);
134  return $_GET['lti_context_id'];
135  }
136 
137  $ref_id = $this->findEffectiveRefId();
138  $this->log->debug("Effective ref_id: ". $ref_id);
139  // context_id = ref_id in request
140  if (isset($_SESSION['lti_' . $ref_id . '_post_data'])) {
141  $this->log->debug("lti context session exists for " . $ref_id);
142  return $ref_id;
143  }
144 
145  // sub item request
146  $this->log->debug("ref_id not exists as context_id, walking tree backwards to find a valid context_id");
147  $locator_items = $ilLocator->getItems();
148  if (is_array($locator_items) && count($locator_items) > 0) {
149  for ($i = count($locator_items)-1;$i>=0;$i--) {
150  if (isset($_SESSION['lti_' . $locator_items[$i]['ref_id'] . '_post_data'])) {
151  $this->log->debug("found valid ref_id in locator: " . $locator_items[$i]['ref_id']);
152  return $locator_items[$i]['ref_id'];
153  }
154  }
155  }
156  $this->log->warning("no valid context_id found for ref_id request: " . $ref_id);
157 
159  $ref_id = '';
160  $obj_type = '';
161  $context_id = '';
162  $referer = '';
163 
164  // first try to get real http referer
165  if (isset($_SERVER['HTTP_REFERER'])) {
166  $referer = $this->findEffectiveRefId($_SERVER['HTTP_REFERER']);
167  }
168  else { // only fallback and not reliable on multiple browser LTi contexts
169  if (isset($_SESSION['referer_ref_id'])) {
170  $referer = $_SESSION['referer_ref_id'];
171  }
172  }
173 
174  if ($referer != '') {
175  if (isset($_SESSION['lti_' . $referer . '_post_data'])) {
176  $ref_id =$referer;
177  $context_id = $referer;
178  $obj_type = ilObject::_lookupType($ref_id,true);
179  $this->log->debug("referer obj_type: " . $obj_type);
180  }
181  else {
182  $this->log->debug("search tree of referer...");
183  if ($this->dic->repositoryTree()->isInTree($referer)) {
184  $path = $this->dic->repositoryTree()->getPathId($referer);
185  for ($i = count($path)-1;$i>=0;$i--) {
186  if (isset($_SESSION['lti_' . $path[$i] . '_post_data'])) {
187  // redirect to referer, because it is valid
188  $ref_id = $referer;
189  $context_id = $path[$i];
190  $obj_type = ilObject::_lookupType($ref_id,true);
191  break;
192  }
193  }
194  }
195  }
196  }
197  if ($ref_id != '' && $obj_type != '') {
198  if ((isset($_GET['baseClass']) && $_GET['baseClass'] === 'ilDashboardGUI')
199  && (isset($_GET['cmdClass']) && $_GET['cmdClass'] === 'ilpersonalprofilegui')) {
200  return $context_id;
201  }
202  ilUtil::sendFailure($this->lng->txt('permission_denied'),true);
203  $redirect = $this->link_dir."goto.php?target=".$obj_type."_".$ref_id."&lti_context_id=".$context_id;
204  $this->log->debug("redirect: " . $redirect);
205  ilUtil::redirect($redirect);
206  }
207  }
208  $lti_context_ids = $_SESSION['lti_context_ids'];
209  if (is_array($lti_context_ids) && count($lti_context_ids) > 0) {
210  if (count($lti_context_ids) == 1) {
211  $this->log->debug("using context_id from only LTI session");
212  return $lti_context_ids[0];
213  }
214  else {
215  $this->log->warning("Multiple LTI sessions exists. The context_id can not be clearly detected");
216  }
217  }
218  return '';
219  }
$_SESSION["AccountId"]
$_GET["client_id"]
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
findEffectiveRefId($url=null)
Find effective ref_id for request.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const CHECK_HTTP_REFERER
contstants
static redirect($a_script)
$i
Definition: metadata.php:24
+ 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 345 of file class.ilLTIViewGUI.php.

References $_COOKIE.

345  : String
346  {
347  if (isset($_COOKIE[$cookie_key]) && $_COOKIE[$cookie_key] != '') {
348  return $_COOKIE[$cookie_key];
349  }
350  else {
351  return '';
352  }
353  }
$_COOKIE[session_name()]
Definition: xapitoken.php:39

◆ getExternalCss()

ilLTIViewGUI::getExternalCss ( )

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

References getPostData().

235  {
236  $post_data = $this->getPostData();
237  if ($post_data !== null) {
238  return (isset($post_data['launch_presentation_css_url'])) ? $post_data['launch_presentation_css_url'] : '';
239  }
240  return '';
241  }
+ Here is the call graph for this function:

◆ getInstance()

static ilLTIViewGUI::getInstance ( )
static

for compatiblity with ilLTIRouterGUI

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

References $DIC.

82  {
83  global $DIC;
84  return $DIC["lti"];
85  }
$DIC
Definition: xapitoken.php:46

◆ getPostData()

ilLTIViewGUI::getPostData ( )

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

References $_SESSION, and getContextId().

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

221  {
222  $context_id = $this->getContextId();
223  if ($context_id == '') {
224  $this->log->warning("could not find any valid context_id!");
225  return null;
226  }
227  $post_data = $_SESSION['lti_' . $this->getContextId() . '_post_data'];
228  if (!is_array($post_data)) {
229  $this->log->warning("no session post_data: " . "lti_" . $this->getContextId() . "_post_data");
230  return null;
231  }
232  return $post_data;
233  }
$_SESSION["AccountId"]
+ 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 336 of file class.ilLTIViewGUI.php.

References $_SESSION.

336  : String
337  {
338  if (isset($_SESSION[$sess_key]) && $_SESSION[$sess_key] != '') {
339  return $_SESSION[$sess_key];
340  } else {
341  return '';
342  }
343  }
$_SESSION["AccountId"]

◆ getShortTitle()

ilLTIViewGUI::getShortTitle ( )

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

257  : string
258  {
259  return $this->lng->txt('lti_mode');
260  }

◆ getTitle()

ilLTIViewGUI::getTitle ( )

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

References getPostData().

243  : string
244  {
245  $post_data = $this->getPostData();
246  if ($post_data !== null) {
247  return (isset($post_data['resource_link_title'])) ? "LTI - " . $post_data['resource_link_title'] : "LTI";
248  }
249  return "LTI";
250  }
+ Here is the call graph for this function:

◆ getTitleForExitPage()

ilLTIViewGUI::getTitleForExitPage ( )

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

252  : string
253  {
254  return $this->lng->txt('lti_exited');
255  }

◆ init()

ilLTIViewGUI::init ( )

Init LTI mode for lti authenticated users.

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

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

68  {
69  $this->link_dir = (defined("ILIAS_MODULE")) ? "../" : "";
70  if ($this->isLTIUser())
71  {
72  $context = $this->dic->globalScreen()->tool()->context();
73  $context->claim()->lti();
74  $this->initGUI();
75  }
76  }
$context
Definition: webdav.php:26
isLTIUser()
get LTI Mode from Users->getAuthMode
+ Here is the call graph for this function:

◆ initGUI()

ilLTIViewGUI::initGUI ( )

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

References $_GET.

Referenced by init().

116  {
117  $this->log->debug("initGUI");
118  $baseclass = strtolower($_GET['baseClass']);
119  $cmdclass = strtolower($_GET['cmdClass']);
120  switch ($baseclass)
121  {
122  case 'illtiroutergui' :
123  return;
124  break;
125  }
126  }
$_GET["client_id"]
+ Here is the caller graph for this function:

◆ isActive()

ilLTIViewGUI::isActive ( )

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

References isLTIUser().

110  : bool
111  {
112  return $this->isLTIUser();
113  }
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
boolean

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

Referenced by init(), and isActive().

92  {
93  if (!$this->dic->user() instanceof ilObjUser) {
94  return false;
95  }
96  return (strpos($this->dic->user()->getAuthMode(), 'lti_') === 0);
97  }
+ Here is the caller graph for this function:

◆ logout()

ilLTIViewGUI::logout (   $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 304 of file class.ilLTIViewGUI.php.

References $_COOKIE, $_SESSION, $auth, $client_id, $GLOBALS, AUTH_LOCAL, ilUtil\setCookie(), and ilAuthStatus\STATUS_UNDEFINED.

Referenced by exitLti().

305  {
306  if ($force_ilias_logout) {
307  $this->log->warning("forcing logout ilias session, maybe a broken LTI context");
308  }
309  else {
310  if (is_array($_SESSION['lti_context_ids']) && count($_SESSION['lti_context_ids']) > 0) {
311  $this->log->debug("there is another valid consumer session: ilias session logout refused.");
312  return;
313  }
314  }
315  $this->dic->logger()->lti()->info("logout");
316  $GLOBALS['DIC']->user()->setAuthMode(AUTH_LOCAL);
317  //ilSession::setClosingContext(ilSession::SESSION_CLOSE_USER); // needed?
318  $auth = $GLOBALS['DIC']['ilAuthSession'];
319  //$auth->logout(); // needed?
320  $auth->setExpired($auth::SESSION_AUTH_EXPIRED,ilAuthStatus::STATUS_UNDEFINED);
321  session_destroy();
322  $client_id = $_COOKIE["ilClientId"];
323  ilUtil::setCookie("ilClientId", "");
324  ilUtil::setCookie("PHPSESSID","");
325  }
$_SESSION["AccountId"]
$auth
Definition: metadata.php:59
static setCookie($a_cookie_name, $a_cookie_value='', $a_also_set_super_global=true, $a_set_cookie_invalid=false)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
const AUTH_LOCAL
$client_id
$_COOKIE[session_name()]
Definition: xapitoken.php:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeContextFromSession()

ilLTIViewGUI::removeContextFromSession (   $context_id)
private

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

References $_SESSION.

Referenced by exitLti().

355  {
356  $lti_context_ids = $_SESSION['lti_context_ids'];
357  if (is_array($lti_context_ids) && in_array($context_id,$lti_context_ids)) {
358  array_splice($lti_context_ids,array_search($context_id,$lti_context_ids),1);
359  $_SESSION['lti_context_ids'] = $lti_context_ids;
360  }
361  }
$_SESSION["AccountId"]
+ Here is the caller graph for this function:

Field Documentation

◆ $dic

ilLTIViewGUI::$dic = null
private

private variables

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

◆ $link_dir

ilLTIViewGUI::$link_dir = ""
private

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

◆ $lng

ilLTIViewGUI::$lng = null

public variables

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

◆ $log

ilLTIViewGUI::$log = null
private

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

◆ $user

ilLTIViewGUI::$user = null
private

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

◆ CHECK_HTTP_REFERER

const ilLTIViewGUI::CHECK_HTTP_REFERER = true

contstants

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

Referenced by getContextId().


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