Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a behavior to send out auto notifications #23

Open
suhaboncukcu opened this issue Oct 19, 2016 · 7 comments
Open

Create a behavior to send out auto notifications #23

suhaboncukcu opened this issue Oct 19, 2016 · 7 comments

Comments

@suhaboncukcu
Copy link

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
Copy link
Contributor

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
Copy link
Author

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

@bobmulder
Copy link
Contributor

Would be kind of 'double' right? ;)

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

@suhaboncukcu
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

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

@bobmulder
Copy link
Contributor

👍 Looking forward to your suggestion! Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants