Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

More work on the tool return page to help the user get the tool confi…

…gured.
  • Loading branch information...
commit c4d80efeb660cdfe5736537d7a1db67f66749527 1 parent 9d57ad1
scriby authored
20  mod/lti/db/access.php
@@ -68,4 +68,24 @@
68 68
             'manager' => CAP_ALLOW
69 69
         )
70 70
     ),
  71
+    
  72
+    'mod/lti:addcoursetool' => array(
  73
+        'captype' => 'write',
  74
+        'contextlevel' => CONTEXT_COURSE,
  75
+        'archetypes' => array(
  76
+            'teacher' => CAP_ALLOW,
  77
+            'editingteacher' => CAP_ALLOW,
  78
+            'manager' => CAP_ALLOW
  79
+        )
  80
+    ),
  81
+    
  82
+    'mod/lti:requesttooladd' => array(
  83
+        'captype' => 'write',
  84
+        'contextlevel' => CONTEXT_COURSE,
  85
+        'archetypes' => array(
  86
+            'teacher' => CAP_ALLOW,
  87
+            'editingteacher' => CAP_ALLOW,
  88
+            'manager' => CAP_ALLOW
  89
+        )
  90
+    )
71 91
 );
4  mod/lti/instructor_edit_tool_type.php
@@ -12,6 +12,8 @@
12 12
 $action = optional_param('action', null, PARAM_TEXT);
13 13
 $typeid = optional_param('typeid', null, PARAM_INT);
14 14
 
  15
+require_capability('mod/lti:addcoursetool', get_context_instance(CONTEXT_COURSE, $courseid));
  16
