Is it possible to store/restore contentUserData from an LRS

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's picture

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

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 

contentData:
   previousState: "{\"answers\":[2,4,3,0,1]}"
   standalone: true

and in H5PIntegration.contents, like

cid-12:
   contentUserData: 
     0: {state: '{"answers":[2,4,3,0,1]}'}

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's picture

Hi!

Things that come to my mind - I don't know your implementation:

  • Are you setting the values in H5PIntegration before they are passed to the content type instance?
  • Have you set `H5PIntegration.saveFreq`? H5P core requires this (some numerical value AFAIR) to restore previous states.

Best,
Oliver

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's picture

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 

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's picture

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