Skip to content

Commit

Permalink
deeplinking + project redirection on lti launch
Browse files Browse the repository at this point in the history
  • Loading branch information
i-do-dev committed Aug 7, 2020
1 parent 54843b8 commit 2dec9a0
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^content$ index.php/content [L,QSA]
RewriteRule ^content/processtolms$ index.php/content/processtolms [L,QSA]
</IfModule>

<IfModule !mod_rewrite.c>
FallbackResource index.php
</IfModule>
10 changes: 8 additions & 2 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
133 changes: 133 additions & 0 deletions src/Controllers/Content.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
namespace CurrikiTsugi\Controllers;
use CurrikiTsugi\Interfaces\ControllerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use CurrikiTsugi\Repositories\IssuerRepository;
use CurrikiTsugi\Repositories\TenantRepository;
use Tsugi\Core\LTIX;
use \Tsugi\Util\U;
use \Tsugi\Core\Settings;
use \Tsugi\Core\ContentItem;
use \Tsugi\Core\DeepLinkResponse;
use \Tsugi\Util\LTI;
use \Tsugi\Util\LTI13;
use \Tsugi\UI\Lessons;

class Content implements ControllerInterface
{
public function __construct(Request $request, Response $response) {
$this->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 "<h2>CurrikiStudio Projects<h2>";
echo "<ul>";
echo '<li><a href="'.$redirect_url.'&title=The Basics Of Investing&projectid=5ed7034deed58f676319990b'.'">The Basics Of Investing</li>';
echo '<li><a href="'.$redirect_url.'&title=Exploring Our National Parks&projectid=5ed87c682ca48c1b4666ceb4'.'">Exploring Our National Parks</li>';
echo '<li><a href="'.$redirect_url.'&title=Globalization Robots And You&projectid=5ed88320e3e1042dc64d7a5e'.'">Globalization Robots And You</li>';
echo '<li><a href="'.$redirect_url.'&title=Electronics Tech. AAS Prep (Year 1)&projectid=5ed8fa36d6a2ad0bd543455f'.'">Electronics Tech. AAS Prep (Year 1)</li>';
echo '<li><a href="'.$redirect_url.'&title=How to Use CurrikiStudio&projectid=5eeae4ab75ce27706d2d18f4'.'">How to Use CurrikiStudio</li>';
echo '<li><a href="'.$redirect_url.'&title=UBS Keys To Your Future Demo&projectid=5eee38a0b51a5323cb2c2592'.'">UBS Keys To Your Future Demo</li>';
echo '<li><a href="'.$redirect_url.'&title=Financial Literacy for Kids&projectid=5efb8f8e7e7d7f10ca210dc3'.'">Financial Literacy for Kids</li>';
echo '<li><a href="'.$redirect_url.'&title=Chemistry - Part I&projectid=5f0df6586e5331109376618f'.'">Chemistry - Part I</li>';
echo '<li><a href="'.$redirect_url.'&title=Pre Algebra&projectid=5f11d0d6863db22c051b3ddc'.'">Pre Algebra</li>';
echo "</ul>";
}

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);

}

}

15 changes: 15 additions & 0 deletions src/ParamValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


}

0 comments on commit 2dec9a0

Please sign in to comment.