How to query out all information by a contextinstanceid?

How to query out all information by a contextinstanceid?

by wz z -
Number of replies: 3

In the event 2 API, there are "component" and "contextinstanceid" columns. But how can I query all information by this? For example, when an event of mod_assign\event\submission_graded triggered, I want to know the name of the assignment, the graded score of the submission and etc.

Average of ratings: -
In reply to wz z

Re: How to query out all information by a contextinstanceid?

by wz z -

I realy need help.

In reply to wz z

Re: How to query out all information by a contextinstanceid?

by Don Cooke -

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




In reply to Don Cooke

Re: How to query out all information by a contextinstanceid?

by wz z -
@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?