Browse Source

LTI add substitution of variables - refs BT#13469

Angel Fernando Quiroz Campos 6 years ago
parent
commit
090bb3d1e7
2 changed files with 40 additions and 4 deletions
  1. 5 1
      plugin/ims_lti/Entity/ImsLtiTool.php
  2. 35 3
      plugin/ims_lti/form.php

+ 5 - 1
plugin/ims_lti/Entity/ImsLtiTool.php

@@ -284,7 +284,11 @@ class ImsLtiTool
         $strings = explode("\n", $this->customParams);
 
         foreach ($strings as $string) {
-            $pairs = explode('=', $string);
+            if (empty($string)) {
+                continue;
+            }
+
+            $pairs = explode('=', $string, 2);
             $key = self::parseCustomKey($pairs[0]);
             $value = $pairs[1];
 

+ 35 - 3
plugin/ims_lti/form.php

@@ -63,10 +63,10 @@ if ($tool->isActiveDeepLinking()) {
         $params['lis_result_sourcedid'] = $toolEval->getId().':'.$user->getId();
         $params['lis_outcome_service_url'] = api_get_path(WEB_PATH).'ims_lti/outcome_service/'.$tool->getId();
         $params['lis_person_sourcedid'] = "$platformDomain:$toolUserId";
-        $params['lis_course_offering_sourcedid'] = "$platformDomain:".$course->getId();
+        $params['lis_course_section_sourcedid'] = "$platformDomain:".$course->getId();
 
         if ($session) {
-            $params['lis_course_offering_sourcedid'] .= ':'.$session->getId();
+            $params['lis_course_section_sourcedid'] .= ':'.$session->getId();
         }
     }
 }
@@ -111,7 +111,39 @@ $params['tool_consumer_instance_url'] = api_get_path(WEB_PATH);
 $params['tool_consumer_instance_contact_email'] = api_get_setting('emailAdministrator');
 $params['oauth_callback'] = 'about:blank';
 
-$params += $tool->parseCustomParams();
+$customParams = $tool->parseCustomParams();
+$imsLtiPlugin->trimParams($customParams);
+
+$substitutables = ImsLti::getSubstitutableParams($user, $course, $session);
+$variables = array_keys($substitutables);
+
+foreach ($customParams as $customKey => $customValue) {
+    if (in_array($customValue, $variables)) {
+        $val = $substitutables[$customValue];
+
+        if (is_array($val)) {
+            $val = current($val);
+
+            if (array_key_exists($val, $params)) {
+                $customParams[$customKey] = $params[$val];
+
+                continue;
+            } else {
+                $val = false;
+            }
+        }
+
+        if (false === $val) {
+            $customParams[$customKey] = $customValue;
+
+            continue;
+        }
+
+        $customParams[$customKey] = $substitutables[$customValue];
+    }
+}
+
+$params += $customParams;
 
 $imsLtiPlugin->trimParams($params);