Implementing the return URL.

Still needs some help text when an error occurs.
This commit is contained in:
Chris Scribner
2011-11-06 20:41:57 -05:00
parent 60bd82f61d
commit 57d1dffd38
4 changed files with 99 additions and 13 deletions
+2 -1
View File
@@ -160,7 +160,6 @@ $string['validurl'] = 'A valid URL must start with http(s)://';
$string['viewsubmissions'] = 'View submissions and grading screen';
//New admin strings
$string['show_in_course'] = 'Show tool type when creating tool instances';
$string['delegate'] = 'Delegate to Instructor';
$string['tool_settings'] = 'Tool Settings';
@@ -210,6 +209,8 @@ $string['domain_mismatch'] = 'Launch URL\'s domain does not match tool configura
$string['custom_config'] = 'Using custom tool configuration.';
$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
$string['external_tool_type_help'] = <<<HTML
+23
View File
@@ -228,6 +228,12 @@ function lti_build_request($instance, $typeconfig, $course) {
//Add outcome service URL
$url = new moodle_url('/mod/lti/service.php');
$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
// Instructor parameters are only taken into consideration if the administrator
@@ -1032,4 +1038,21 @@ function lti_get_type($typeid){
global $DB;
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
View File
@@ -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);
}
}
+1 -12
View File
@@ -91,18 +91,7 @@ $PAGE->set_context($context);
$url = new moodle_url('/mod/lti/view.php', array('id'=>$cm->id));
$PAGE->set_url($url);
$launchcontainer = $basiclti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ?
$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;
}
$launchcontainer = lti_get_launch_container($basiclti, $toolconfig);
if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){
$PAGE->set_pagelayout('frametop'); //Most frametops don't include footer, and pre-post blocks