Trax Logs has a flexible architecture that you can extend in order to support new events. This may be usefull if you want to support Moodle events that are not already supported, or if you want to support events triggered by your own Moodle plugin.
Of course, you will need to be familiar with PHP coding, as well as understanding how to design xAPI Statements following best practices.
Once you have identified the events you want to handle, you can start implementing statement classes following this guide.
To support a new event, you have to implement a single class which inherits from the abstract class logstore_trax\src\statements\base_statement
. In this class, you must implement the statement()
function, which returns the statement to be sent to the LRS, given a Moodle event record which is stored in $this->event
.
Your implementation should use the following services:
$this->actors
, which generates actors given an actor type and a Moodle ID,$this->verbs
, which generates verbs given their code,$this->activities
, which generates activities given a module type and a Moodle ID.
For furthur details, you can look at the source code which is documented.
Your statement class must be correctly named in order to be detected by the plugin. The name is based on the name of the Moodle event. For example:
core\event\course_module_viewed
must be implemented by a class namedcourse_module_viewed
.mod_forum\event\course_module_viewed
must also be implemented by a class namedcourse_module_viewed
.core\event\user_loggedout
must be implemented by a class nameduser_loggedout
.
For Moodle native events, statement classes must be located in TRAX_PLUGIN/classes/src/statements/CORE_OR_PLUGIN_NAME/
.
For example:
core\event\course_module_viewed
must be implemented by a class located inTRAX_PLUGIN/classes/src/statements/core/
.mod_forum\event\course_module_viewed
may be implemented by a class located inTRAX_PLUGIN/classes/src/statements/mod_forum/
, or inTRAX_PLUGIN/classes/src/statements/core/
.
Regarding events coming from third-party plugins, statement classes must be located in THIRD_PARTY_PLUGIN/classes/xapi/statements/
.
The namespace of the statement class must be consistent with its location. For instance:
- If the class is located in
TRAX_PLUGIN/classes/src/statements/core/
, the namespace must belogstore_trax\src\statements\core
. - If the class is located in
TRAX_PLUGIN/classes/src/statements/mod_forum/
, the namespace must belogstore_trax\src\statements\mod_forum
. - If the class is located in
THIRD_PARTY_PLUGIN/classes/xapi/statements/
,the namespace must beTHIRD_PARTY_PLUGIN\xapi\statements
.
Activity classes are implemented in TRAX_PLUGIN/classes/src/activities
.
Regarding events coming from third-party plugins, you can implement custom activity classes in THIRD_PARTY_PLUGIN/classes/xapi/activities/
.