19declare(strict_types=1);
48 private \ILIAS\HTTP\Wrapper\WrapperFactory
$wrapper;
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'];
75 public function init(): void
77 $this->link_dir = (defined(
"ILIAS_MODULE")) ?
"../" :
"";
79 $context = $this->dic->globalScreen()->tool()->context();
101 if (!$this->dic->user() instanceof
ilObjUser) {
104 if ($this->dic->user()->getAuthMode() ==
null) {
107 return (strpos($this->dic->user()->getAuthMode(),
'lti_') === 0);
116 $cmd = $ilCtrl->getCmd();
137 $this->log->debug(
"initGUI");
140 if ($this->wrapper->query()->has(
'baseClass')) {
141 $baseclass = strtolower($this->wrapper->query()->retrieve(
'baseClass', $this->kindlyTo->string()));
143 if ($this->wrapper->query()->has(
'cmdClass')) {
144 $cmdclass = strtolower($this->wrapper->query()->retrieve(
'cmdClass', $this->kindlyTo->string()));
147 if ($baseclass ==
'illtiroutergui') {
160 if ($this->wrapper->query()->has(
'lti_context_id') &&
161 $this->wrapper->query()->retrieve(
'lti_context_id', $this->kindlyTo->string()) !==
'') {
162 $contextId = (
int) $this->wrapper->query()->retrieve(
'lti_context_id', $this->kindlyTo->int());
163 $this->log->debug(
"find context_id by GET param: " . (
string) $contextId);
174 $this->log->debug(
"Effective ref_id: " .
$ref_id);
177 $this->log->debug(
"lti context session exists for " .
$ref_id);
181 $this->log->debug(
"ref_id not exists as context_id, walking tree backwards to find a valid context_id");
182 $locator_items = $this->
locator->getItems();
183 if (is_array($locator_items) && count($locator_items) > 0) {
184 for ($i = count($locator_items) - 1;$i >= 0;$i--) {
185 if (
ilSession::has(
'lti_' . $locator_items[$i][
'ref_id'] .
'_post_data')) {
186 $this->log->debug(
"found valid ref_id in locator: " . $locator_items[$i][
'ref_id']);
187 return $locator_items[$i][
'ref_id'];
191 $this->log->warning(
"no valid context_id found for ref_id request: " .
$ref_id);
200 if (isset(
$_SERVER[
'HTTP_REFERER'])) {
208 $referer = (
int) $this->effectiveRefId;
213 $context_id = $referer;
215 $this->log->debug(
"referer obj_type: " . $obj_type);
217 $this->log->debug(
"search tree of referer...");
218 if ($this->dic->repositoryTree()->isInTree($referer)) {
219 $path = $this->dic->repositoryTree()->getPathId($referer);
220 for ($i = count(
$path) - 1;$i >= 0;$i--) {
224 $context_id =
$path[$i];
232 if (
$ref_id > 0 && $obj_type !=
'') {
235 $this->wrapper->query()->has(
'baseClass') &&
236 $this->wrapper->query()->retrieve(
'baseClass', $this->kindlyTo->string()) ===
'ilDashboardGUI'
240 $this->wrapper->query()->has(
'cmdClass') &&
241 $this->wrapper->query()->retrieve(
'cmdClass', $this->kindlyTo->string()) ===
'ilpersonalprofilegui'
247 $redirect = $this->link_dir .
"goto.php?target=" . $obj_type .
"_" .
$ref_id .
"<i_context_id=" . $context_id;
248 $this->log->debug(
"redirect: " . $redirect);
249 $DIC->ctrl()->redirectToURL($redirect);
253 if (is_array($lti_context_ids) && count($lti_context_ids) > 0) {
254 if (count($lti_context_ids) == 1) {
255 $this->log->debug(
"using context_id from only LTI session");
256 return $lti_context_ids[0];
258 $this->log->warning(
"Multiple LTI sessions exists. The context_id can not be clearly detected");
270 if ($context_id == 0) {
271 $this->log->warning(
"could not find any valid context_id!");
275 if (!is_array($post_data)) {
276 $this->log->warning(
"no session post_data: " .
"lti_" . $context_id .
"_post_data");
288 if ($post_data !==
null) {
289 return (isset($post_data[
'launch_presentation_css_url'])) ? $post_data[
'launch_presentation_css_url'] :
'';
300 if ($post_data !==
null) {
301 return (isset($post_data[
'resource_link_title'])) ?
"LTI - " . $post_data[
'resource_link_title'] :
"LTI";
311 return $this->
lng->txt(
'lti_exited');
319 return $this->
lng->txt(
'lti_mode');
328 $this->log->info(
"exitLTI");
329 $force_ilias_logout =
false;
331 if ($context_id == 0) {
332 $this->log->warning(
"could not find any valid context_id!");
333 $force_ilias_logout =
true;
338 if (isset($post_data[
'launch_presentation_return_url'])) {
339 $return_url = $post_data[
'launch_presentation_return_url'];
345 $this->log->debug(
'unset SESSION["' .
'lti_' . $context_id .
'_post_data"]');
348 if (!isset($return_url) || $return_url ===
'') {
349 $cc = $this->dic->globalScreen()->tool()->context()->current();
350 $cc->addAdditionalData(LtiViewLayoutProvider::GS_EXIT_LTI,
true);
351 $ui_factory = $this->dic->ui()->factory();
352 $renderer = $this->dic->ui()->renderer();
354 $ui_factory->messageBox()->info($this->
lng->txt(
'lti_exited_info'))
356 $tpl = $this->dic[
"tpl"];
357 $tpl->setContent(
$renderer->render($content));
358 $this->
logout($force_ilias_logout);
359 $tpl->printToStdout();
361 $this->
logout($force_ilias_logout);
362 header(
'Location: ' . $return_url);
369 public function logout(
bool $force_ilias_logout =
false): void
371 if ($force_ilias_logout) {
372 $this->log->warning(
"forcing logout ilias session, maybe a broken LTI context");
375 $this->log->debug(
"there is another valid consumer session: ilias session logout refused.");
379 $this->log->info(
"logout");
382 $auth = $this->dic[
'ilAuthSession'];
385 $auth->setExpired(
true);
400 $lti_context_id_param = ($lti_context_id !=
'') ?
"<i_context_id=" . $lti_context_id :
'';
402 return $this->link_dir . $targetScript . $this->dic->ctrl()->getLinkTargetByClass(array(
'illtiroutergui',strtolower(get_class($this))), $cmd) .
"&baseClass=illtiroutergui" . $lti_context_id_param;
416 if ($this->dic->wrapper->cookie()->has($cookie_key) && $this->dic->wrapper->cookie()->retrieve($cookie_key, $this->dic->refinery()->kindlyTo()->string() !=
'')) {
417 return $this->dic->wrapper->cookie()->retrieve($cookie_key, $this->dic->refinery()->kindlyTo()->string());
426 if (is_array($lti_context_ids) && in_array($context_id, $lti_context_ids)) {
427 array_splice($lti_context_ids, array_search($context_id, $lti_context_ids), 1);
440 if ($this->wrapper->query()->has(
'ref_id')) {
441 $query[
'ref_id'] = $this->wrapper->query()->retrieve(
'ref_id', $this->kindlyTo->string());
443 if ($this->wrapper->query()->has(
'target')) {
444 $query[
'target'] = $this->wrapper->query()->retrieve(
'target', $this->kindlyTo->string());
447 parse_str((
string) parse_url(
$url, PHP_URL_QUERY), $query);
449 if (isset($query[
'ref_id']) && (
int) $query[
'ref_id']) {
450 $this->effectiveRefId = (
int) $query[
'ref_id'];
457 if (isset($query[
'target'])) {
458 $target_arr = explode(
'_', (
string) $query[
'target']);
461 if (isset($target_arr[1]) and (
int) $target_arr[1]) {
462 $this->effectiveRefId = (
int) $target_arr[1];
Customizing of pimple-DIC for ILIAS.
Class LtiViewLayoutProvider.
@classDescription class for ILIAS ViewLTI
getSessionValue(string $sess_key)
removeContextFromSession(string $context_id)
ILIAS Refinery KindlyTo Group $kindlyTo
getCookieValue(string $cookie_key)
logout(bool $force_ilias_logout=false)
logout ILIAS and destroys Session and ilClientId cookie if no consumer is still open in the LTI User ...
findEffectiveRefId(?string $url=null)
Find effective ref_id for request.
isLTIUser()
get LTI Mode from Users->getAuthMode
ILIAS DI Container $dic
private variables
init()
Init LTI mode for lti authenticated users.
ilLanguage $lng
public variables
static getInstance()
for compatiblity with ilLTIRouterGUI
exitLti()
exit LTI session and if defined redirecting to returnUrl ToDo: Standard Template with delos ....
const CHECK_HTTP_REFERER
contstants
ILIAS HTTP Wrapper WrapperFactory $wrapper
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static _lookupType(int $id, bool $reference=false)
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
static setCookie(string $a_cookie_name, string $a_cookie_value='', bool $a_also_set_super_global=true, bool $a_set_cookie_invalid=false)