General developer forum

Execute some logic before and after quiz attempt

 
Picture of Dnyaneshwar K
Execute some logic before and after quiz attempt
 

Hi,
I am using  "\mod_quiz\event\attempt_started"  Event observers but i am not getting any result,php error messages or logs.

I am creating own local plugin for leaderboard functionality but I am stuck in  Event observers call.

My folder structure is.

- local/leaderboard

     - locallib.php

     - version.php

     - db

             -- events.php

In events.php file

$observers = array(
   array(
        'eventname' => '\mod_quiz\event\attempt_started',
        'includefile'=> '/local/leaderboard/locallib.php',
        'callback' => 'quiz_attempt_started',
        'internal' => 1
    ),

 array(
        'eventname' => '\mod_quiz\event\attempt_submitted',
        'includefile' => '/local/leaderboard/locallib.php',
        'callback' => 'quiz_submitted_start'
       
    ),

);

In locallib.php

function quiz_attempt_started($event) {

     file_put_contents('/local/leaderboard/log.txt', $event);

     //Logic Here

}

function quiz_submitted_start($event) {

  file_put_contents('/local/leaderboard/log.txt', $event);

  // Logic Here

}

Here noting to get error or result.Am I forgetting or doing something wrong here? 

 
Average of ratings: -
Picture of Hittesh Ahuja
Re: Execute some logic before and after quiz attempt
Plugin developersTesters

Can you see the event observer in the events list in Moodle . Its located here moodle/report/eventlist/index.php ? If not then mayvbe try purging your caches or bump up the plugin version

 
Average of ratings: -