Creating local plugin - get event

Creating local plugin - get event

by Matt Checkerson -
Number of replies: 3

Hello dear community, I`m creating local plugin and want to do some action on event. Here is my code:

db/events.php

defined('MOODLE_INTERNAL') || die();

$observers = array(
    array(
        'eventname' => '*',
        'includefile' => '/local/workseed/lib.php',
        'callback' => 'all',
        'internal' => true
     ),
    array(
        'eventname' => '\mod_quiz\event\attempt_submitted',
        'includefile' => '/local/workseed/lib.php',
        'callback' => 'local_workseed_attempt_submitted',
        'internal' => false
     ),
    array(
        'eventname' => '\mod_quiz\event\attempt_started',
        'includefile' => '/local/workseed/lib.php',
        'callback' => 'local_workseed_attempt_started',
        'internal' => false
     )
);
lib.php:

defined('MOODLE_INTERNAL') || die();
require_once(dirname(dirname(__DIR__)) . '/config.php');


function all(* $event){
error_log($event)
}

function local_workseed_attempt_submitted(mod_quiz\event\attempt_submitted $event) {
    error_log('Attempt submit');
    return true;
}

function local_workseed_attempt_started(mod_quiz\event\attempt_started $event) {
    error_log('Attempt start');
    return true;
}

But when I start or finish quiz, functions in lib.php doesn`t work.

What I`m doing wrong? How I can fix it?

Thanks a lot for help

Average of ratings: -
In reply to Matt Checkerson

Re: Creating local plugin - get event

by Enrico Preti -

Have you increase the version number of the plugin after creating the db/events.php file to update it?

In reply to Enrico Preti

Re: Creating local plugin - get event

by Matt Checkerson -

thanks for help, but i had actually stupid error) I forgot <?php in the top of events.php. 

After added - code work fine.

In reply to Matt Checkerson

Re: Creating local plugin - get event

by santosh kumar -

Hi Matt,

can you share whole plugin file. Basically, I am working  similar plugin. but getting issue to implement my code.


Thanks,

Sant