I am using laminas to build a project: a discourse kind system.
Our PM propose a function that publish a kind of topic(not all topic, just some choosen ones), when users reply to these topics, they may win a prize (a game activation code, etc) by chance.
To me, I want it to be decoupled to the main disourse logic. It should be a plugin-kind function.
It not break into the existing logic. And can be extented more such kind functions, and can be removed easily.
When a reply won the prize, this layer I mean this reply will have a special mark. Others will see the mark and take part in this topic.
I am considering where is the best entrance to place such extral function logic. registering some customed events like after_replied, or do these at the end of each controller action.
Any advises will be very much appreciated. Thank you!
I don’t know where to place the following code, in the Module.php?(I only found attach method in the onBootstrap() of Module.php file)
$events->attach('do', function ($e) {});
the PM said that, we may hold different activities(promotions) onside a topic. I am planning to write different classes for different promotion logics. each class encapsulate a concrete promotion logic. this way will provide flexibility to me. I can write anything inside the class.
My question is that how to involve the promotion class(as well as promotion class instance) in/with the event stuff?
how to trigger the event after comment done. in another saying, where to place the trigger related code
$events->trigger('do', null, $params);
should I put it inside the CommentTable’s save() method?
You said it should decoupled with controller and action. inside the comment model you suggested. But I don’t know how. I am still looking forward to your example.