General developer forum

Databases: contextlevel values?

 
Picture of Monica Franz
Databases: contextlevel values?
 
Hi!

We're using Moodle 1.9.3 and MySQL.

Which values can the contextlevel in mdl_context have and what do they mean?
Are there constants defined for the contextlevel, and can I use them in a query outside from the Moodle code?

Monica


 
Average of ratings: -
Frank Ralf
Re: Databases: contextlevel values?
Documentation writersPlugin developers
Hi Monica,

See Context for an introduction to the general concept and links to further information.

hth
Frank
 
Average of ratings: -
Picture of Monica Franz
Re: Databases: contextlevel values?
 
Hallo Frank!

Danke für die Antwort!

Now I'll change back to English:

The link you gave me was interesting. I found the constants of e.g. the CONTEXT_LEVEL in there (docs.moodle.org/en/Development:Roles#Context).
But no values?

In the mdl_context table the values I found were e.g.10, 40, 50.

I found a SELECT query in an earlier discussion for getting the students of a course.
In the WHERE clause they are using contextlevel=50 and roleid=5.

I'm trying to make a website out of our Moodle platform using the Moodle database.

I need the category list, the course list of a specific category and the list of students and there trainer in a specific course.

As the course-contextlevel seems to have the value 50, I need the value of the category-contextlevel.

I think it would be easier and better for maintance, if I could the "get_" functions and the constant definitions, etc.

Monica
 
Average of ratings: -
Frank Ralf
Re: Databases: contextlevel values?
Documentation writersPlugin developers
Hi Monica,

I collected some related links some time ago which might be useful for you: User:Frank_Ralf/Glossary_list2

Moodle's core library lib/datalib.php provides lots of functions for retrieving information from the database.

See also Developer FAQ.

Cheers,
Frank

 
Average of ratings: Useful (1)
Picture of Monica Franz
Re: Databases: contextlevel values?
 
Hi Frank!

Thanks again!

As I found out that the new website is supposed to work on a different server than our Moodle-platform is running, I need to implement own functions, so I still need the values of the constants. Just the connection to the Moodle database from the other server is possible.

Well I'll look up the core library. Your infos on your glossary helped me too.

Thanks again!

If I have more questions I'll keep on posting!

Gruß,

Monica
 
Average of ratings: -
Frank Ralf
Re: Databases: contextlevel values?
Documentation writersPlugin developers
Just an idea: You could write your own Moodle plug-in which collects all the relevant data and provides it to the external website (kind of a web service). You might have a look at this contributed module for inspiration: Integration: OKTech Web Services.

And for information on Moodle's database structure, Database FAQ is a good starting point.

Cheers/Tschüß
Frank



 
Average of ratings: Useful (1)
Picture of Monica Franz
Re: Databases: contextlevel values?
 
Hi Frank!

Was für ein Zufall!

Thats what I just discussed with my colleagues! So I'll write a script on the Moodle server which accesses the Moodle database using the "get_"functions . On the other server there runs the website and between both I'll have to make a "webinterface" to moodle.

In this way I wouldn't have to care about database changes in upgrades.

Well I'll continue reading the Module & Plugins stuff you sent and try if I can handle that!

Thanks!

Bis dann!

Monica


 
Average of ratings: -
Frank Ralf
Re: Databases: contextlevel values?
Documentation writersPlugin developers
Hi Monica,

Just two more links for inspiration:

Drupal modules for Moodle integration
http://drupalmodules.com/search/node/moodle+category%3A24

"Moodle Quick API for RESTful integration with other web applications, e.g. Drupal"
http://code.google.com/p/qapi/

hth
Frank



 
Average of ratings: Useful (1)
Picture of Monica Franz
Re: Databases: contextlevel values?
 
Hallo Frank!

That what drupal is doing I want to do as well. For the queries I would like to use the Moodle "get_" functions for maintainance reasons.

My new problem is that I don't now where to put my little php-file to as it's just our "local selfmade plugin" and how to test it. For quick-testing I don't want to start it in the Moodle-platform (e.g. HTML-Block).

I looked up the developer-docu, but for my little php-script it is like " mit Kanonen auf Spatzen schiessen". At the moment I just want to try things out as a very new "Moodle-developer".

Bis bald!

Monica



 
Average of ratings: -
Frank Ralf
Re: Databases: contextlevel values?
Documentation writersPlugin developers
Hallo Monica,

You will find some useful information in the Introduction to Moodle Programming course.

AFAIK you can put your PHP file in your Moodle directory and call it directly. You will have to make sure that you include or require all necessary Moodle libraries. See What happens when you require config.php? for details.

However I would recommend creating a very simple plug-in/block for that purpose so you can use Moodle's administration features for plug-ins. http://docs.moodle.org/en/Development:Blocks is a good introduction.

Cheers,
Frank
 
Average of ratings: Useful (1)
Picture of Monica Franz
Re: Databases: contextlevel values?
 
Hi Frank!

Thank you very much for your information!

Man sollte jemanden fragen, der sich damit auskennt!

I was looking around to find that information, but the point was: to find the right question/search.

Any way many thanks!

Till soon!

Monica
 
Average of ratings: -
Frank Ralf
Re: Databases: contextlevel values?
Documentation writersPlugin developers
JFTR

See Integration FAQ for further information.
 
Average of ratings: -
Picture of Monica Franz
Re: Databases: contextlevel values?
 
Just for information:

The constants for the context levels are described in moodle/lib/accesslib.php:

CONTEXT_SYSTEM = 10;
_USER = 30;
_COURSECAT = 40;
_COURSE = 50;
_MODULE = 70;
_BLOCK = 80;


 
Average of ratings: Useful (3)