how to save user data / current state

Forums: 

Hello my yet undefined saviour,

I am new to H5P and on the verge to create a new content type.

Experimenting with my test-package worked good so far but now I am in despair, trying to implement the functionality to save the content state to make it possible to return to the exercise later.

Please correct me at the following things:

  • I found setUserData() in the H5P API Reference. wich is used by the h5p-php-library ?
  • Using moodle I have to install the plugIn instead of using core to get the option 'Save content state' (so I did).
  • To actually save something, I have to implement: getCurrentState(), wich is called frequently if the 'save content state' is checked.
  • the getCurrentState-functionality has nothing to do with xAPI wich means so far I could totally ignore everything that has to do with xAPI.
  • To load the saved state, all I have to do is to insert a 3rd parameter to the constructor.

Am I supposed to do more than implementing the getCurrentState-function and (in case of moodle) use the plugIn instead of core, to make it work? (do I need to do something with Ajax for example)?

 

this.getCurrentState = () => {
	  return{
		  myContent: document.getElementById('myContent').value
	  };
  };

 

Thank you beforehand, every kind of help is much apreciated.

Greetings

Content types: 
otacke's picture

Hi anonymous developer!

H5P core will store the value that you pass as the return value of `getCurrentState`. That's fine. But how do you think should H5P core know what to do with that value in your content type?

"To load the saved state, all I have to do is to insert a 3rd parameter to the constructor." Not sure where you derived that from. The constructor's third argument contains the `previousState` that you gave H5P core. You can retrieve it and re-create the state as needed from it.

Cheers,
Oliver

p. s.: `document.getElementById('textBoxToSave')` - do you really want to query the DOM in order to access the element? That's slow and prone to error if code changes.

p. p. s.: There are coding style guidelines for H5P.

Hi and thank you for answering to my post :)

I am sorry for the misunderstanding, of course I have to somehow use the 'previousState' and do my things with it. I am not able to bring my code to run at the moment and I am not sure, if I maybe forgot something and wanted to find out, if I understood the functionality right.

With that "all I have to do...." I wanted to check if it realy is "that easy" theoretically.

Would I am asking to much if I beg you to look at my prototype (wich is approximately as small as the greetingCard example) to find out what I got wrong? As I am at my wits' end at the moment.

I know about the coding style guidelines, this is my quick and dirty test. Since it will be thrown away it doesn't matter for me yet. thank you for mentioning those things.

p.s. It is my luck that you personally answering on my post as I was thinking about asking you if there would be another twitch stream in the near future. :)

 

otacke's picture

Hey!

It is really not hard. Maybe this post is helpful for starters to understand how the feature is working: https://snordian.de/2023/03/04/how-does-resuming-an-exercise-work-in-h5p/

  • Have you checked that your `getCurrentState` function gets called? If not the feature may not have been activated in the plugin settings or non of the events that trigger saving have fired.
  • If your `getCurrentState` was called, what's the 3rd constructor argument holding? Have you checked that?

Best,

Oliver 

HI, thanks for the reply.

  • I made an alert into 'getCurrentState', it never appeared.
  • the 3rd constructor argument is an empty object for now (obviously).

The checkbox 'Save content state' is true, the 'Save content state frequency' is set to 10 (seconds) for testing purpose.

I inserted the 'Course presentation' example (v 1.24) with the Cloudberries-content to test if the state is saved if the functionality is implemented correctly but this doesn't work also.

I will try to set up a drupal environment now.

otacke's picture

First:

Since you are using moodle, make sure that you use the H5P activity (with the black H5P symbol) to insert H5P content to a course, not the content bank (the blue H5P symbol stuff). The latter is from moodle's custom H5P integration which does not feature support for resuming.

If you are using moodle, have you made sure that you're in development mode? Otherwise, if you want to upload libraries that have the same version number, these are ignored.

Best,
Oliver

Thank you so much!

Finally it works. :)

I've got your video about "blue and black, the difference something" open in another tab since three days or so and thought, I will watch it as far as I got the saveing to work, 'don't have the time for that yet'..... oh my... I thought it was something wrong with my code but actually I used the blue(core) version to insert the content into my course as you guessed. I didn't even saw the black one.

I will look out for the development mode. I already ran into this issue and incremented my buildnumber after every change.

I hope your forehead is fine after reading this post. :D

Thank you so much, I could finally start now.

otacke's picture

My head is fine :-) You're not the first person running into those issues. Developing will not require any host platform at all (hopefully) soon, so things like these should not be such a pain anymore.

Thank you again for your reply. And especially for the blog post. This will help future developers a lot!

Could you please be so kind and express this statement a little bit further:

"Developing will not require any host platform at all (hopefully) soon, so things like these should not be such a pain anymore."

And how can I participate in this, because developing new content types is really a pain for now.

otacke's picture

The H5P CLI tool is currently being turned upside down and will feature tools for developing. https://github.com/h5p/h5p-cli

otacke's picture

Hope this helps: https://snordian.de/2023/03/06/how-can-i-implement-support-for-resuming-in-an-h5p-content-type/

papi Jo's picture

Thanks for your 2 really helpful pages: https://snordian.de/2023/03/06/how-can-i-implement-support-for-resuming-... and https://snordian.de/2023/03/04/how-does-resuming-an-exercise-work-in-h5p/ Well-written, perfect (as always)...

As regards the Save content state feature in Moodle when using the core H5P activity (the blue icon), you are certainly aware that development has started to make this available. I closely follow (and test) this very much need feature development, and hopefully it will be available in the next version of Moodle (4.2) scheduled for 24 April 2023.

otacke's picture

Hi

Yes, I am aware of that process and I also mentioned that in the post (https://snordian.de/2023/03/04/how-does-resuming-an-exercise-work-in-h5p/#moodles_custom_H5P_integration_in_moodle_core).

Best,
Oliver