how can h5p get the moodle's userid ,username?
Submitted by LangKong on Sun, 12/03/2023 - 05:37
Forums:
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)
otacke
Mon, 12/04/2023 - 11:37
Permalink
Hi!H5P integrations and the
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
LangKong
Mon, 12/04/2023 - 11:55
Permalink
add a line in the plugin code
add a line in the plugin code:
h5p/classes/play.php
public function add_assets_to_page() {
$contentsettings['metadata']['userid']=$USER->id;
otacke
Mon, 12/04/2023 - 18:20
Permalink
I can't add anything, I am
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
Tue, 12/05/2023 - 18:24
Permalink
Hi LangKong
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.