how can h5p get the moodle's userid ,username?

my moodle has a h5p plugin . In my h5p,I make something for diffrent user, and need to know the user id ,user name which belongs to the moodle.

for example, in h5p , how to show "hello username"  (username here is moodle username)

0
0
Supporter votes Members of the Supporter Network can vote for feature requests. When the supporter network has generated sufficient funding for the top voted feature request it will normally be implemented and released. More about the H5P Supporter Network
otacke's picture

Hi!

H5P integrations and the H5P core do not pass this information to content types.

You could query the `window.H5PIntegration` object for a `user` object property that, if present (a user is logged in), will hold some information, BUT `H5P.Integration` should not be queried from content types, as it's not a clearly specified and may change without warning AND because different H5P integrations may not use the same variable names, so your content type might work on moodle but not on WordPress or Drupal or somewhere else. That's against a fundamental idea of H5P content types, so I cleary discourage you from doing this or at least urge you to have fallback solutions in place, e.g. a neutral welcome if no proper variable is found.

Best,
Oliver

add a line in the plugin code:

h5p/classes/play.php
public function add_assets_to_page() {

$contentsettings['metadata']['userid']=$USER->id;

 

otacke's picture

I can't add anything, I am not a member of H5P Group.

But I can tell you a) that I don't see what you'd gain beyond what I just outlined and b) that a solution that would only work if a content type is run on some particular H5P integration is not viable.

papi Jo's picture

If you just want to display in Moodle the current user (student)'s user name, or real first and last names, you could use the Moodle Generico filter plugin which features a Welcome user Template. In the example below I have put the Generico filter Welcome user Template in the Description field of my H5P content. I have attached 2 screenshots for 2 different users logged in to my Moodle site.

Hope that helps.