Implementing the return URL.
authorChris Scribner <scriby@gmail.com>
Thu, 6 Oct 2011 23:36:49 +0000 (19:36 -0400)
committerChris Scribner <scriby@gmail.com>
Mon, 7 Nov 2011 01:41:57 +0000 (20:41 -0500)
Still needs some help text when an error occurs.

mod/lti/lang/en/lti.php
mod/lti/locallib.php
mod/lti/return.php [new file with mode: 0644]
mod/lti/view.php

index 092b2bf..34e4376 100644 (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
index 795cd19..f25c93c 100644 (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;
 }
\ No newline at end of file
diff --git a/mod/lti/return.php b/mod/lti/return.php
new file mode 100644 (file)
index 0000000..b1c0ed8
--- /dev/null
@@ -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);
+    }
+}
\ No newline at end of file
index fb1759f..3ae2098 100644 (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