From c4d80efeb660cdfe5736537d7a1db67f66749527 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 12 Oct 2011 13:07:08 -0400 Subject: [PATCH] More work on the tool return page to help the user get the tool configured. --- mod/lti/db/access.php | 20 ++++++++++++ mod/lti/instructor_edit_tool_type.php | 4 ++- mod/lti/lang/en/lti.php | 21 +++++++++++-- mod/lti/lib.php | 14 +++++---- mod/lti/locallib.php | 20 ++++++++---- mod/lti/request_tool.php | 44 +++++++++++++++++++++++++++ mod/lti/return.php | 22 +++++++++++--- mod/lti/version.php | 2 +- mod/lti/view.php | 2 +- 9 files changed, 127 insertions(+), 22 deletions(-) create mode 100644 mod/lti/request_tool.php diff --git a/mod/lti/db/access.php b/mod/lti/db/access.php index 3006bb90f58..bc8a15f054a 100644 --- a/mod/lti/db/access.php +++ b/mod/lti/db/access.php @@ -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 + ) + ) ); diff --git a/mod/lti/instructor_edit_tool_type.php b/mod/lti/instructor_edit_tool_type.php index 530f0ce4e3d..e355212f77e 100644 --- a/mod/lti/instructor_edit_tool_type.php +++ b/mod/lti/instructor_edit_tool_type.php @@ -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)) { diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php index e1634bf0587..77cebd1070b 100644 --- a/mod/lti/lang/en/lti.php +++ b/mod/lti/lang/en/lti.php @@ -45,6 +45,12 @@ * @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.

- If you have a consumer key and shared secret, you may enter it on the - external tool instance (make sure advanced options are visible).
- Alternatively, you may create a course level tool provider configuration here. + 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).
+ Alternatively, you may create a course level tool provider configuration here.

+HTML; +$string['lti_launch_error_tool_request'] = <<<'HTML'

To submit a request for an administrator to complete the tool configuration, click here.

HTML; +$string['lti_tool_request_added'] = <<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 diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 60233e32c8f..a2239f39fce 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -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 index 00000000000..80e50af7499 --- /dev/null +++ b/mod/lti/request_tool.php @@ -0,0 +1,44 @@ +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 diff --git a/mod/lti/return.php b/mod/lti/return.php index 87719617d80..fe84ac4e869 100644 --- a/mod/lti/return.php +++ b/mod/lti/return.php @@ -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 '

'; - 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(); diff --git a/mod/lti/version.php b/mod/lti/version.php index c8d95c8550e..5fbab518b17 100644 --- a/mod/lti/version.php +++ b/mod/lti/version.php @@ -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) diff --git a/mod/lti/view.php b/mod/lti/view.php index b4ab3cc59f0..212409f12e4 100644 --- a/mod/lti/view.php +++ b/mod/lti/view.php @@ -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