public function testEntity()
 {
     NotificationManager::instance()->addTemplate('newNotification', ['title' => 'New Notification', 'body' => ':from has sent :to a notification about :about']);
     $notify = NotificationManager::instance()->notify(['users' => 1, 'template' => 'newNotification', 'vars' => ['from' => 'Bob', 'to' => 'Leonardo', 'about' => 'Programming Stuff']]);
     $entity = $this->Notifications->get(2);
     $this->assertEquals('newNotification', $entity->template);
     $this->assertEquals('New Notification', $entity->title);
     $this->assertEquals('Bob has sent Leonardo a notification about Programming Stuff', $entity->body);
 }
 public function setUp()
 {
     parent::setUp();
     $this->Manager = NotificationManager::instance();
     $this->Model = TableRegistry::get('Notifier.Notifications');
     // Setup our component and fake the controller
     $request = new Request();
     $response = new Response();
     $this->controller = $this->getMock('Cake\\Controller\\Controller', ['redirect'], [$request, $response]);
     $this->controller->loadComponent('Auth');
     $this->controller->Auth->setUser(['id' => 1]);
     $registry = new ComponentRegistry($this->controller);
     $this->Notifier = new NotifierComponent($registry);
 }
 public function testIndex()
 {
     NotificationManager::instance()->notify(['users' => [1], 'vars' => ['title' => 'Testing the title', 'body' => 'Testing the body']]);
     $this->session(['Auth' => ['CakeAdmin' => ['id' => 1, 'email' => '*****@*****.**', 'cakeadmin' => 1]]]);
     $this->get('/admin/notifications');
     $this->assertResponseSuccess();
     $this->assertNoRedirect();
     $viewVars = $this->_controller->viewVars;
     $this->assertArrayHasKey('notifications', $viewVars);
     $this->assertArrayHasKey(0, $viewVars['notifications']);
     $this->assertInstanceOf('Notifier\\Model\\Entity\\Notification', $viewVars['notifications'][0]);
     $this->assertResponseContains('Testing the title');
     $this->assertResponseContains('Testing the body');
 }
 /**
  * afterSave event
  *
  * @param \Cake\Event\Event $event Event.
  * @param \Cake\ORM\Entity $entity Entity.
  * @param array $options Options.
  * @return void
  */
 public function afterSave($event, $entity, $options)
 {
     if ($entity->isNew()) {
         NotificationManager::instance()->notify(['recipientLists' => ['administrators'], 'template' => 'newAdministrator', 'vars' => ['email' => $entity->get('email'), 'created' => $entity->get('created')]]);
     }
 }
 protected function _setRecipientList()
 {
     NotificationManager::instance()->addRecipientList('administrators', TableRegistry::get('CakeAdmin.Administrators')->find('list')->toArray());
 }
Beispiel #6
0
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\ORM\TableRegistry;
use Settings\Core\Setting;
use Cake\Event\EventManager;
use CakeAdmin\Event\CakeAdminMailer;
use Notifier\Utility\NotificationManager;
# Plugins
Plugin::load('Utils', []);
Plugin::load('Settings', ['bootstrap' => true, 'routes' => true]);
Plugin::load('Notifier', ['bootstrap' => true, 'routes' => true]);
# Configurations
Configure::write('Session.timeout', 4320);
Configure::write('CA.theme', 'CakeAdmin');
Configure::write('CA.viewClass', null);
Configure::write('CA.layout.default', 'CakeAdmin.default');
Configure::write('CA.layout.login', 'CakeAdmin.login');
Configure::write('CA.fields', ['username' => 'email', 'password' => 'password']);
Configure::write('CA.email.from', ['*****@*****.**' => 'Bob | CakeManager']);
Configure::write('CA.email.transport', 'default');
Configure::write('CA.Menu.main', []);
Configure::write('Settings.Prefixes.CA', 'CakeAdmin');
Configure::write('CA.PostTypes', []);
Configure::write('CA.Models.administrators', 'CakeAdmin.Administrators');
# Settings
Setting::register('App.Name', 'CakeAdmin Application');
# Theming
Plugin::load('LightStrap', ['bootstrap' => true, 'routes' => true]);
# Notification Templates
NotificationManager::instance()->addTemplate('newAdministrator', ['title' => 'New administrator has been registered', 'body' => ':email has been registered as administrator at :created']);
 /**
  * afterSave event
  *
  * @param \Cake\Event\Event $event Event.
  * @param \Cake\ORM\Entity $entity Entity.
  * @param array $options Options.
  * @return void
  */
 public function afterSave($event, $entity, $options)
 {
     PathManager::instance()->buildRoutes('blogs');
     NotificationManager::instance()->notify(['users' => [1], 'template' => 'blog_post', 'vars' => ['title' => $entity->title, 'creator' => $entity->created_by]]);
 }
 /**
  * notify
  *
  * Sends notifications to specific users.
  * The first parameter `$data` is an array with multiple options.
  *
  * ### Options
  * - `users` - An array or int with id's of users who will receive a notification.
  * - `roles` - An array or int with id's of roles which all users ill receive a notification.
  * - `template` - The template wich will be used.
  * - `vars` - The variables used in the template.
  *
  * ### Example
  * ```
  *  NotificationManager::instance()->notify([
  *      'users' => 1,
  *      'template' => 'newOrder',
  *      'vars' => [
  *          'receiver' => $receiver->name
  *          'total' => $order->total
  *      ],
  *  ]);
  * ```
  *
  * @param array $data Data with options.
  * @return string
  */
 public function notify($data)
 {
     return NotificationManager::instance()->notify($data);
 }
 public function testInstance()
 {
     $instance = NotificationManager::instance();
     $this->assertInstanceOf('Notifier\\Utility\\NotificationManager', $instance);
 }
 public function afterSave($event, $entity, $options)
 {
     if ($entity->isNew()) {
         NotificationManager::instance()->notify(['recipientLists' => ['administrators'], 'template' => 'new_user', 'vars' => ['email' => $entity->get('email'), 'created' => $entity->get('created')]]);
         $event = new Event('Model.Users.afterRegister', $this, ['user' => $entity]);
         EventManager::instance()->dispatch($event);
     }
 }