MDL-30344 lti - Fix issue with privacy settings not working for a course level tool...
[moodle.git] / mod / lti / ajax.php
index 8bcc089..bf1ba74 100644 (file)
@@ -39,14 +39,23 @@ $response = new stdClass();
 switch ($action) {
     case 'find_tool_config':
         $toolurl = required_param('toolurl', PARAM_RAW);
+        $toolid = optional_param('toolid', 0, PARAM_INT);
 
-        $tool = lti_get_tool_by_url_match($toolurl, $courseid);
-
-        if (!empty($tool)) {
-            $response->toolid = $tool->id;
-            $response->toolname = htmlspecialchars($tool->name);
-            $response->tooldomain = htmlspecialchars($tool->tooldomain);
+        if(empty($toolid) && !empty($toolurl)){
+            $tool = lti_get_tool_by_url_match($toolurl, $courseid);
+            
+            if(!empty($tool)){
+                $toolid = $tool->id;
             
+                $response->toolid = $tool->id;
+                $response->toolname = htmlspecialchars($tool->name);
+                $response->tooldomain = htmlspecialchars($tool->tooldomain);
+            }
+        } else {
+            $response->toolid = $toolid;
+        }
+        
+        if (!empty($toolid)) {
             //Look up privacy settings
             $query = 
             '
@@ -57,7 +66,7 @@ switch ($action) {
                 AND name IN (\'sendname\', \'sendemailaddr\', \'acceptgrades\', \'allowroster\')
             ';
                         
-            $privacyconfigs = $DB->get_records_sql($query, array('typeid' => $tool->id));
+            $privacyconfigs = $DB->get_records_sql($query, array('typeid' => $toolid));
             foreach($privacyconfigs as $config){
                 $configname = $config->name;
                 $response->$configname = $config->value;