More work on the tool return page to help the user get the tool configured.
authorChris Scribner <scriby@gmail.com>
Wed, 12 Oct 2011 17:07:08 +0000 (13:07 -0400)
committerChris Scribner <scriby@gmail.com>
Mon, 7 Nov 2011 01:42:00 +0000 (20:42 -0500)
mod/lti/db/access.php
mod/lti/instructor_edit_tool_type.php
mod/lti/lang/en/lti.php
mod/lti/lib.php
mod/lti/locallib.php
mod/lti/request_tool.php [new file with mode: 0644]
mod/lti/return.php
mod/lti/version.php
mod/lti/view.php

index 3006bb9..bc8a15f 100644 (file)
@@ -68,4 +68,24 @@ $capabilities = array(
             'manager' => CAP_ALLOW
         )
     ),
+    
+    'mod/lti:addcoursetool' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'archetypes' => array(
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'manager' => CAP_ALLOW
+        )
+    ),
+    
+    'mod/lti:requesttooladd' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'archetypes' => array(
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'manager' => CAP_ALLOW
+        )
+    )
 );
index 530f0ce..e355212 100644 (file)
@@ -12,6 +12,8 @@ $PAGE->set_pagelayout('popup');
 $action = optional_param('action', null, PARAM_TEXT);
 $typeid = optional_param('typeid', null, PARAM_INT);
 