+
15 17
 if(!empty($typeid)){
16 18
     $type = lti_get_type($typeid);
17 19
     if($type->course != $courseid){
@@ -25,7 +27,7 @@
25 27
 
26 28
 $data = data_submitted();
27 29
 
28  
-if (confirm_sesskey() && isset($data->submitbutton)) {
  30
+if (isset($data->submitbutton) && confirm_sesskey()) {
29 31
     $type = new stdClass();
30 32
     
31 33
     if (!empty($typeid)) {
21  mod/lti/lang/en/lti.php
@@ -45,6 +45,12 @@
45 45
  * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
46 46
  */
47 47
 
  48
+//Permissions
  49
+$string['lti:view'] = 'View LTI activities';
  50
+$string['lti:grade'] = 'Grade LTI activities';
  51
+$string['lti:addcoursetool'] = 'Grade LTI activities';
  52
+$string['lti:requesttooladd'] = 'Submit a tool to admins for configuration';
  53
+
48 54
 $string['accept'] = 'Accept';
49 55
 $string['activity'] = 'Activity';
50 56
 $string['addnewapp'] = 'Enable External Application';
@@ -217,15 +223,24 @@
217 223
         This error may be a result of a missing consumer key and shared secret for the tool provider.
218 224
     </p>
219 225
     <p>
220  
-        If you have a consumer key and shared secret, you may enter it on the 
221  
-        <a href="{$a->instance_edit_url}" target="_top">external tool instance</a> (make sure advanced options are visible).<br />
222  
-        Alternatively, you may create a course level tool provider configuration <a href="{$a->course_tool_editor}" target="_top">here</a>.
  226
+        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 />
  227
+        Alternatively, you may create a course level tool provider configuration <a href="{$a->course_tool_editor}">here</a>.
223 228
     </p>
  229
+HTML;
  230
+$string['lti_launch_error_tool_request'] = <<<'HTML'
224 231
     <p>
225 232
         To submit a request for an administrator to complete the tool configuration, click <a href="{$a->admin_request_url}" target="_top">here</a>.
226 233
     </p>
227 234
 HTML;
228 235
 
  236
+$string['lti_tool_request_added'] = <<<HTML
  237
+    Tool configuration request successfully submitted. You may need to contact an administrator to complete the tool configuration.
  238
+HTML;
  239
+
  240
+$string['lti_tool_request_existing'] = <<<HTML
  241
+    A tool configuration for the tool domain has already been submitted.
  242
+HTML;
  243
+
229 244
 //Instance help
230 245
 
231 246
 $string['external_tool_type_help'] = <<<HTML
14  mod/lti/lib.php
@@ -384,11 +384,13 @@ function lti_grade_item_delete($basiclti) {
384 384
 function lti_extend_settings_navigation($settings, $parentnode) {
385 385
     global $PAGE;
386 386
     
387  
-    $keys = $parentnode->get_children_key_list();
  387
+    if(has_capability('mod/lti:grade', get_context_instance(CONTEXT_MODULE, $PAGE->cm->id))){
  388
+        $keys = $parentnode->get_children_key_list();
388 389
     
389  
-    $node = navigation_node::create('Submissions',
390  
-        new moodle_url('/mod/lti/grade.php', array('id'=>$PAGE->cm->id)),
391  
-        navigation_node::TYPE_SETTING, null, 'mod_lti_submissions');
392  
-    
393  
-    $parentnode->add_node($node, $keys[1]);
  390
+        $node = navigation_node::create('Submissions',
  391
+            new moodle_url('/mod/lti/grade.php', array('id'=>$PAGE->cm->id)),
  392
+            navigation_node::TYPE_SETTING, null, 'mod_lti_submissions');
  393
+
  394
+        $parentnode->add_node($node, $keys[1]);
  395
+    }
394 396
 }
20  mod/lti/locallib.php
@@ -139,7 +139,7 @@ function lti_view($instance) {
139 139
     $requestparams = lti_build_request($instance, $typeconfig, $course);
140 140
 
141 141
     $launchcontainer = lti_get_launch_container($instance, $typeconfig);
142  
-    $returnurlparams = array('course' => $course->id, 'launch_container' => $launchcontainer);
  142
+    $returnurlparams = array('course' => $course->id, 'launch_container' => $launchcontainer, 'instanceid' => $instance->id);
143 143
     
144 144
     if ( $orgid ) {
145 145
         $requestparams["tool_consumer_instance_guid"] = $orgid;
@@ -149,8 +149,8 @@ function lti_view($instance) {
149 149
         $returnurlparams['unsigned'] = '1';
150 150
         
151 151
         //Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns
152  
-    $url = new moodle_url('/mod/lti/return.php', $returnurlparams);
153  
-        $parms['launch_presentation_return_url'] = $url->out(false);    
  152
+        $url = new moodle_url('/mod/lti/return.php', $returnurlparams);
  153
+        $requestparams['launch_presentation_return_url'] = $url->out(false);    
154 154
     }
155 155
     
156 156
     if(!empty($key) && !empty($secret)){
@@ -1102,9 +1102,17 @@ function lti_get_type($typeid){
1102 1102
 }
1103 1103
 
1104 1104
 function lti_get_launch_container($lti, $toolconfig){
1105  
-    $launchcontainer = $lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ? 
1106  
-                        $toolconfig['launchcontainer'] :
1107  
-                        $lti->launchcontainer;
  1105
+    if($lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT){
  1106
+        if(isset($toolconfig['launchcontainer'])){
  1107
+            $launchcontainer = $toolconfig['launchcontainer'];
  1108
+        }
  1109
+    } else {
  1110
+        $launchcontainer = $lti->launchcontainer;
  1111
+    }
  1112
+    
  1113
+    if(empty($launchcontainer) || $launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT){
  1114
+        $launchcontainer = LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS;
  1115
+    }
1108 1116
 
1109 1117
     $devicetype = get_device_type();
1110 1118
 
44  mod/lti/request_tool.php
... ...
@@ -0,0 +1,44 @@
  1
+<?php
  2
+
  3
+require_once('../../config.php');
  4
+require_once($CFG->dirroot.'/mod/lti/lib.php');
  5
+
  6
+$instanceid = required_param('instanceid', PARAM_INT);
  7
+
  8
+$lti = $DB->get_record('lti', array('id' => $instanceid));
  9
+$course = $DB->get_record('course', array('id' => $lti->course));
  10
+
  11
+require_login($course);
  12
+
  13
+require_capability('mod/lti:requesttooladd', get_context_instance(CONTEXT_COURSE, $lti->course));
  14
+
  15
+$baseurl = lti_get_domain_from_url($lti->toolurl);
  16
+
  17
+$url = new moodle_url('/mod/lti/request_tool.php', array('instanceid' => $instanceid));
  18
+$PAGE->set_url($url);
  19
+
  20
+$pagetitle = strip_tags($course->shortname);
  21
+$PAGE->set_title($pagetitle);
  22
+$PAGE->set_heading($course->fullname);
  23
+
  24
+$PAGE->set_pagelayout('incourse');
  25
+
  26
+echo $OUTPUT->header();
  27
+
  28
+//Add a tool type if one does not exist already
  29
+if(!lti_get_tool_by_url_match($lti->toolurl, $lti->course, LTI_TOOL_STATE_ANY)){
  30
+    //There are no tools (active, pending, or rejected) for the launch URL. Create a new pending tool
  31
+    $tooltype = new stdClass();
  32
+    $toolconfig = new stdClass();
  33
+
  34
+    $toolconfig->lti_toolurl = lti_get_domain_from_url($lti->toolurl); 
  35
+    $toolconfig->lti_typename = $toolconfig->lti_toolurl;
  36
+
  37
+    lti_add_type($tooltype, $toolconfig);
  38
+    
  39
+    echo get_string('lti_tool_request_added', 'lti');
  40
+} else {
  41
+    echo get_string('lti_tool_request_existing', 'lti');
  42
+}
  43
+
  44
+echo $OUTPUT->footer();
22  mod/lti/return.php
@@ -6,8 +6,11 @@
6 6
 require_once($CFG->dirroot.'/mod/lti/lib.php');
7 7
 
8 8
 $courseid = required_param('course', PARAM_INT);
  9
+$instanceid = required_param('instanceid', PARAM_INT);
  10
+
9 11
 $errormsg = optional_param('lti_errormsg', '', PARAM_RAW);
10 12
 $unsigned = optional_param('unsigned', '0', PARAM_INT);
  13
+
11 14
 $launchcontainer = optional_param('launch_container', LTI_LAUNCH_CONTAINER_WINDOW, PARAM_INT);
12 15
 
13 16
 $course = $DB->get_record('course', array('id' => $courseid));
@@ -28,17 +31,28 @@
28 31
     } else {
29 32
         $PAGE->set_pagelayout('incourse');
30 33
     }
31  
-            
  34
+    
32 35
     echo $OUTPUT->header();
33 36
     
34 37
     echo get_string('lti_launch_error', 'lti');
35 38
     
36  
-    //TODO: Add some help around this error message.
37 39
     echo htmlspecialchars($errormsg);
38 40
 
39  
-    if($unsigned == 1){
  41
+    $canaddtools = has_capability('mod/lti:addcoursetool', get_context_instance(CONTEXT_COURSE, $courseid));
  42
+    
  43
+    if($unsigned == 1 && $canaddtools){
40 44
         echo '<br /><br />';
41  
-        echo get_string('lti_launch_error_unsigned_help', 'lti');
  45
+        
  46
+        $links = new stdClass();
  47
+        $coursetooleditor = new moodle_url('/mod/lti/instructor_edit_tool_type.php', array('course' => $courseid, 'action' => 'add'));
  48
+        $links->course_tool_editor = $coursetooleditor->out(false);
  49
+        
  50
+        $adminrequesturl = new moodle_url('/mod/lti/request_tool.php', array('instanceid' => $instanceid));
  51
+        $links->admin_request_url = $adminrequesturl->out(false);
  52
+        
  53
+        echo get_string('lti_launch_error_unsigned_help', 'lti', $links);
  54
+        
  55
+        echo get_string('lti_launch_error_tool_request', 'lti', $links);
42 56
     }
43 57
     
44 58
     echo $OUTPUT->footer();
2  mod/lti/version.php
@@ -46,5 +46,5 @@
46 46
  * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
47 47
  */
48 48
 
49  
-$module->version  = 2011100701;  // The current module version (Date: YYYYMMDDXX)
  49
+$module->version  = 2011101201;  // The current module version (Date: YYYYMMDDXX)
50 50
 $module->cron     = 0;           // Period for cron to check this module (secs)
2  mod/lti/view.php
@@ -81,7 +81,7 @@
81 81
 if($tool){
82 82
     $toolconfig = lti_get_type_config($tool->id);
83 83
 } else {
84  
-    $toolconfig = array('launchcontainer' => LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS);
  84
+    $toolconfig = array();
85 85
 }
86 86
 
87 87
 $PAGE->set_cm($cm, $course); // set's up global $COURSE

0 notes on commit c4d80ef

Please sign in to comment.
Something went wrong with that request. Please try again.