FMCorz / moodle-block_xp

A gamification plugin for Moodle allowing students to gain experience points and level up.
https://levelup.plus/?ref=github
149 stars 42 forks source link

Dynamic event data & rules #124

Closed KristofGit closed 3 years ago

KristofGit commented 3 years ago

Hello,

I checked out level up and it looks quite promising. While playing around a bit with its rule configuration feature I wondered if its possible to take also event content/data into account that can be defined dynamically while triggering the event. I was left with the impression that currently only the static event name, component, action, and target can be taken into account for rules.

But for our use case we likely would need some more flexibility. We plan to integrate multiple different data sources by creating a basic API that enables external data sources to "fire" a single custom event in Moodle which we enrich dynamically with some data supplied by the mentioned data sources. For example, would it be possible to take more dynamic event content into account? In the Moodle documentation I found a "other" property being mentioned (https://docs.moodle.org/dev/Events_API) that would likely fit our use case. Or is possible to take the results of a method call on the event object into account? Have I maybe overlooked something?

Thanks for your time

Kristof

FMCorz commented 3 years ago

Hi @KristofGit,

There are two things to consider here. 1/ Level up! observing the event, 2/ The event themselves.

At present, Level up! does not contain rules to observe additional properties of the event, they could be implemented however most users already find the Event property rule difficult to understand. And that's totally fair considering that it is very developer oriented.

Secondly, while you could create a generic event and give it data, or data structures, that change depending on what your business requirements are, this is not recommended. Moodle events are meant to be strict in their data format and should not broadly change. They should represent exactly what is going on, without the need to take a deep dive in the other properties to figure out what really did happen. Also, using a custom method to retrieve information implies that some database lookups may be performed, which is discouraged as an event should not expect that the information it contains still exist. Note that events may be repeated when restoring a backup, at which point they only represent a past action, and not a live one.

If you are looking to extend Level up!, the easiest would be to create new events, different from each other, of educational type PARTICIPATING which reside in a course module, so they will be picked up by Level up! automatically. Alternatively, you could directly award the points to users using code similar to this: https://gist.github.com/FMCorz/2e6d29c8dda5ec9d6d6c349d6b2e8528

I hope this was helpful.

Regards, Fred