+require_capability('mod/lti:addcoursetool', get_context_instance(CONTEXT_COURSE, $courseid));
+
 if(!empty($typeid)){
     $type = lti_get_type($typeid);
     if($type->course != $courseid){
@@ -25,7 +27,7 @@ echo $OUTPUT->header();
 
 $data = data_submitted();
 
-if (confirm_sesskey() && isset($data->submitbutton)) {
+if (isset($data->submitbutton) && confirm_sesskey()) {
     $type = new stdClass();
     
     if (!empty($typeid)) {
index e1634bf..77cebd1 100644 (file)
  * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
+//Permissions
+$string['lti:view'] = 'View LTI activities';
+$string['lti:grade'] = 'Grade LTI activities';
+$string['lti:addcoursetool'] = 'Grade LTI activities';
+$string['lti:requesttooladd'] = 'Submit a tool to admins for configuration';
+
 $string['accept'] = 'Accept';
 $string['activity'] = 'Activity';
 $string['addnewapp'] = 'Enable External Application';
@@ -217,15 +223,24 @@ $string['lti_launch_error_unsigned_help'] = <<<'HTML'
         This error may be a result of a missing consumer key and shared secret for the tool provider.
     </p>
     <p>
-        If you have a consumer key and shared secret, you may enter it on the 
-        <a href="{$a->instance_edit_url}" target="_top">external tool instance</a> (make sure advanced options are visible).<br />
-        Alternatively, you may create a course level tool provider configuration <a href="{$a->course_tool_editor}" target="_top">here</a>.
+        If you have a consumer key and shared secret, you may enter it when editing the external tool instance (make sure advanced options are visible).<br />
+        Alternatively, you may create a course level tool provider configuration <a href="{$a->course_tool_editor}">here</a>.
     </p>
+HTML;
+$string['lti_launch_error_tool_request'] = <<<'HTML'
     <p>
         To submit a request for an administrator to complete the tool configuration, click <a href="{$a->admin_request_url}" target="_top">here</a>.
     </p>
 HTML;
 
+$string['lti_tool_request_added'] = <<<HTML
+    Tool configuration request successfully submitted. You may need to contact an administrator to complete the tool configuration.
+HTML;
+
+$string['lti_tool_request_existing'] = <<<HTML
+    A tool configuration for the tool domain has already been submitted.
+HTML;
+
 //Instance help
 
 $string['external_tool_type_help'] = <<<HTML
index af8fe96..a807614 100644 (file)
@@ -384,11 +384,13 @@ function lti_grade_item_delete($basiclti) {
 function lti_extend_settings_navigation($settings, $parentnode) {
     global $PAGE;
     
-    $keys = $parentnode->get_children_key_list();
+    if(has_capability('mod/lti:grade', get_context_instance(CONTEXT_MODULE, $PAGE->cm->id))){
+        $keys = $parentnode->get_children_key_list();
     
-    $node = navigation_node::create('Submissions',
-        new moodle_url('/mod/lti/grade.php', array('id'=>$PAGE->cm->id)),
-        navigation_node::TYPE_SETTING, null, 'mod_lti_submissions');
-    
-    $parentnode->add_node($node, $keys[1]);
+        $node = navigation_node::create('Submissions',
+            new moodle_url('/mod/lti/grade.php', array('id'=>$PAGE->cm->id)),
+            navigation_node::TYPE_SETTING, null, 'mod_lti_submissions');
+
+        $parentnode->add_node($node, $keys[1]);
+    }
 }
\ No newline at end of file
index 60233e3..a2239f3 100644 (file)
@@ -139,7 +139,7 @@ function lti_view($instance) {
     $requestparams = lti_build_request($instance, $typeconfig, $course);
 
     $launchcontainer = lti_get_launch_container($instance, $typeconfig);
-    $returnurlparams = array('course' => $course->id, 'launch_container' => $launchcontainer);
+    $returnurlparams = array('course' => $course->id, 'launch_container' => $launchcontainer, 'instanceid' => $instance->id);
     
     if ( $orgid ) {
         $requestparams["tool_consumer_instance_guid"] = $orgid;
@@ -149,8 +149,8 @@ function lti_view($instance) {
         $returnurlparams['unsigned'] = '1';
         
         //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', $returnurlparams);
-        $parms['launch_presentation_return_url'] = $url->out(false);    
+        $url = new moodle_url('/mod/lti/return.php', $returnurlparams);
+        $requestparams['launch_presentation_return_url'] = $url->out(false);    
     }
     
     if(!empty($key) && !empty($secret)){
@@ -1102,9 +1102,17 @@ function lti_get_type($typeid){
 }
 
 function lti_get_launch_container($lti, $toolconfig){
-    $launchcontainer = $lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ? 
-                        $toolconfig['launchcontainer'] :
-                        $lti->launchcontainer;
+    if($lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT){
+        if(isset($toolconfig['launchcontainer'])){
+            $launchcontainer = $toolconfig['launchcontainer'];
+        }
+    } else {
+        $launchcontainer = $lti->launchcontainer;
+    }
+    
+    if(empty($launchcontainer) || $launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT){
+        $launchcontainer = LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS;
+    }
 
     $devicetype = get_device_type();
 
diff --git a/mod/lti/request_tool.php b/mod/lti/request_tool.php
new file mode 100644 (file)
index 0000000..80e50af
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+
+require_once('../../config.php');
+require_once($CFG->dirroot.'/mod/lti/lib.php');
+
+$instanceid = required_param('instanceid', PARAM_INT);
+
+$lti = $DB->get_record('lti', array('id' => $instanceid));
+$course = $DB->get_record('course', array('id' => $lti->course));
+
+require_login($course);
+
+require_capability('mod/lti:requesttooladd', get_context_instance(CONTEXT_COURSE, $lti->course));
+
+$baseurl = lti_get_domain_from_url($lti->toolurl);
+
+$url = new moodle_url('/mod/lti/request_tool.php', array('instanceid' => $instanceid));
+$PAGE->set_url($url);
+
+$pagetitle = strip_tags($course->shortname);
+$PAGE->set_title($pagetitle);
+$PAGE->set_heading($course->fullname);
+
+$PAGE->set_pagelayout('incourse');
+
+echo $OUTPUT->header();
+
+//Add a tool type if one does not exist already
+if(!lti_get_tool_by_url_match($lti->toolurl, $lti->course, LTI_TOOL_STATE_ANY)){
+    //There are no tools (active, pending, or rejected) for the launch URL. Create a new pending tool
+    $tooltype = new stdClass();
+    $toolconfig = new stdClass();
+
+    $toolconfig->lti_toolurl = lti_get_domain_from_url($lti->toolurl); 
+    $toolconfig->lti_typename = $toolconfig->lti_toolurl;
+
+    lti_add_type($tooltype, $toolconfig);
+    
+    echo get_string('lti_tool_request_added', 'lti');
+} else {
+    echo get_string('lti_tool_request_existing', 'lti');
+}
+
+echo $OUTPUT->footer();
\ No newline at end of file
index 8771961..fe84ac4 100644 (file)
@@ -6,8 +6,11 @@ require_once('../../config.php');
 require_once($CFG->dirroot.'/mod/lti/lib.php');
 
 $courseid = required_param('course', PARAM_INT);
+$instanceid = required_param('instanceid', PARAM_INT);
+
 $errormsg = optional_param('lti_errormsg', '', PARAM_RAW);
 $unsigned = optional_param('unsigned', '0', PARAM_INT);
+
 $launchcontainer = optional_param('launch_container', LTI_LAUNCH_CONTAINER_WINDOW, PARAM_INT);
 
 $course = $DB->get_record('course', array('id' => $courseid));
@@ -28,17 +31,28 @@ if(!empty($errormsg)){
     } else {
         $PAGE->set_pagelayout('incourse');
     }
-            
+    
     echo $OUTPUT->header();
     
     echo get_string('lti_launch_error', 'lti');
     
-    //TODO: Add some help around this error message.
     echo htmlspecialchars($errormsg);
 
-    if($unsigned == 1){
+    $canaddtools = has_capability('mod/lti:addcoursetool', get_context_instance(CONTEXT_COURSE, $courseid));
+    
+    if($unsigned == 1 && $canaddtools){
         echo '<br /><br />';
-        echo get_string('lti_launch_error_unsigned_help', 'lti');
+        
+        $links = new stdClass();
+        $coursetooleditor = new moodle_url('/mod/lti/instructor_edit_tool_type.php', array('course' => $courseid, 'action' => 'add'));
+        $links->course_tool_editor = $coursetooleditor->out(false);
+        
+        $adminrequesturl = new moodle_url('/mod/lti/request_tool.php', array('instanceid' => $instanceid));
+        $links->admin_request_url = $adminrequesturl->out(false);
+        
+        echo get_string('lti_launch_error_unsigned_help', 'lti', $links);
+        
+        echo get_string('lti_launch_error_tool_request', 'lti', $links);
     }
     
     echo $OUTPUT->footer();
index c8d95c8..5fbab51 100644 (file)
@@ -46,5 +46,5 @@
  * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-$module->version  = 2011100701;  // The current module version (Date: YYYYMMDDXX)
+$module->version  = 2011101201;  // The current module version (Date: YYYYMMDDXX)
 $module->cron     = 0;           // Period for cron to check this module (secs)
index b4ab3cc..212409f 100644 (file)
@@ -81,7 +81,7 @@ $tool = lti_get_tool_by_url_match($basiclti->toolurl);
 if($tool){
     $toolconfig = lti_get_type_config($tool->id);
 } else {
-    $toolconfig = array('launchcontainer' => LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS);
+    $toolconfig = array();
 }
 
 $PAGE->set_cm($cm, $course); // set's up global $COURSE