summaryrefslogtreecommitdiff
path: root/app/Subscriber/NotificationSubscriber.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Subscriber/NotificationSubscriber.php')
-rw-r--r--app/Subscriber/NotificationSubscriber.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/app/Subscriber/NotificationSubscriber.php b/app/Subscriber/NotificationSubscriber.php
new file mode 100644
index 00000000..41fd6aef
--- /dev/null
+++ b/app/Subscriber/NotificationSubscriber.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Subscriber;
+
+use Event\GenericEvent;
+use Model\Task;
+use Model\Comment;
+use Model\Subtask;
+use Model\File;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+class NotificationSubscriber extends \Core\Base implements EventSubscriberInterface
+{
+ public static function getSubscribedEvents()
+ {
+ return array(
+ Task::EVENT_CREATE => array('execute', 0),
+ Task::EVENT_UPDATE => array('execute', 0),
+ Task::EVENT_CLOSE => array('execute', 0),
+ Task::EVENT_OPEN => array('execute', 0),
+ Task::EVENT_MOVE_COLUMN => array('execute', 0),
+ Task::EVENT_MOVE_POSITION => array('execute', 0),
+ Task::EVENT_ASSIGNEE_CHANGE => array('execute', 0),
+ Subtask::EVENT_CREATE => array('execute', 0),
+ Subtask::EVENT_UPDATE => array('execute', 0),
+ Comment::EVENT_CREATE => array('execute', 0),
+ Comment::EVENT_UPDATE => array('execute', 0),
+ File::EVENT_CREATE => array('execute', 0),
+ );
+ }
+
+ public function execute(GenericEvent $event, $event_name)
+ {
+ $this->notification->sendNotifications($event_name, $this->getEventData($event));
+ }
+
+ public function getEventData(GenericEvent $event)
+ {
+ $values = array();
+
+ switch (get_class($event)) {
+ case 'Event\TaskEvent':
+ $values['task'] = $this->taskFinder->getDetails($event['task_id']);
+ break;
+ case 'Event\SubtaskEvent':
+ $values['subtask'] = $this->subtask->getById($event['id'], true);
+ $values['task'] = $this->taskFinder->getDetails($values['subtask']['task_id']);
+ break;
+ case 'Event\FileEvent':
+ $values['file'] = $event->getAll();
+ $values['task'] = $this->taskFinder->getDetails($values['file']['task_id']);
+ break;
+ case 'Event\CommentEvent':
+ $values['comment'] = $this->comment->getById($event['id']);
+ $values['task'] = $this->taskFinder->getDetails($values['comment']['task_id']);
+ break;
+ }
+
+ return $values;
+ }
+}