2017 © Pedro Peláez
 

cakephp-plugin cakephp-notifier

Oxenti fork from cakemanager Notifier plugin for CakePHP

image

oxenti/cakephp-notifier

Oxenti fork from cakemanager Notifier plugin for CakePHP

  • Friday, August 5, 2016
  • by oxenti
  • Repository
  • 4 Watchers
  • 0 Stars
  • 68 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 26 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Notifier plugin for CakePHP

Build Status Coverage Status Gitter, (*1)

Installation

You can install this plugin into your CakePHP application using composer., (*2)

The recommended way to install composer packages is:, (*3)

    composer require oxenti/cakephp-notifier:dev-master

Usage

Configurations

You will need to add the following line to your application's bootstrap.php file:, (*4)

Plugin::load('Notifier', ['bootstrap' => true, 'routes' => true]);

// or run the following command:
bin/cake plugin install -b -r Notifier

Note: You don't need to load the routes if you are not using the CakeManager Plugin., (*5)

After loading the plugin you need to migrate the tables for the plugin using:, (*6)

bin/cake migrations migrate -p Notifier

NotificationManager

The NotificationManager is the Manager of the plugin. You can get an instance with:, (*7)

NotificationManager::instance();

The NotificationManager has the following namespace: Notifier\Utility\NotificationManager., (*8)

NotifierComponent

The `NotifierComponent can be used in controllers to create notifications and return data like read/unread notifications and totals (like 4 unread notifications)., (*9)

Templates

Notifications are viewed in a template including variables. When sending a new notification, you tell the notification what template to use., (*10)

An example about how to add templates:, (*11)

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

When adding a new template, you have to add a title and a body. Both are able to contain variables like :username and :name. Later on we will tell more about these variables., (*12)

Removing a template is easy:, (*13)

$notificationManager->removeTemplate('newBlog');

Notify

Now we will be able to send a new notification using our newBlog template., (*14)

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

Note: You are also able to send notifications via the component: $this->Notifier->notify()., (*15)

With the notify method we sent a new notification. A list of all attributes:, (*16)

  • users - This is an integer or array filled with id's of users to notify. So, when you want to notify user 261 and 373, add [261, 373].
  • recipientLists - This is a string or array with lists of recipients. Further on you can find more about RecipientLists.
  • template - The template you added, for example newBlog.
  • vars - Variables to use. In the template newBlog we used the variables username and name. These variables can be defined here.

Lists

Of course you want to get a list of notifications per user. Here are some examples:, (*17)

// getting a list of all notifications of the current logged in user
$this->Notifier->getNotifications();

// getting a list of all notifications of the user with id 2
$this->Notifier->getNotifications(2);

// getting a list of all unread notifications
$this->Notifier->allNotificationList(2, true);

// getting a list of all read notifications
$this->Notifier->allNotificationList(2, false);

// getting a number of all notifications of the current logged in user
$this->Notifier->countNotifications();

// getting a number of all notifications of the user with id 2
$this->Notifier->countNotifications(2);

// getting a number of all unread notifications
$this->Notifier->countNotificationList(2, true);

// getting a number of all read notifications
$this->Notifier->countNotificationList(2, false);

You can do something like this to use the notification-list in your view:, (*18)

$this->set('notifications', $this->Notifier->getNotifications());

RecipientLists

To send notifications to large groups you are able to use RecipientLists. You can register them with:, (*19)

$notificationManager->addRecipientList('administrators', [1,2,3,4]);

Now we have created a list of recipients called administrators., (*20)

This can be used later on when we send a new notification:, (*21)

$notificationManager->notify([
    'recipientLists' => ['administrators'],
]);

Now, the users 1, 2, 3 and 4 will recieve a notification., (*22)

Model / Entity

The following getters can be used at your entity: - title - The generated title including the variables. - body - The generated body including the variables. - unread - Boolean if the notification is not read yet. - read - Boolean if the notification is read yet., (*23)

Example:, (*24)

// returns true or false
$entity->get('unread');

// returns the full output 'Bob Mulder has posted a new blog named My Great New Post'
$entity->get('body');

Keep in touch

If you need some help or got ideas for this plugin, feel free to chat at Gitter., (*25)

Pull Requests are always more than welcome!, (*26)

The Versions

05/08 2016

dev-master

9999999-dev

Oxenti fork from cakemanager Notifier plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

06/01 2016

dev-master-postgres-fix

dev-master-postgres-fix

Notifier plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

26/09 2015

1.0.0

1.0.0.0

Notifier plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires