General developer forum

How to query out all information by a contextinstanceid?

 
Picture of Don Cooke
Re: How to query out all information by a contextinstanceid?
 

Follow these steps :


1. Write an observer class for the event in your classes folder with a routine  for the event you want to catch

The class name and php file name need to be the same for the moodle class loader to work correctly.

eg.     public static final function handle_creation(\core\event\course_module_created $e) {


2. Create an events.php under the db folder for the component

eg. 

    array(
        'eventname'   => '\core\event\course_module_created',
        'callback'    => '<your component name>\<your observer class>::handle_creation',
        'internal'    => true,
    ),


3. Dump the $e object in your observer using

print_object($e);


Each event provides relevant data for the event type.

With this data you should be able to use the Moodle DB API and the moodle helper functions to do pretty much whatever you need to in response to the event.


It is possible to get info out of the DB using complex queries - this is a good reference to get you started.

https://docs.moodle.org/35/en/ad-hoc_contributed_reports    (include the correct version number of course)



Hope this helps

Don




 
Average of ratings: -
Picture of wz z
Re: How to query out all information by a contextinstanceid?
 
@Don, thank you for providing the ad-hoc SQL queries page, that's really what I want. The info retrieved with Event 2 API is very insufficient.  However, unfortunately, the only one SQL query containing contextinstanceid on that page is applicable to "Considering only several modules: url, resource, forum, quiz, questionnaire", it is not universal to all activities. I'm not familar with Moodle SQL schema, what should I then do?



 
Average of ratings: -