Skip to content

Commit

Permalink
Implementing the return URL.
Browse files Browse the repository at this point in the history
Still needs some help text when an error occurs.
  • Loading branch information
scriby committed Nov 7, 2011
1 parent 60bd82f commit 57d1dff
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 13 deletions.
3 changes: 2 additions & 1 deletion mod/lti/lang/en/lti.php
Expand Up @@ -160,7 +160,6 @@
$string['viewsubmissions'] = 'View submissions and grading screen'; $string['viewsubmissions'] = 'View submissions and grading screen';


//New admin strings //New admin strings

$string['show_in_course'] = 'Show tool type when creating tool instances'; $string['show_in_course'] = 'Show tool type when creating tool instances';
$string['delegate'] = 'Delegate to Instructor'; $string['delegate'] = 'Delegate to Instructor';
$string['tool_settings'] = 'Tool Settings'; $string['tool_settings'] = 'Tool Settings';
Expand Down Expand Up @@ -210,6 +209,8 @@
$string['custom_config'] = 'Using custom tool configuration.'; $string['custom_config'] = 'Using custom tool configuration.';
$string['tool_config_not_found'] = 'Tool configuration not found for this URL.'; $string['tool_config_not_found'] = 'Tool configuration not found for this URL.';


$string['return_to_course'] = 'Click <a href="{$a->link}" target="_top">here</a> to return to the course.';

//Instance help //Instance help


$string['external_tool_type_help'] = <<<HTML $string['external_tool_type_help'] = <<<HTML
Expand Down
23 changes: 23 additions & 0 deletions mod/lti/locallib.php
Expand Up @@ -228,6 +228,12 @@ function lti_build_request($instance, $typeconfig, $course) {
//Add outcome service URL //Add outcome service URL
$url = new moodle_url('/mod/lti/service.php'); $url = new moodle_url('/mod/lti/service.php');
$requestparams['lis_outcome_service_url'] = $url->out(); $requestparams['lis_outcome_service_url'] = $url->out();

$launchcontainer = lti_get_launch_container($instance, $typeconfig);

//Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns
$url = new moodle_url('/mod/lti/return.php', array('course' => $course->id, 'launch_container' => $launchcontainer));
$requestparams['launch_presentation_return_url'] = $url->out(false);


// Concatenate the custom parameters from the administrator and the instructor // Concatenate the custom parameters from the administrator and the instructor
// Instructor parameters are only taken into consideration if the administrator // Instructor parameters are only taken into consideration if the administrator
Expand Down Expand Up @@ -1032,4 +1038,21 @@ function lti_get_type($typeid){
global $DB; global $DB;


return $DB->get_record('lti_types', array('id' => $typeid)); return $DB->get_record('lti_types', array('id' => $typeid));
}

function lti_get_launch_container($lti, $toolconfig){
$launchcontainer = $lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ?
$toolconfig['launchcontainer'] :
$lti->launchcontainer;

$devicetype = get_device_type();

//Scrolling within the object element doesn't work on iOS or Android
//Opening the popup window also had some issues in testing
//For mobile devices, always take up the entire screen to ensure the best experience
if($devicetype === 'mobile' || $devicetype === 'tablet' ){
$launchcontainer = LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW;
}

return $launchcontainer;
} }
73 changes: 73 additions & 0 deletions mod/lti/return.php
@@ -0,0 +1,73 @@
<?php

//This page is used to handle the return back to Moodle from the tool provider

require_once('../../config.php');
require_once($CFG->dirroot.'/mod/lti/lib.php');

$courseid = required_param('course', PARAM_INT);
$errormsg = optional_param('lti_errormsg', '', PARAM_RAW);
$launchcontainer = optional_param('launch_container', LTI_LAUNCH_CONTAINER_WINDOW, PARAM_INT);

$course = $DB->get_record('course', array('id' => $courseid));

require_login($course);

if(!empty($errormsg)){
$url = new moodle_url('/mod/lti/return.php', array('course' => $courseid));
$PAGE->set_url($url);

$pagetitle = strip_tags($course->shortname);
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);

//Avoid frame-in-frame action
if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
$PAGE->set_pagelayout('embedded');
} else {
$PAGE->set_pagelayout('incourse');
}

echo $OUTPUT->header();

//TODO: Add some help around this error message.
echo htmlspecialchars($errormsg);

echo $OUTPUT->footer();
} else {
$courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
$url = $courseurl->out();

//Avoid frame-in-frame action
if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
//Output a page containing some script to break out of frames and redirect them

echo '<html><body>';

$script = <<<SCRIPT
<script type='text/javascript'>
//<![CDATA[
if(window != top){
top.location.href = '{$url}';
}
//]]
</script>
SCRIPT;

$clickhere = get_string('return_to_course', 'lti', (object)array('link' => $url));

$noscript = <<<NOSCRIPT
<noscript>
{$clickhere}
</noscript>
NOSCRIPT;

echo $script;
echo $noscript;

echo '</body></html>';
} else {
//If no error, take them back to the course
redirect($url);
}
}
13 changes: 1 addition & 12 deletions mod/lti/view.php
Expand Up @@ -91,18 +91,7 @@
$url = new moodle_url('/mod/lti/view.php', array('id'=>$cm->id)); $url = new moodle_url('/mod/lti/view.php', array('id'=>$cm->id));
$PAGE->set_url($url); $PAGE->set_url($url);


$launchcontainer = $basiclti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ? $launchcontainer = lti_get_launch_container($basiclti, $toolconfig);
$toolconfig['launchcontainer'] :
$basiclti->launchcontainer;

$devicetype = get_device_type();

//Scrolling within the object element doesn't work on iOS or Android
//Opening the popup window also had some issues in testing
//For mobile devices, always take up the entire screen to ensure the best experience
if($devicetype === 'mobile' || $devicetype === 'tablet' ){
$launchcontainer = LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW;
}


if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){ if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){
$PAGE->set_pagelayout('frametop'); //Most frametops don't include footer, and pre-post blocks $PAGE->set_pagelayout('frametop'); //Most frametops don't include footer, and pre-post blocks
Expand Down

0 comments on commit 57d1dff

Please sign in to comment.