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.
I realy need help.
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