Permalink
Browse files

Update role checking to check course role if module is not available

  • Loading branch information...
1 parent 16cac56 commit 1d4f052e4626579e70485232ca71997a35384075 @scriby scriby committed Oct 17, 2011
Showing with 21 additions and 7 deletions.
  1. +21 −7 mod/lti/locallib.php
View
@@ -205,7 +205,7 @@ function lti_build_request($instance, $typeconfig, $course) {
$instance->cmid = 0;
}
- $role = lti_get_ims_role($USER, $instance->cmid);
+ $role = lti_get_ims_role($USER, $instance->cmid, $instance->course);
$locale = $course->lang;
if ( strlen($locale) < 1 ) {
@@ -442,16 +442,30 @@ function lti_map_keyname($key) {
* @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, $cmid) {
- $context = get_context_instance(CONTEXT_MODULE, $cmid);
+function lti_get_ims_role($user, $cmid, $courseid) {
$roles = array();
- if(has_capability('mod/lti:manage', $context)){
- array_push($roles, 'Instructor');
+ if(empty($cmid)){
+ //If no cmid is passed, check if the user is a teacher in the course
+ //This allows other modules to programmatically "fake" a launch without
+ //a real LTI instance
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
+
+ if(has_capability('moodle/course:manageactivities', $coursecontext)){
+ array_push($roles, 'Instructor');
+ } else {
+ array_push($roles, 'Learner');
+ }
} else {
- array_push($roles, 'Learner');
+ $context = get_context_instance(CONTEXT_MODULE, $cmid);
+
+ if(has_capability('mod/lti:manage', $context)){
+ array_push($roles, 'Instructor');
+ } else {
+ array_push($roles, 'Learner');
+ }
}
-
+
if(is_siteadmin($user)){
array_push($roles, 'urn:lti:sysrole:ims/lis/Administrator');
}

0 comments on commit 1d4f052

Please sign in to comment.