lairaalmas il y a 1 an
Parent
commit
099545d69f
2 fichiers modifiés avec 52 ajouts et 12 suppressions
  1. 11 1
      js/globals/globals_functions.js
  2. 41 11
      js/moodle/integrationFunctions.js

+ 11 - 1
js/globals/globals_functions.js

@@ -154,7 +154,10 @@ const navigation = {
 const sendToDatabase = function (extraData) {
   // FOR MOODLE
   if (moodle) {
-    if (self.result) moodleVar.hits[curMapPosition - 1]++;
+    alert("i'm calling getAnswer again on sendToDatabase()");
+    console.clear();
+    console.log(self.control.isCorrect);
+    if (self.control.isCorrect) moodleVar.hits[curMapPosition - 1]++;
     else moodleVar.errors[curMapPosition - 1]++;
 
     moodleVar.time[curMapPosition - 1] += game.timer.elapsed;
@@ -169,6 +172,10 @@ const sendToDatabase = function (extraData) {
       '&iLM_PARAM_ArchiveContent=' +
       encodeURIComponent(report);
 
+    console.log(grade);
+    console.log(report);
+    console.log(moodleVar);
+
     const init = {
       method: 'POST',
       body: data,
@@ -202,6 +209,9 @@ const sendToDatabase = function (extraData) {
       langString +
       extraData;
 
+    console.log('----------------');
+    console.log(data);
+
     const url = 'php/save.php';
 
     const init = {

+ 41 - 11
js/moodle/integrationFunctions.js

@@ -38,6 +38,8 @@ function getParameterByName(name) {
 function getAnswer() {
   let str = '';
   if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
+    alert("(getAnswer) I'm a student sending results (getAnswer())");
+
     // Student - sending results
     str +=
       'gameName:' +
@@ -65,7 +67,10 @@ function getAnswer() {
         moodleVar.time[i] +
         '}';
     }
+    console.log(str);
   } else {
+    alert("(getAnswer) I'm a professor creating an assignment (getAnswer())");
+
     // Professor - creating new assignment
     if (!gameName) {
       alert(game.lang.error_must_select_game);
@@ -102,12 +107,27 @@ function getAnswer() {
  */
 function getEvaluation() {
   if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
+    alert(
+      "(getEvaluation) I'm a student getting an evaluation (getEvaluation())"
+    );
+
     // Student
     let i;
     for (i = 0; i < moodleVar.hits.length && moodleVar.hits[i] == 1; i++);
     const grade = i / 4;
-    parent.getEvaluationCallback(grade); // Sends grade to moodle db
+    // console.clear();
+    // console.log(grade);
+    try {
+      parent.getEvaluationCallback(grade); // Sends grade to moodle db
+    } catch (error) {
+      console.error('Game error: Could not send evaluation. ' + error);
+    }
+    console.log('done');
     return grade;
+  } else {
+    alert(
+      "(getEvaluation) I'm a professor getting an evaluation (getEvaluation())"
+    );
   }
 }
 
@@ -116,21 +136,30 @@ function getEvaluation() {
  * Holds the parameters passed by the iAssign to the iLM via URL.
  */
 const iLMparameters = {
-  /**
-   * This parameter gets the role in which the iLM is being used: <br>
-   * - if true, the user is creating a new iLM (as professor) <br>
-   * - if false, the user is solving the iLM (as student), value=false
-   */
-  iLM_PARAM_SendAnswer: getParameterByName('iLM_PARAM_SendAnswer'), // Checks if you're student (false) or professor (true)
-  /**
-   * This parameter is used when the user is opening an iLM to solve it. <br>
+  /** This parameter is used when the user is opening an iLM to solve it. <br>
    * It holds a URL with the path to the game file (assignment/iLM) created by the professor. <br>
    * Example: http://myschool.edu/moodle/mod/iassign/ilm_security.php?id=3&token=b3660dd4de0b0e9bb01fea6cc8f02ccd&view=1
    *
    * The first parameter, 'token', can be used only once.
-   * Once the iLM gets the game file, the token is destroied (for security).
-   */
+   * Once the iLM gets the game file, the token is destroied (for security).*/
+
+  // This parameter must receive from iAssign the URL of the iLM content
+  // Example: http://myschool.edu/moodle/mod/iassign/ilm_security.php?id=3&token=b3660dd4de0b0e9bb01fea6cc8f02ccd&view=1
+  // The first parameter, 'token', can be used only once, after sending its content to the iLM, iAssign will erase the file (avoiding "peeping")
   iLM_PARAM_Assignment: getParameterByName('iLM_PARAM_Assignment'),
+
+  /** This parameter gets the role in which the iLM is being used: <br>
+   * - if true, the user is creating a new iLM (as professor) <br>
+   * - if false, the user is solving the iLM (as student), value=false */
+
+  // iLM_PARAM_SendAnswer = true <=> iLM MUST NOT send any answer to the server
+  iLM_PARAM_SendAnswer: getParameterByName('iLM_PARAM_SendAnswer'), // Checks if you're student (false) or professor (true)
+
+  /**
+   * if iLM_PARAM_Authoring == true <=> iLM WILL be used by TEACHER to create a new exercise
+   */
+  iLM_PARAM_Authoring: getParameterByName('iLM_PARAM_Authoring'),
+
   /**
    * Gets current moodle language.
    */
@@ -138,6 +167,7 @@ const iLMparameters = {
   iLM_PARAM_ServerToGetAnswerURL: getParameterByName(
     'iLM_PARAM_ServerToGetAnswerURL'
   ),
+  iLM_PARAM_ArchiveContent: getParameterByName('iLM_PARAM_ArchiveContent'),
 };
 
 /**