Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Feb 25 2019 17:22
    EOM opened #35
  • Dec 20 2018 22:58
    JeanValJeann opened #34
  • Oct 07 2018 15:03
    Devin0231577 commented #31
  • Oct 07 2018 14:15
    rafi01010010 commented #31
  • Sep 18 2018 03:50
    tgoeminne opened #33
  • Sep 16 2018 15:04
    emiliano-idata opened #32
  • Jun 18 2018 03:05
    Devin0231577 opened #31
  • Jun 13 2018 14:38
    zakblacki edited #30
  • Jun 13 2018 14:38
    zakblacki opened #30
  • May 23 2018 11:53
    LubosRemplik commented #29
  • Mar 02 2018 13:11
    codecov-io commented #29
  • Mar 02 2018 13:10
    codecov-io commented #29
  • Mar 02 2018 13:09
    codecov-io commented #29
  • Mar 02 2018 13:08
    codecov-io commented #29
  • Mar 02 2018 13:07
    codecov-io commented #29
  • Mar 02 2018 13:07
    codecov-io commented #29
  • Mar 02 2018 13:07
    LubosRemplik commented #29
  • Mar 02 2018 13:06
    codecov-io commented #29
  • Mar 02 2018 13:06
    codecov-io commented #29
  • Mar 02 2018 12:44
    codecov-io commented #29
Justin Atack
@justinatack
I can't work out how you output the notification "message" title/body. The "notifications" var in the view just contains a JSON string and no template title/body. Is there a view function that outputs the vars and template as a string?
Justin Atack
@justinatack

Array
(
[0] => Notifier\Model\Entity\Notification Object
(
[id] => 3
[template] => newUser
[vars] => {"loggedin_user":"Justin DEDACTED","new_user":"Rex DEDACTED"}
[user_id] => 1
[state] => 1
[created] => Cake\I18n\Time Object
(
[time] => 2016-01-05T05:09:38+0000
[timezone] => UTC
[fixedNowTime] =>
)

        [modified] => Cake\I18n\Time Object
            (
                [time] => 2016-01-05T05:09:38+0000
                [timezone] => UTC
                [fixedNowTime] => 
            )

        [tracking_id] => YIjHeLBdam
        [[new]] => 
        [[accessible]] => Array
            (
                [template] => 1
                [vars] => 1
                [tracking_id] => 1
                [user_id] => 1
            )

        [[dirty]] => Array
            (
            )

        [[original]] => Array
            (
            )

        [[virtual]] => Array
            (
                [0] => title
                [1] => body
                [2] => unread
                [3] => read
            )

        [[errors]] => Array
            (
            )

        [[repository]] => Notifier.Notifications
    )

}

This is the notifications array output in my view. Where is the template title/body?
Bob Mulder
@bobmulder
Hi man. I am trying to get some sleep but a short reply: The entity you are getting back has the virtual fields title and body. As well you cam try to convert the entity to an array with toArray(). Get that?
Bob Mulder
@bobmulder
Let me know ;) I see you struggle a lot with this so we should think about improving the docs I guess...
Justin Atack
@justinatack
Sorry to disturb your sleep. My code can wait. I guess a code example of how to handle things in the view would be great. I'm not sure what you mean by toArray(). Better docs are always a good thing :) stops peple like me hassling you. If I get this worked out I'm more than happy to contribute back to your docs on GitHub from a noob perspective.
Bob Mulder
@bobmulder

@justinatack as you can see here (https://github.com/cakemanager/cakephp-notifier/blob/master/src/Model/Entity/Notification.php#L77-L121) the notification-entity contains the virual fields. So, to get the title you use $notification->title.

The notifier plugin works with templates, and I think I didn't explain that clear enough in the docs. Templates are NOT the same as templates in CakePHP itself. You can register templates inside your config/bootstrap.php for example:

$notificationManager->addTemplate('newBlog', [
    'title' => 'New blog by :username',
    'body' => ':username has posted a new blog named :name'
]);

(templates are stored in the Configure-class of Cake)

You can 'use' this template when you create a notification:

$notificationManager->notify([
    'users' => [1,2],
    'recipientLists' => ['administrators'],
    'template' => 'newBlog', // <--------------- HERE YOU GO
    'vars' => [
        'username' => 'Bob Mulder',
        'name' => 'My great new blogpost'
    ]
]);

Docs: https://github.com/cakemanager/cakephp-notifier#templates

I hope this made sense, else let me know ;)

iamsaloc
@cruamps
Hi.
Is there a way to use Notifier with localized templates (title / body) ?
Some recipients are English and others are French or German.
Bob Mulder
@bobmulder
Hi @cruamps, good question! The plugin does not provide because I've never needed it ;P
Maybe you can work on a PR? :)
iamsaloc
@cruamps
I'll think about it ;)
Bob Mulder
@bobmulder
Great ;) You could add a column to the table to keep the lanuages if needed...
AKKAWEB
@akkaweb
Hello! Kudos for a great plugin! I just started using it yesterday and I've got excited about it. :) . I have a question, which might be more CakePHP than your plugin, but I am hoping you will help me figure it out. I would like to detect a save that is performed by a Plugin and add a notification for it. The concrete example is a simple Feedback Plugin I created (https://github.com/akkaweb/AKKA-CakePHP-Feedback-Plugin) and I would like to detect when it saves the feedback without actually making a change to the plugin itself. Is that possible? If so, how can I accomplish it? Thanks !
Bob Mulder
@bobmulder
Hey @akkaweb, thanks for your kudos :)
I am afraid this can't be done without any changes. The good news is that the change can be very simple. Have you ever heard of cake's events?
AKKAWEB
@akkaweb
Hey @bobmulder , thanks for the reply. I am aware of Cake Events but have not used it yet to comfortably know what to do. What do you suggest?
Bob Mulder
@bobmulder
I will send you a code sample as soon as possible @akkaweb
Bob Mulder
@bobmulder

