Is it possible to store/restore contentUserData from an LRS
Submitted by rkraemer on Mon, 08/22/2022 - 10:59
Forums:
What would be the approach to store and restore contentUserData from an LRS. It is actually straightforward to store the contentUserData to an xAPI State. However, re-populating the H5P content with contentUserData from the xAPI State does not seem to work. It appears that, even if the state in the H5PIntegration.contents array is in place with the restored contentUserData, the H5P content will not render the state. Any ideas? Please advise, thank you!
otacke
Mon, 08/22/2022 - 15:05
Permalink
Hi rkraemer!If you're talking
Hi rkraemer!
If you're talking about one of the existing H5P integrations (e.g. WordPress, Drupal, etc.), you just need to activate the respective setting in the plugin options.
If you're trying to create a custom solution, you'd not use the xAPI state (it does not contain the content type's state, merely the score and potentially some of the user inputs).
Content types that support this feature have a `getCurrentState` function that will return the state that needs to be stored. So, in order to retrieve the current state, you'd call that function on a content type instance (if it has that function) and store the return value.
When instantiating H5P content, there's the 3rd argument (often called `extras` in code) which is an object and can hold a `previousState` property. That's where the value that you have stored before (the return value of `getCurrentState`) needs to go.
Cheers,
Oliver
rkraemer
Wed, 08/24/2022 - 10:55
Permalink
Hi Oliver, I am working on a
Hi Oliver, I am working on a custom solution with a CMS and I have been using the 'getCurrentState' function to store the data temporarily in browser sessionStorage. With that I can restore 'previousState' and/or 'preloadedData' in H5P.getUserData in H5P.js.
Objects in H5P.instances, like
and in H5PIntegration.contents, like
seem to get properly restored.
However the H5P content, like Multiple-choice, will not display or render the previous state - what am I mising? Thank you
otacke
Wed, 08/24/2022 - 14:23
Permalink
Hi!Things that come to my
Hi!
Things that come to my mind - I don't know your implementation:
Best,
Oliver
rkraemer
Thu, 08/25/2022 - 07:32
Permalink
The CMS I am working on is
The CMS I am working on is Typo3 with the "H5p" Extension installed. It appears that the values are passed in time to the 'H5P.newRunnable' function as shown in my previous post. Also H5PIntegration.saveFreq is set to 30. Is there a particular "trigger" that invokes the rendering for the previous state that I am missing?
otacke
Thu, 08/25/2022 - 08:23
Permalink
Hello again!No, there's no
Hello again!
No, there's no other trigger required. You could check what of the values in H5PIntegration ends up in JavaScript in one of the content types that support restoring the previous state. That's where restoring is done based on the values that are passed by H5P.newRunnable (if there's a state set and `saveFreq` is not nullish, then the value would be passed, see https://github.com/h5p/h5p-php-library/blob/b9058680c386f0faed59eca44e5a618e8ace6218/js/h5p.js#L918-L920).
Maybe there's some encoding issue somewhere?
Best,
Oliver
rkraemer
Fri, 08/26/2022 - 07:37
Permalink
Hi Oliver,the issue was that
Hi Oliver,
the issue was that 'previousState' expects an object and not a string. Now that the previous state may be restored, I was wondering why the previuos state is not fully restored. For example, on a multiple-choice interaction, you would submit a selection of answers and then receive the feedback. When the state of the multiple choice is restored I would expect that the selected answers and the feedback will be displayed. However currently only the selected answers are displayed without the feedback. Is that by design?
Anyway, many thanks for the quick support!
Robert
otacke
Fri, 08/26/2022 - 22:48
Permalink
Hi Robert!I am not sure if
Hi Robert!
I am not sure if that's "by design" or rather "by omission", but yes. Most content types only re-create the answers but not what I call the "view state" (showing results, showing the solutions, possibly something else).
Best,
Oliver