quick access to moodle environment variables

quick access to moodle environment variables

by Chris Tebb -
Number of replies: 5
Hi smile

I am beginning to code my groupware module for moodle, and I have been going through the code trying to find out how to obtain information about the current course, user, instance of my module etc.

I have got as far as:-

course->id = ID of course user is in
groupware->id = ID of Instance of my module user is in

But I require some other information like the ID of the current user etc...

Is there a particular file I should be looking in for this information? I have looked in moodle, datalib etc, but cannot find the right information.

I am presuming there are some class files that I can look through to find out the
data the classes store? There seems to be an instance of a course and groupware class I can read information from, is there also an instance of the user class for the current user?

Many thanks,

Chris.
Average of ratings: -
In reply to Chris Tebb

Re: quick access to moodle environment variables

by Chris Tebb -
Update smile I found the user object, it was USER, capitalised smile

I got this from line 23 of the index.php file for the main site:-

if (empty($USER->id))

Any guidance about where to find these things without hunting through code would be fantastic.

Many thanks,
chris.
In reply to Chris Tebb

Re: quick access to moodle environment variables

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
The coding guidelines will be helpful to you I think. smile

There are four global environment objects:  $CFG, $SESSION, $THEME and $USER
In reply to Martin Dougiamas

Re: quick access to moodle environment variables

by Chris Tebb -
Thanks Martin. I was following these, but these globals were presented as something not to extend, not something people should use. Though as a PHP programmer, I should I suppose have simply seen these and print_r'd them to find out more.

Aside from the wiki, where is the best place I can contribute more developer documentation to? or is this wiki the right place? it seems to be infrequently updated, so I wondered if some other document repository has superceeded it?

Many thanks,

Chris.
In reply to Chris Tebb

Re: quick access to moodle environment variables

by W Page -
Please keep asking questions Chris.  Although I have not posted before, I am learning a lot watching this thread and the other threads about your project.

WP1
In reply to W Page

Re: quick access to moodle environment variables

by Chris Tebb -
Are you developing a new module as well? I've found it difficult to get into, but now have most of the answers I need I think. I will produce some developer docs to further help new module developers soon.

If you think I can answer any questions to you, as someone who has now suceeded in creating a basic module, please post, and I'll reply.

Many thanks,

Chris.