Event and logging

Event and logging

by freddie valdez -
Number of replies: 2

Hi, im trying to add an event to the logging report provided by moodle in site admin.

As i understand this has to be done by triggering an event. So triggering an event = event registers in logs? 

I'm unsure if im doing this correctly since nothing is being added to the logs.

I went trough some plugins i had installed and noticed they didnt use observers for their events.

For testing purposes im trying to trigger the event once a course is viewed.

Currently i have this file structure

  • plugin
    •  index.php
    • classes
      • event
        • plugin_viewed.php
    • (other_files)
My index.php has the following relevant lines

$context = context_system::instance();
$event = \plugin\event\plugin_viewed::create(array('login' => $Login));
$event->trigger();
My plugin_viewed.php file has the following

<?php

namespace plugin\event;
defined('MOODLE_INTERNAL') || die();
class plugin_viewed extends \core\event\course_viewed {

/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->login' viewed plugin" ;
}
/**.
/**"course module id '$this->contextinstanceid'.";
}

/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
}

}




Average of ratings: -
In reply to freddie valdez

Re: Event and logging

by Dominique Palumbo -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Hi,

I think it miss this command before triggering.

$event->add_record_snapshot($tablename, $record);

can be

$event->add_record_snapshot('course', $course);

If you look in Moodle code for  add_record_snapshot you'll find another usefull sample
$event->add_record_snapshot('user', $user);
$event->add_record_snapshot('course_modules', $cm);
...

Hope it's help.

Dominique.

In reply to Dominique Palumbo

Re: Event and logging

by freddie valdez -
it shouldn't need snapshot since that has to do more with auxiliary information.

Nevertheless what i found out was the directory of the plugin i was using was the wrong one for the plugin and once i fixed that and added observers i managed to fix it and record the event in the logs.
Average of ratings: Useful (1)