Event observing does not appear to work

Event observing does not appear to work

by Michael Ko -
Number of replies: 4

Hi,

Running Moodle 2.8.1 and I am trying to create a local plugin that observers the quiz attempt submitted event. However, after following all instructions, it does not seem to work.

Next I tried to see if Moodle's standard event observers are working.

In mod/quiz/db/events.php there is:

array(
'eventname' => '\mod_quiz\event\attempt_submitted',
'includefile' => '/mod/quiz/locallib.php',
'callback' => 'quiz_attempt_submitted_handler',
'internal' => false
),
I modified function quiz_attempt_submitted_handler($event) and added to the start:

print_r($event);
error_log('Comes here'); die();
After attempting a quiz and submitting it, this code was not executed.

Does this mean that event observing is not working at all? And how can I go about resolving this?

Thank you in advance for any assistance.

Average of ratings: Useful (1)
In reply to Michael Ko

Re: Event observing does not appear to work

by Michael Ko -

I made a custom event and it was observed correctly.

It seems to be only the quiz attempt submitted event that is not being observed as required.

Average of ratings: Useful (1)
In reply to Michael Ko

Re: Event observing does not appear to work

by Michael Ko -
Issue resolved.

The quiz attempt submission event is only triggered if the quiz is not in preview mode. Testing it as an admin, I was in preview mode.

Average of ratings: Useful (2)
In reply to Michael Ko

Re: Event observing does not appear to work

by Christopher Mottes -

Thank you so much, Michael, you just saved me potentially hours or more! smile

Cheers,

Chris

In reply to Christopher Mottes

Re: Event observing does not appear to work

by Virgil Ashruf -

Additionally you can check the Event List report under Site Administration > Reports > Event List. You can then select your event and see what's observing it. You can also use that information to learn from the way other observers 'listen' to the event.