Merge branch 'MDL-61651_master' of git://github.com/markn86/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 24 Apr 2018 00:45:30 +0000 (08:45 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 24 Apr 2018 00:45:30 +0000 (08:45 +0800)
mod/lti/amd/build/contentitem.min.js
mod/lti/amd/src/contentitem.js
mod/lti/locallib.php
mod/lti/mod_form.js

index 0312415..c381e2f 100644 (file)
Binary files a/mod/lti/amd/build/contentitem.min.js and b/mod/lti/amd/build/contentitem.min.js differ
index a6dad92..f9995e4 100644 (file)
@@ -38,6 +38,7 @@ define(
     ],
     function($, notification, str, templates, FormField, ModalFactory, ModalEvents) {
         var dialogue;
+        var doneCallback;
         var contentItem = {
             /**
              * Init function.
@@ -45,7 +46,8 @@ define(
              * @param {string} url The URL for the content item selection.
              * @param {object} postData The data to be sent for the content item selection request.
              */
-            init: function(url, postData) {
+            init: function(url, postData, cb) {
+                doneCallback = cb;
                 var context = {
                     url: url,
                     postData: postData
@@ -100,7 +102,9 @@ define(
             new FormField('instructorcustomparameters', FormField.TYPES.TEXT, true, ''),
             new FormField('icon', FormField.TYPES.TEXT, true, ''),
             new FormField('secureicon', FormField.TYPES.TEXT, true, ''),
-            new FormField('launchcontainer', FormField.TYPES.SELECT, true, 0)
+            new FormField('launchcontainer', FormField.TYPES.SELECT, true, 0),
+            new FormField('grade_modgrade_point', FormField.TYPES.TEXT, false, ''),
+            new FormField('cmidnumber', FormField.TYPES.TEXT, true, '')
         ];
 
         /**
@@ -123,6 +127,10 @@ define(
                 }
                 field.setFieldValue(value);
             }
+
+            if (doneCallback) {
+                doneCallback();
+            }
         };
 
         return contentItem;
index 8074fd9..7ff4363 100644 (file)
@@ -921,9 +921,35 @@ function lti_tool_configuration_from_content_item($typeid, $messagetype, $ltiver
         } else {
             $config->typeid = $typeid;
         }
+        $config->instructorchoiceacceptgrades = LTI_SETTING_NEVER;
+        if (!$islti2 && isset($typeconfig['acceptgrades'])) {
+            $acceptgrades = $typeconfig['acceptgrades'];
+            if ($acceptgrades == LTI_SETTING_ALWAYS) {
+                // We create a line item regardless if the definition contains one or not.
+                $config->instructorchoiceacceptgrades = LTI_SETTING_ALWAYS;
+            }
+            if ($acceptgrades == LTI_SETTING_DELEGATE || $acceptgrades == LTI_SETTING_ALWAYS) {
+                if (isset($item->lineItem)) {
+                    $lineitem = $item->lineItem;
+                    $config->instructorchoiceacceptgrades = LTI_SETTING_ALWAYS;
+                    $maxscore = 100;
+                    if (isset($lineitem->scoreConstraints)) {
+                        $sc = $lineitem->scoreConstraints;
+                        if (isset($sc->totalMaximum)) {
+                            $maxscore = $sc->totalMaximum;
+                        } else if (isset($sc->normalMaximum)) {
+                            $maxscore = $sc->normalMaximum;
+                        }
+                    }
+                    $config->grade_modgrade_point = $maxscore;
+                    if (isset($lineitem->assignedActivity) && isset($lineitem->assignedActivity->activityId)) {
+                        $config->cmidnumber = $lineitem->assignedActivity->activityId;
+                    }
+                }
+            }
+        }
         $config->instructorchoicesendname = LTI_SETTING_NEVER;
         $config->instructorchoicesendemailaddr = LTI_SETTING_NEVER;
-        $config->instructorchoiceacceptgrades = LTI_SETTING_NEVER;
         $config->launchcontainer = LTI_LAUNCH_CONTAINER_DEFAULT;
         if (isset($item->placementAdvice->presentationDocumentTarget)) {
             if ($item->placementAdvice->presentationDocumentTarget === 'window') {
@@ -941,6 +967,7 @@ function lti_tool_configuration_from_content_item($typeid, $messagetype, $ltiver
             }
             $config->instructorcustomparameters = implode("\n", $customparameters);
         }
+        $config->contentitemjson = json_encode($item);
     }
     return $config;
 }
index d158cd3..f341ccc 100644 (file)
@@ -90,7 +90,9 @@
                     };
 
                     require(['mod_lti/contentitem'], function(contentitem) {
-                        contentitem.init(contentItemUrl, postData);
+                        contentitem.init(contentItemUrl, postData, function() {
+                            M.mod_lti.editor.toggleGradeSection();
+                        });
                     });
                 }
             });