From 09504ced8f96f41e6446fcdc878536dbf03ba0a7 Mon Sep 17 00:00:00 2001 From: suhaboncukcu Date: Tue, 18 Oct 2016 20:52:34 +0200 Subject: [PATCH 1/5] Enables config files for the plugin without changing the current functionality --- config/bootstrap.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/config/bootstrap.php b/config/bootstrap.php index a4dc4c1..8714b41 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -20,4 +20,9 @@ 'body' => ':body' ]); -Configure::write('Notifier.recipientLists', []); \ No newline at end of file +Configure::write('Notifier.recipientLists', []); + + +collection((array)Configure::read('Notifier.config'))->each(function ($file) { + Configure::load($file); +}); From d85b366351d08b88a900f5f9cda517b3903f335a Mon Sep 17 00:00:00 2001 From: suhaboncukcu Date: Tue, 18 Oct 2016 21:00:33 +0200 Subject: [PATCH 2/5] adds improvements on readme about new features --- README.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1cd0504..66d744d 100644 --- a/README.md +++ b/README.md @@ -33,15 +33,42 @@ After loading the plugin you need to migrate the tables for the plugin using: #### Templates -Before sending any notification, we need to register a template. An example about how to add templates: +Before sending any notification, we need to register a template. There are two ways to add templates: + +##### 1. Using NotificationManager utility class to create templates ```php + use Bakkerij\Notifier\Utility\NotificationManager; + + $notificationManager = NotificationManager::instance(); $notificationManager->addTemplate('newBlog', [ 'title' => 'New blog by :username', 'body' => ':username has posted a new blog named :name' ]); ``` +##### 2. Using config files to define templates + +Create a file in your config folder named `templates.php` and create your templates as below: + +```php + return [ + 'Notifier' => [ + 'templates' => [ + 'newBlog' => [ + 'title' => 'New blog by :username', + 'body' => ':username has posted a new blog named :name' + ], + 'newMessage' => [ + 'title' => 'New message from :username', + 'body' => ':username sent you a message on :timeago' + ] + ] + ] + ]; +``` + + 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. From 782254974b0521e166d5d838cadf241a93866d89 Mon Sep 17 00:00:00 2001 From: suhaboncukcu Date: Tue, 18 Oct 2016 21:09:47 +0200 Subject: [PATCH 3/5] adds a few more improvement lines to readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 66d744d..4f971f3 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,12 @@ Create a file in your config folder named `templates.php` and create your templa ]; ``` +Then load your file from your bootstrap.php file: + +```php + Configure::write('Notifier.config', ['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. From 5bd71d0d74b42f7096415e491989180cb8720491 Mon Sep 17 00:00:00 2001 From: suhaboncukcu Date: Tue, 18 Oct 2016 21:11:47 +0200 Subject: [PATCH 4/5] removes newline at the end ofthe file as original --- config/bootstrap.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/bootstrap.php b/config/bootstrap.php index 8714b41..54897ca 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -22,7 +22,6 @@ Configure::write('Notifier.recipientLists', []); - collection((array)Configure::read('Notifier.config'))->each(function ($file) { Configure::load($file); -}); +}); \ No newline at end of file From 693fa7a5328a1ec1571b8961ccc388ef9e98c6e4 Mon Sep 17 00:00:00 2001 From: suhaboncukcu Date: Tue, 18 Oct 2016 21:42:26 +0200 Subject: [PATCH 5/5] fixes TravisErrors with a CakePHP standard phpcs run --- src/Model/Entity/Notification.php | 4 ++++ src/Utility/NotificationManager.php | 3 +++ tests/TestCase/Model/Table/NotificationsTableTest.php | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Model/Entity/Notification.php b/src/Model/Entity/Notification.php index 5da078e..2b6fca0 100644 --- a/src/Model/Entity/Notification.php +++ b/src/Model/Entity/Notification.php @@ -94,6 +94,7 @@ protected function _getTitle() return Text::insert($template['title'], $vars); } + return ''; } @@ -117,6 +118,7 @@ protected function _getBody() return Text::insert($template['body'], $vars); } + return ''; } @@ -132,6 +134,7 @@ protected function _getUnread() if ($this->_properties['state'] === 1) { return true; } + return false; } @@ -147,6 +150,7 @@ protected function _getRead() if ($this->_properties['state'] === 0) { return true; } + return false; } diff --git a/src/Utility/NotificationManager.php b/src/Utility/NotificationManager.php index ecdea55..5a630ca 100644 --- a/src/Utility/NotificationManager.php +++ b/src/Utility/NotificationManager.php @@ -43,6 +43,7 @@ public static function instance($manager = null) if (empty(static::$_generalManager)) { static::$_generalManager = new NotificationManager(); } + return static::$_generalManager; } @@ -203,6 +204,7 @@ public function getTemplate($name, $type = null) if ($type == 'body') { return $templates[$name]['body']; } + return $templates[$name]; } @@ -224,6 +226,7 @@ public function getTrackingId() for ($i = 0; $i < 10; $i++) { $trackingId .= $characters[rand(0, $charactersLength - 1)]; } + return $trackingId; } } diff --git a/tests/TestCase/Model/Table/NotificationsTableTest.php b/tests/TestCase/Model/Table/NotificationsTableTest.php index 7ac241c..9169ce1 100644 --- a/tests/TestCase/Model/Table/NotificationsTableTest.php +++ b/tests/TestCase/Model/Table/NotificationsTableTest.php @@ -23,7 +23,7 @@ */ class NotificationsTableTest extends TestCase { - + public $fixtures = [ 'plugin.bakkerij\Notifier.notifications', ];