bakkerij / notifier

Notifications plugin for CakePHP 3.x
MIT License
59 stars 38 forks source link

Create a behavior to send out auto notifications #23

Open suhaboncukcu opened 7 years ago

suhaboncukcu commented 7 years ago

As you know keeping controllers clean and implementing the data related logic into model level is a better approach for CakePHP in a few different ways.

So, since the notifications are created with templates, I often find myself using variables from my entity just after saving it. For example; I want to notify all users when I add a new record to my posts. So I suggest thinking about something like below:

    $this->addBehavior('bakkerij/notifier.notifier', [
                'template' => 'someTemplateName',
                'keywords' => [
                    'keyword1' => 'columnNameOne',
                    'keyword2' => 'columnNameTwo',
                ],
                'to' => 'recipentListName?'
    ]);
bobmulder commented 7 years ago

Sorry for the delay @suhaboncukcu. What would be the sense of a behavior?

If you want to keep your controllers clean (I agree with that :)), you can still add your code to send notifications within events in your model right?

suhaboncukcu commented 7 years ago

As I can code my own notifications plugin :) I thought it would be something nice working out of the box.

bobmulder commented 7 years ago

Would be kind of 'double' right? ;)

Can you show me an example how it would work better in your situation? I am curious!

suhaboncukcu commented 7 years ago

I have a system that people joins to some channels and they get mails each time something added to their channels.

I installed the notifications plugin to set up internal notifications (or with adapters may be, to be able to send to different places).

After configuring the plugin, I should run the component each time I need a notification sent, which could be at different endpoints. So I really don't want to do that since we are working as several people on the project and it could lead some conflicts. So, I should create en event listener and fire an event to handle this notification sending which I would use the utility class since I'm on model level.

If I had a behavior instead; I could just call that behavior within my model class. I can -of course- create a behavior with the utility class. Only if I don't have a behavior class waiting ready for me. :)

bobmulder commented 7 years ago

I don't have a behavior class waiting for you unfortunately. Can you set up a PR? I think you're right that the behavior should use the Utility class heavily...

suhaboncukcu commented 7 years ago

surely, as soon as I have time. I will send a PR. Which I think would describe my case better as well.

bobmulder commented 7 years ago

:+1: Looking forward to your suggestion! Good luck!