Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing the method used to get LTI roles

  • Loading branch information...
commit 16cac56633e83231b52bda0041b1eb00ec62f745 1 parent 6d462df
@scriby scriby authored
View
13 mod/lti/db/access.php
@@ -45,7 +45,6 @@
$capabilities = array(
'mod/lti:view' => array(
-
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
@@ -69,6 +68,18 @@
)
),
+ 'mod/lti:manage' => array(
+ 'riskbitmask' => RISK_XSS,
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'archetypes' => array(
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW
+ )
+ ),
+
'mod/lti:addcoursetool' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
View
1  mod/lti/launch.php
@@ -80,5 +80,6 @@
add_to_log($course->id, "lti", "launch", "launch.php?id=$cm->id", "$basiclti->id");
+$basiclti->cmid = $cm->id;
lti_view($basiclti);
View
50 mod/lti/locallib.php
@@ -201,8 +201,11 @@ function lti_build_sourcedid($instanceid, $userid, $launchid = null, $servicesal
function lti_build_request($instance, $typeconfig, $course) {
global $USER, $CFG;
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
- $role = lti_get_ims_role($USER, $context);
+ if(empty($instance->cmid)){
+ $instance->cmid = 0;
+ }
+
+ $role = lti_get_ims_role($USER, $instance->cmid);
$locale = $course->lang;
if ( strlen($locale) < 1 ) {
@@ -433,34 +436,27 @@ function lti_map_keyname($key) {
}
/**
- * Returns the IMS user role in a given context
- *
- * This function queries Moodle for an user role and
- * returns the correspondant IMS role
- *
- * @param StdClass $user Moodle user instance
- * @param StdClass $context Moodle context
- *
- * @return string IMS Role
- *
+ * Gets the IMS role string for the specified user and LTI course module.
+ *
+ * @param mixed $user User object or user id
+ * @param int $cmid The course module id of the LTI activity
+ * @return string A role string suitable for passing with an LTI launch
*/
-function lti_get_ims_role($user, $context) {
-
- $roles = get_user_roles($context, $user->id);
- $rolesname = array();
- foreach ($roles as $role) {
- $rolesname[] = $role->shortname;
- }
-
- if (in_array('admin', $rolesname) || in_array('coursecreator', $rolesname)) {
- return get_string('imsroleadmin', 'lti');
+function lti_get_ims_role($user, $cmid) {
+ $context = get_context_instance(CONTEXT_MODULE, $cmid);
+ $roles = array();
+
+ if(has_capability('mod/lti:manage', $context)){
+ array_push($roles, 'Instructor');
+ } else {
+ array_push($roles, 'Learner');
}
-
- if (in_array('editingteacher', $rolesname) || in_array('teacher', $rolesname)) {
- return get_string('imsroleinstructor', 'lti');
+
+ if(is_siteadmin($user)){
+ array_push($roles, 'urn:lti:sysrole:ims/lis/Administrator');
}
-
- return get_string('imsrolelearner', 'lti');
+
+ return join(',', $roles);
}
/**
View
2  mod/lti/version.php
@@ -46,5 +46,5 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-$module->version = 2011101201; // The current module version (Date: YYYYMMDDXX)
+$module->version = 2011101400; // The current module version (Date: YYYYMMDDXX)
$module->cron = 0; // Period for cron to check this module (secs)
Please sign in to comment.
Something went wrong with that request. Please try again.