@akkaweb This is an example how to work with events to make your plugin work with the notifier.

First of all: read more about events here: http://book.cakephp.org/3.0/en/core-libraries/events.html

This example shows you what to do in your model. Lets call your event in your case 'Model.Feedback.afterSave'. This is the only change you should do at the side of your plugin. Whats done now, is that when a feedback item has been sent, the event is called.

So what we got to do now is use the event to notify.

For that we need a listener. If you see that example, it should be clear enough you have to catch your event, and use the Notifier...

AKKAWEB
@akkaweb
@bobmulder thank you for that. I will try and implement that within my plugin. I will post back with how successful I get with it. In true, I had read about events in the book several times, but I always left with some confusion. But I think now, I understand the separation between the event itself and listeners. Thanks for that!
AKKAWEB
@akkaweb
@bobmulder Because I wanted to attach notifications to other plugins that are not in my control and I could not change their code, I researched a little more and I found the following solution
Because CakePHP already has an afterSaveevent that is fired by the Model, all I had to do was create src/Event/FeedbackListener.php and look into the Fired Model Event for the Feedback Save Event
Bob Mulder
@bobmulder
Did you manage to do that @akkaweb? I doubt because the afterSave event has been fired only to that class, right?
AKKAWEB
@akkaweb
Here is the code that I used in my FeedbackListener.php
This message was deleted
Bob Mulder
@bobmulder
Haha please, use markdown :P
AKKAWEB
@akkaweb
Ok... let me try
<?php

namespace App\Event;

use Cake\Event\EventListenerInterface;
use Notifier\Utility\NotificationManager;

class FeedbackListener implements EventListenerInterface {

  public function implementedEvents() {
    return [
        'Model.afterSave' => 'addFeedbackNotification',
    ];
  }

  public function addFeedbackNotification($event, $entity) {
    if ($entity->source() == 'AkkaFeedback.Feedbacks' && $entity->isNew()) {
      // Add notification
      $notificationManager = NotificationManager::instance();
      $notificationManager->addTemplate('newMessage', [
          'title' => 'New Message Notification',
          'body' => 'New message from :name'
      ]);
      $notificationManager->addRecipientList('administrators', [7]);
      $notificationManager->notify([
          'recipientLists' => ['administrators'],
          'template' => 'newMessage',
          'vars' => [
              'id' => $entity->get('id'),
              'name' => $entity->get('name'),
              'feedback' => $entity->get('feedback')
          ]
      ]);
    }
  }
}
Plus I added this to bootstrap.php
/**
 * Event listeners
 */
use App\Event\FeedbackListener;
use Cake\Event\EventManager;

$feedackListener = new FeedbackListener();
EventManager::instance()->attach($feedackListener);
Bob Mulder
@bobmulder
Yeah, in fact this should work. However, using this code will be very expensive, because you listen to the event Model.afterSave. So, on every model's safe you'll fire this event (thats why you used if/else). So to improve your code I would suggest creating a new event into your afterSave-method in your model (in the plugin), and listen on that event. The bootstrap looks good!
AKKAWEB
@akkaweb
I will definitely add afterSave to my plugin to make it easy to track its save events. The reason I went this route is because I use a plugin from another developer that does not fire any specific events and I wanted a notification on new creation as well. But all good for now, thanks for the help!
Bob Mulder
@bobmulder
No problem! Good luck and let me know if you need help!

Oh, to improve your code, I would move

$notificationManager->addTemplate('newMessage', [
          'title' => 'New Message Notification',
          'body' => 'New message from :name'
      ]);

to your bootstrap.php. Else the templates can't be read when showing them...

AKKAWEB
@akkaweb
Much better! Thanks a lot! I also moved
$notificationManager->addRecipientList('administrators', [7]);
as I will be using administrators in a bunch of other places. Code look much more cleaner!
Bob Mulder
@bobmulder
Nice! Thats what it's meant to. I understand it wasn't clear enough in the docs?
AKKAWEB
@akkaweb
Well! The doc was not as specific as you have put it to me now. Now it makes way more sense. I think it would help other users of your plugin if you can make this suggestion there...
Just to add, everything else though is very clear on your doc and easy to follow..
AKKAWEB
@akkaweb
@bobmulder Perhaps on your next release. It would be nice to have an option within getNotifications() that would limit the amount of notifications to return. Like latest 4 notifications.
Bob Mulder
@bobmulder
Great idea @akkaweb, as well, feel free to do a PR ;) Don't have that much time for this plugin...
AKKAWEB
@akkaweb
@bobmulder Will do! Thanks!
AKKAWEB
@akkaweb
@bobmulder FYI! I did a PR for the LIMIT change. Once you get a chance to review, please let me know if you have any questions.
Bob Mulder
@bobmulder
@akkaweb Thank you! I've added a comment to #8
AKKAWEB
@akkaweb
@bobmulder Thanks for the constructive comments. I have made suggested changes and updated submitted code.
designskiller
@designskiller
hi
How to install notifier without using composer
Bob Mulder
@bobmulder
Why should you want that @designskiller?
designskiller
@designskiller
because if i do that with composer others will be updated too
Am using an existing project.