Data exposed to Blocks?

Data exposed to Blocks?

by Brandon Quinn -
Number of replies: 3
I want to create a block which serves content based on who is viewing it. How can I tell what user is accessing it? Also, can I query/ write to my User table from a block?

I haven't found any documentation that describes the external data I can access from a block.

Thanks!
Average of ratings: -
In reply to Brandon Quinn

Re: Data exposed to Blocks?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
It should work to vary the block contents based on global $USER, which holds information about the currently logged-in user.
In reply to Tim Hunt

Re: Data exposed to Blocks?

by Brandon Quinn -
Thanks, Tim. Where can I find the class definition for $USER, and information about the other globals?
In reply to Brandon Quinn

Re: Data exposed to Blocks?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Just do

print_object($USER);

somewhere in your code, and see what you have got.

$USER is basically get_record('user', 'id', {current user id});

but with some extra bits. It is initialised in require_login, if I remember correctly.