summaryrefslogtreecommitdiff
path: root/app/Event
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-08-15 17:23:41 -0700
committerFrédéric Guillot <fred@kanboard.net>2014-08-15 17:23:41 -0700
commit9eeded33f68872515954a2fc177fcb47a9273ae9 (patch)
treef3ef9507e087ca6bf3ce624232da240a8689b051 /app/Event
parentc539bdc8ab746c5afd48cf87de057dc38d50adac (diff)
Add email notifications
Diffstat (limited to 'app/Event')
-rw-r--r--app/Event/BaseNotificationListener.php76
-rw-r--r--app/Event/CommentNotificationListener.php30
-rw-r--r--app/Event/FileNotificationListener.php30
-rw-r--r--app/Event/SubTaskNotificationListener.php30
-rw-r--r--app/Event/TaskNotificationListener.php29
5 files changed, 195 insertions, 0 deletions
diff --git a/app/Event/BaseNotificationListener.php b/app/Event/BaseNotificationListener.php
new file mode 100644
index 00000000..6c1728cb
--- /dev/null
+++ b/app/Event/BaseNotificationListener.php
@@ -0,0 +1,76 @@
+<?php
+
+namespace Event;
+
+use Core\Listener;
+use Model\Notification;
+
+/**
+ * Base notification listener
+ *
+ * @package event
+ * @author Frederic Guillot
+ */
+abstract class BaseNotificationListener implements Listener
+{
+ /**
+ * Notification model
+ *
+ * @accesss protected
+ * @var Model\Notification
+ */
+ protected $notification;
+
+ /**
+ * Template name
+ *
+ * @accesss private
+ * @var string
+ */
+ private $template = '';
+
+ /**
+ * Fetch data for the mail template
+ *
+ * @access public
+ * @param array $data Event data
+ * @return array
+ */
+ abstract public function getTemplateData(array $data);
+
+ /**
+ * Constructor
+ *
+ * @access public
+ * @param \Model\Notification $notification Notification model instance
+ * @param string $template Template name
+ */
+ public function __construct(Notification $notification, $template)
+ {
+ $this->template = $template;
+ $this->notification = $notification;
+ }
+
+ /**
+ * Execute the action
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function execute(array $data)
+ {
+ $values = $this->getTemplateData($data);
+
+ // Get the list of users to be notified
+ $users = $this->notification->getUsersList($values['task']['project_id']);
+
+ // Send notifications
+ if ($users) {
+ $this->notification->sendEmails($this->template, $users, $values);
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/app/Event/CommentNotificationListener.php b/app/Event/CommentNotificationListener.php
new file mode 100644
index 00000000..3771ea7e
--- /dev/null
+++ b/app/Event/CommentNotificationListener.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Event;
+
+use Event\BaseNotificationListener;
+
+/**
+ * Comment notification listener
+ *
+ * @package event
+ * @author Frederic Guillot
+ */
+class CommentNotificationListener extends BaseNotificationListener
+{
+ /**
+ * Fetch data for the mail template
+ *
+ * @access public
+ * @param array $data Event data
+ * @return array
+ */
+ public function getTemplateData(array $data)
+ {
+ $values = array();
+ $values['comment'] = $this->notification->comment->getById($data['id']);
+ $values['task'] = $this->notification->task->getById($data['task_id'], true);
+
+ return $values;
+ }
+}
diff --git a/app/Event/FileNotificationListener.php b/app/Event/FileNotificationListener.php
new file mode 100644
index 00000000..98fc4260
--- /dev/null
+++ b/app/Event/FileNotificationListener.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Event;
+
+use Event\BaseNotificationListener;
+
+/**
+ * File notification listener
+ *
+ * @package event
+ * @author Frederic Guillot
+ */
+class FileNotificationListener extends BaseNotificationListener
+{
+ /**
+ * Fetch data for the mail template
+ *
+ * @access public
+ * @param array $data Event data
+ * @return array
+ */
+ public function getTemplateData(array $data)
+ {
+ $values = array();
+ $values['file'] = $data;
+ $values['task'] = $this->notification->task->getById($data['task_id'], true);
+
+ return $values;
+ }
+}
diff --git a/app/Event/SubTaskNotificationListener.php b/app/Event/SubTaskNotificationListener.php
new file mode 100644
index 00000000..0a239421
--- /dev/null
+++ b/app/Event/SubTaskNotificationListener.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Event;
+
+use Event\BaseNotificationListener;
+
+/**
+ * SubTask notification listener
+ *
+ * @package event
+ * @author Frederic Guillot
+ */
+class SubTaskNotificationListener extends BaseNotificationListener
+{
+ /**
+ * Fetch data for the mail template
+ *
+ * @access public
+ * @param array $data Event data
+ * @return array
+ */
+ public function getTemplateData(array $data)
+ {
+ $values = array();
+ $values['subtask'] = $this->notification->subtask->getById($data['id'], true);
+ $values['task'] = $this->notification->task->getById($data['task_id'], true);
+
+ return $values;
+ }
+}
diff --git a/app/Event/TaskNotificationListener.php b/app/Event/TaskNotificationListener.php
new file mode 100644
index 00000000..ffbe7a8c
--- /dev/null
+++ b/app/Event/TaskNotificationListener.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Event;
+
+use Event\BaseNotificationListener;
+
+/**
+ * Task notification listener
+ *
+ * @package event
+ * @author Frederic Guillot
+ */
+class TaskNotificationListener extends BaseNotificationListener
+{
+ /**
+ * Fetch data for the mail template
+ *
+ * @access public
+ * @param array $data Event data
+ * @return array
+ */
+ public function getTemplateData(array $data)
+ {
+ $values = array();
+ $values['task'] = $this->notification->task->getById($data['task_id'], true);
+
+ return $values;
+ }
+}