adlnet / Moodle-mod_cmi5launch

A Moodle plugin which allows teachers to upload cmi5 packaged lessons within a Moodle Course Activity and then assign the activity to students
Apache License 2.0
5 stars 4 forks source link

Error when test is submitted #12

Closed ADLMeganBohland closed 1 year ago

ADLMeganBohland commented 1 year ago

A new course was created, and works fine until the test is taken and submitted. Then it is unable to retrieve the information from the LRS. I traced the error and believe this is caused by it being unable to find a 'name' value in the results. It is supposed to parse the returned statements and display progress. The statements are returned as json and converted to array. It is the name field in array it cannot find. I am currently investigating.

image

ADLMeganBohland commented 1 year ago

The problem appears to be that the "object" can appear in different parts of the statements. The program cannot find it when it is not where it expects. This is a statement that causes no problem: { "2a90a6d8-8056-4cc4-b142-5a94092d534b": [ { "id": "6fc9b57b-0730-420f-bd4f-13c25f85ff7e", "timestamp": "2023-08-17T18:26:38.748Z", "actor": { "account": { "homePage": "https://moodle.com", "name": "admin" }, "objectType": "Agent" }, "verb": { "id": "http://adlnet.gov/expapi/verbs/answered" }, "object": { "objectType": "Activity", "id": "https://w3id.org/xapi/cmi5/catapult/player/course/700b8d8b-9b58-4800-a13b-26dff4a27106/au/0/test/quiz1/question/q0", "definition": { "type": "http://adlnet.gov/expapi/activities/cmi.interaction", "interactionType": "fill-in", "name": { "en-US": "How many major types of rock are there?" }, "correctResponsesPattern": [ "3" ] } }, "context": { "contextActivities": { "grouping": [ { "id": "https://w3id.org/xapi/cmi5/catapult/lts/course/geology-intro-single-au-mastery-score-responsive/1", "objectType": "Activity" } ], "other": [ { "id": "http://id.tincanapi.com/activity/software/@rusticisoftware/cmi5/3.1.0", "definition": { "name": { "und": "@rusticisoftware/cmi5 (3.1.0)" }, "description": { "en": "A JavaScript library implementing the cmi5 specification for AUs during runtime." }, "type": "http://id.tincanapi.com/activitytype/source" }, "objectType": "Activity" } ] }, "extensions": { "https://w3id.org/xapi/cmi5/context/extensions/sessionid": "81f03df2-6704-4459-bef5-db8ec268583f" }, "registration": "2a90a6d8-8056-4cc4-b142-5a94092d534b" }, "result": { "response": "3", "success": true }, "stored": "2023-08-17T18:26:40.074Z", "authority": { "objectType": "Agent", "name": "New Client", "mbox": "mailto:dev@adlnet.gov" }, "version": "1.0.0" } ] }

And this is an example statement causing the issue: { "2a90a6d8-8056-4cc4-b142-5a94092d534b": [ { "actor": { "account": { "name": "admin", "homePage": "https://moodle.com" }, "objectType": "Agent" }, "verb": { "id": "https://w3id.org/xapi/adl/verbs/satisfied", "display": { "en": "satisfied" } }, "context": { "registration": "2a90a6d8-8056-4cc4-b142-5a94092d534b", "contextActivities": { "category": [ { "id": "https://w3id.org/xapi/cmi5/context/categories/cmi5", "objectType": "Activity" } ], "grouping": [ { "id": "https://w3id.org/xapi/cmi5/catapult/lts/course/geology-intro-single-au-mastery-score-responsive", "objectType": "Activity" } ] }, "extensions": { "https://w3id.org/xapi/cmi5/context/extensions/sessionid": "81f03df2-6704-4459-bef5-db8ec268583f" } }, "id": "23b94ff7-f6d9-4589-8372-c5eaa0a29b78", "timestamp": "2023-08-17T18:26:39.118Z", "object": { "id": "https://w3id.org/xapi/cmi5/catapult/player/course/700b8d8b-9b58-4800-a13b-26dff4a27106", "definition": { "type": "https://w3id.org/xapi/cmi5/activitytype/course" }, "objectType": "Activity" }, "stored": "2023-08-17T18:26:39.298Z", "authority": { "objectType": "Agent", "name": "New Client", "mbox": "mailto:dev@adlnet.gov" }, "version": "1.0.0" } ] }

I am investigating the best way to handle this scenario. Perhaps an if/else statement.

ADLMeganBohland commented 1 year ago

I believe by using array_key_exists, we can check where the object is, and if it can't be found, at least fail more gracefully. "Object" should always exist on the seond level of a statement (which is the third level once converted by php json_enocde. So by searching their we may be able to avoid the programs confusion. I have started implementing this fix.

ADLMeganBohland commented 1 year ago

I have applied a fix and installed the patch on the moodle.castle.adlnet.gov Moodle instance. I tested and it appears to have resolved the issue.