From 2dec9a08d13dc848ba0a73b6dd5bdd6070e4d999 Mon Sep 17 00:00:00 2001 From: i-do-dev Date: Fri, 7 Aug 2020 15:10:00 +0500 Subject: [PATCH] deeplinking + project redirection on lti launch --- .htaccess | 9 +++ src/App.php | 10 ++- src/Controllers/Content.php | 133 ++++++++++++++++++++++++++++++++++++ src/ParamValidate.php | 15 ++++ 4 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 .htaccess create mode 100644 src/Controllers/Content.php diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..41b0445 --- /dev/null +++ b/.htaccess @@ -0,0 +1,9 @@ + + RewriteEngine on + RewriteRule ^content$ index.php/content [L,QSA] + RewriteRule ^content/processtolms$ index.php/content/processtolms [L,QSA] + + + + FallbackResource index.php + \ No newline at end of file diff --git a/src/App.php b/src/App.php index 5e34b98..5cbce6c 100644 --- a/src/App.php +++ b/src/App.php @@ -17,7 +17,7 @@ public function bootstrap() { if(!is_null($this->controller)){ global $path_info_parts; - //execute controller instead LTI Launch + //execute controller instead LTI Launch - also set controller action if (isset($path_info_parts[1]) && method_exists($this->controller, $path_info_parts[1])) { call_user_func(array($this->controller, $path_info_parts[1])); }else { @@ -28,7 +28,13 @@ public function bootstrap() //exectute LTI Launch $LTI = LTIX::requireData(); $playlist_id = ParamValidate::playlistInCustom($_SESSION) ?: ParamValidate::playlistInQueryString($_SESSION); - if ($playlist_id) { + $project_id = ParamValidate::projectInCustom($_SESSION) ?: ParamValidate::projectInQueryString($_SESSION); + if($project_id) { + $lti_token_params = http_build_query($_SESSION['lti_post']); + $project_studio_link = CURRIKI_STUDIO_HOST."/project/preview2/$project_id"; + $redirect_to_studio_url = $project_studio_link . "?" . $lti_token_params; + header("Location: $redirect_to_studio_url"); + }elseif ($playlist_id) { $lti_token_params = http_build_query($_SESSION['lti_post']); $playlist_studio_link = CURRIKI_STUDIO_HOST."/playlist/lti/preview/$playlist_id"; $redirect_to_studio_url = $playlist_studio_link . "?" . $lti_token_params; diff --git a/src/Controllers/Content.php b/src/Controllers/Content.php new file mode 100644 index 0000000..3390fff --- /dev/null +++ b/src/Controllers/Content.php @@ -0,0 +1,133 @@ +request = $request; + $this->response = $response; + $this->return_url = null; + $this->allow_lti = null; + $this->allow_link = null; + $this->allow_multiple = null; + $this->allow_import = null; + $this->LAUNCH = null; + $this->tool = null; + $this->debug = false; + $this->deeplink = false; + $this->deepLinkingLaunch(); + } + + public function deepLinkingLaunch() + { + global $CFG; + // No parameter means we require CONTEXT, USER, and LINK + $this->LAUNCH = LTIX::requireData(LTIX::USER); + + // Model + $p = $CFG->dbprefix; + $tool_registrations = findAllRegistrations(false, true); + $this->tool = $tool_registrations['curriki']; + + + if ( isset($this->LAUNCH->deeplink) ) $this->deeplink = $this->LAUNCH->deeplink; + if ( $this->deeplink ) { + $this->return_url = $this->deeplink->returnUrl(); + $this->allow_lti = $this->deeplink->allowLtiLinkItem(); + $this->allow_link = $this->deeplink->allowLink(); + $this->allow_multiple = $this->deeplink->allowMultiple(); + $this->allow_import = $this->deeplink->allowImportItem(); + } else { + $this->return_url = ContentItem::returnUrl(); + $this->allow_lti = ContentItem::allowLtiLinkItem(); + $this->allow_link = ContentItem::allowLink(); + $this->allow_import = ContentItem::allowImportItem(); + $this->allow_multiple = ContentItem::allowMultiple(); + } + } + + public function index() + { + global $CFG; + $redirect_url = $CFG->apphome.'/mod/curriki/content/processtolms'; + $redirect_url = U::add_url_parm($redirect_url, 'PHPSESSID', session_id()); + + echo "

CurrikiStudio Projects

"; + echo ""; + } + + public function processtolms() + { + global $CFG; + $title = U::get($_GET, "title"); + $text = U::get($_GET, "text"); + $fa_icon = isset($this->tool['FontAwesome']) ? $this->tool['FontAwesome'] : false; + $presentationDocumentTarget = U::get($_GET, "presentationDocumentTarget"); + $displayWidth = U::get($_GET, "displayWidth"); + $displayHeight = U::get($_GET, "displayHeight"); + $additionalParams = array(); + if ( $presentationDocumentTarget ) { + $additionalParams['presentationDocumentTarget'] = $presentationDocumentTarget; + if ( ($presentationDocumentTarget == 'embed' || $presentationDocumentTarget == 'iframe') && + $displayWidth && $displayHeight && is_numeric($displayWidth) && is_numeric($displayHeight) ) { + $additionalParams['placementWidth'] = $displayWidth; + $additionalParams['placementHeight'] = $displayHeight; + } + } + $icon = false; + if ( $fa_icon !== false ) { + $icon = $CFG->fontawesome.'/png/'.str_replace('fa-','',$fa_icon).'.png'; + } + + // Set up to send the response + if ( $this->deeplink ) { + $retval = new DeepLinkResponse($this->deeplink); + } else { + $retval = new ContentItem(); + } + $points = false; + $activity_id = false; + if ( isset($this->tool['messages']) && is_array($this->tool['messages']) && + array_search('launch_grade', $this->tool['messages']) !== false ) { + $points = 10; + $activity_id = $install; + } + + $custom = false; + $projectid = U::get($_GET, "projectid"); + $custom = $projectid ? ['project' => $projectid] : null; + $path = $this->tool['url'] . '?project='.$projectid; + + $retval->addLtiLinkItem($path, $title, $text, $icon, $fa_icon, $custom, $points, $activity_id, $additionalParams); + + $iframeattr=false; $endform=false; + $content = $retval->prepareResponse($endform, $this->debug, $iframeattr); + echo($content); + + } + +} + diff --git a/src/ParamValidate.php b/src/ParamValidate.php index c283f87..b7218e1 100644 --- a/src/ParamValidate.php +++ b/src/ParamValidate.php @@ -15,4 +15,19 @@ public static function playlistInQueryString($session) { return isset($_SESSION['lti_post']) && isset($_SESSION['lti_post']['playlist']) ? $_SESSION['lti_post']['playlist'] : null; } + + public static function projectInCustom($session) + { + $lti_jwt = $session['tsugi_jwt']; + $lti_claim_custom_url = "https://purl.imsglobal.org/spec/lti/claim/custom"; + $lti_claim_custom = $lti_jwt->body->{$lti_claim_custom_url}; + return property_exists($lti_claim_custom, 'project') ? $lti_claim_custom->project : null; + } + + public static function projectInQueryString($session) + { + return isset($_SESSION['lti_post']) && isset($_SESSION['lti_post']['project']) ? $_SESSION['lti_post']['project'] : null; + } + + }