Download the PHP package jeffersonsimaogoncalves/cakephp-notifier without Composer
On this page you can find all versions of the php package jeffersonsimaogoncalves/cakephp-notifier. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jeffersonsimaogoncalves/cakephp-notifier
More information about jeffersonsimaogoncalves/cakephp-notifier
Files in jeffersonsimaogoncalves/cakephp-notifier
Package cakephp-notifier
Short Description Notifier plugin for CakePHP
License MIT
Informations about the package cakephp-notifier
Notifier plugin for CakePHP
This plugin allows you to integrate a simple notification system into your application.
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install this plugin as composer package is:
Now load the plugin via the following command:
After loading the plugin you need to migrate the tables for the plugin using:
Sending notifications
Templates
Before sending any notification, we need to register a template. An example about how to add templates:
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.
Notify
Now we will be able to send a new notification using our newBlog
template.
Note: You are also able to send notifications via the component:
$this->Notifier->notify()
.
With the notify
method we sent a new notification. A list of all attributes:
users
- This is an integer or array filled with id's of users to notify. So, when you want to notify user c72da51b-16c8-4741-8646-2e45721b3277 and 7be18ce3-94e6-476a-870d-a0108d1697b7, add[c72da51b-16c8-4741-8646-2e45721b3277, 7be18ce3-94e6-476a-870d-a0108d1697b7]
.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 examplenewBlog
.vars
- Variables to use. In the templatenewBlog
we used the variablesusername
andname
. These variables can be defined here.
Recipient Lists
To send notifications to large groups you are able to use RecipientLists. You can register them with:
Now we have created a list of recipients called administrators
.
This can be used later on when we send a new notification:
Now, the users 7be18ce3-94e6-476a-870d-a0108d1697b7, c72da51b-16c8-4741-8646-2e45721b3277, 7be18ce3-94e6-476a-870d-a0108d1697b4 and c72da51b-16c8-4741-8646-2e45721b3272 will receive a notification.
Retrieving notifications
Lists
You can easily retrieve notifications via the getNotifications
method. Some examples:
Counts
Getting counts of read/unread notifications can be done via the countNotifications
method. Some examples:
Mark as read
To mark notifications as read, you can use the markAsRead
method. Some examples:
Notification Entity
The following getters can be used at your notifications 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.
Example:
Passing to view
You can do something like this to use the notification list in your view:
Notification Manager
The NotificationManager
is the Manager of the plugin. You can get an instance with:
The NotificationManager
has the following namespace: JeffersonSimaoGoncalves\Notifier\Utility\NotificationManager
.
The manager has the following methods available:
notify
addRecipientList
getRecipientList
addTemplate
getTemplate
Notifier Component
The JeffersonSimaoGoncalves/Notifier.Notifier
component can be used in Controllers:
The component has the following methods available:
getNotifications
countNotifications
markAsRead
notify
Keep in touch
Pull Requests are always more than welcome!
Credits
This work is based on the code by Bakkerij.