diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-12-27 19:10:38 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-12-27 19:10:38 -0500 |
commit | 17dc5bdc9ede52ad618bbf326e67e3b6988170f7 (patch) | |
tree | 9cf4d325667f11fa735bca84042fb385e3273329 /app/Event | |
parent | cf821e117ce8b937cff7f386a107aaa81ba6bf9b (diff) |
Move events handling to Symfony\EventDispatcher
Diffstat (limited to 'app/Event')
-rw-r--r-- | app/Event/Base.php | 79 | ||||
-rw-r--r-- | app/Event/CommentEvent.php | 7 | ||||
-rw-r--r-- | app/Event/FileEvent.php | 7 | ||||
-rw-r--r-- | app/Event/GenericEvent.php | 45 | ||||
-rw-r--r-- | app/Event/NotificationListener.php | 83 | ||||
-rw-r--r-- | app/Event/ProjectActivityListener.php | 61 | ||||
-rw-r--r-- | app/Event/ProjectDailySummaryListener.php | 28 | ||||
-rw-r--r-- | app/Event/ProjectModificationDateListener.php | 30 | ||||
-rw-r--r-- | app/Event/SubtaskEvent.php | 7 | ||||
-rw-r--r-- | app/Event/TaskEvent.php | 7 | ||||
-rw-r--r-- | app/Event/WebhookListener.php | 44 |
11 files changed, 73 insertions, 325 deletions
diff --git a/app/Event/Base.php b/app/Event/Base.php deleted file mode 100644 index 0217fa08..00000000 --- a/app/Event/Base.php +++ /dev/null @@ -1,79 +0,0 @@ -<?php - -namespace Event; - -use Pimple\Container; -use Core\Listener; -use Core\Tool; - -/** - * Base Listener - * - * @package event - * @author Frederic Guillot - * - * @property \Model\Comment $comment - * @property \Model\Project $project - * @property \Model\ProjectActivity $projectActivity - * @property \Model\SubTask $subTask - * @property \Model\Task $task - * @property \Model\TaskFinder $taskFinder - */ -abstract class Base implements Listener -{ - /** - * Container instance - * - * @access protected - * @var \Pimple\Container - */ - protected $container; - - /** - * Constructor - * - * @access public - * @param \Pimple\Container $container - */ - public function __construct(Container $container) - { - $this->container = $container; - } - - /** - * Return class information - * - * @access public - * @return string - */ - public function __toString() - { - return get_called_class(); - } - - /** - * Load automatically models - * - * @access public - * @param string $name Model name - * @return mixed - */ - public function __get($name) - { - return Tool::loadModel($this->container, $name); - } - - /** - * Get event namespace - * - * Event = task.close | Namespace = task - * - * @access public - * @return string - */ - public function getEventNamespace() - { - $event_name = $this->container['event']->getLastTriggeredEvent(); - return substr($event_name, 0, strpos($event_name, '.')); - } -} diff --git a/app/Event/CommentEvent.php b/app/Event/CommentEvent.php new file mode 100644 index 00000000..75a132d7 --- /dev/null +++ b/app/Event/CommentEvent.php @@ -0,0 +1,7 @@ +<?php + +namespace Event; + +class CommentEvent extends GenericEvent +{ +} diff --git a/app/Event/FileEvent.php b/app/Event/FileEvent.php new file mode 100644 index 00000000..81bd83c9 --- /dev/null +++ b/app/Event/FileEvent.php @@ -0,0 +1,7 @@ +<?php + +namespace Event; + +class FileEvent extends GenericEvent +{ +} diff --git a/app/Event/GenericEvent.php b/app/Event/GenericEvent.php new file mode 100644 index 00000000..b29d8f32 --- /dev/null +++ b/app/Event/GenericEvent.php @@ -0,0 +1,45 @@ +<?php + +namespace Event; + +use ArrayAccess; +use Symfony\Component\EventDispatcher\Event as BaseEvent; + +class GenericEvent extends BaseEvent implements ArrayAccess +{ + private $container = array(); + + public function __construct(array $values = array()) + { + $this->container = $values; + } + + public function getAll() + { + return $this->container; + } + + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + public function offsetUnset($offset) + { + unset($this->container[$offset]); + } + + public function offsetGet($offset) + { + return isset($this->container[$offset]) ? $this->container[$offset] : null; + } +} diff --git a/app/Event/NotificationListener.php b/app/Event/NotificationListener.php deleted file mode 100644 index 3c049327..00000000 --- a/app/Event/NotificationListener.php +++ /dev/null @@ -1,83 +0,0 @@ -<?php - -namespace Event; - -/** - * Notification listener - * - * @package event - * @author Frederic Guillot - */ -class NotificationListener extends Base -{ - /** - * Template name - * - * @accesss private - * @var string - */ - private $template = ''; - - /** - * Set template name - * - * @access public - * @param string $template Template name - */ - public function setTemplate($template) - { - $this->template = $template; - } - - /** - * 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); - $users = $this->notification->getUsersList($values['task']['project_id']); - - if ($users) { - $this->notification->sendEmails($this->template, $users, $values); - return true; - } - - return false; - } - - /** - * Fetch data for the mail template - * - * @access public - * @param array $data Event data - * @return array - */ - public function getTemplateData(array $data) - { - $values = array(); - - switch ($this->getEventNamespace()) { - case 'task': - $values['task'] = $this->taskFinder->getDetails($data['task_id']); - break; - case 'subtask': - $values['subtask'] = $this->subtask->getById($data['id'], true); - $values['task'] = $this->taskFinder->getDetails($data['task_id']); - break; - case 'file': - $values['file'] = $data; - $values['task'] = $this->taskFinder->getDetails($data['task_id']); - break; - case 'comment': - $values['comment'] = $this->comment->getById($data['id']); - $values['task'] = $this->taskFinder->getDetails($values['comment']['task_id']); - break; - } - - return $values; - } -} diff --git a/app/Event/ProjectActivityListener.php b/app/Event/ProjectActivityListener.php deleted file mode 100644 index 75efe65d..00000000 --- a/app/Event/ProjectActivityListener.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -namespace Event; - -/** - * Project activity listener - * - * @package event - * @author Frederic Guillot - */ -class ProjectActivityListener extends Base -{ - /** - * 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) - { - if (isset($data['task_id'])) { - - $values = $this->getValues($data); - - return $this->projectActivity->createEvent( - $values['task']['project_id'], - $values['task']['id'], - $this->acl->getUserId(), - $this->container['event']->getLastTriggeredEvent(), - $values - ); - } - - return false; - } - - /** - * Get event activity data - * - * @access private - * @param array $data Event data dictionary - * @return array - */ - private function getValues(array $data) - { - $values = array(); - $values['task'] = $this->taskFinder->getDetails($data['task_id']); - - switch ($this->getEventNamespace()) { - case 'subtask': - $values['subtask'] = $this->subTask->getById($data['id'], true); - break; - case 'comment': - $values['comment'] = $this->comment->getById($data['id']); - break; - } - - return $values; - } -} diff --git a/app/Event/ProjectDailySummaryListener.php b/app/Event/ProjectDailySummaryListener.php deleted file mode 100644 index cd593abc..00000000 --- a/app/Event/ProjectDailySummaryListener.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -namespace Event; - -/** - * Project daily summary listener - * - * @package event - * @author Frederic Guillot - */ -class ProjectDailySummaryListener extends Base -{ - /** - * 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) - { - if (isset($data['project_id'])) { - return $this->projectDailySummary->updateTotals($data['project_id'], date('Y-m-d')); - } - - return false; - } -} diff --git a/app/Event/ProjectModificationDateListener.php b/app/Event/ProjectModificationDateListener.php deleted file mode 100644 index abc176b0..00000000 --- a/app/Event/ProjectModificationDateListener.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php - -namespace Event; - -/** - * Project modification date listener - * - * Update the "last_modified" field for a project - * - * @package event - * @author Frederic Guillot - */ -class ProjectModificationDateListener extends Base -{ - /** - * 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) - { - if (isset($data['project_id'])) { - return $this->project->updateModificationDate($data['project_id']); - } - - return false; - } -} diff --git a/app/Event/SubtaskEvent.php b/app/Event/SubtaskEvent.php new file mode 100644 index 00000000..229db860 --- /dev/null +++ b/app/Event/SubtaskEvent.php @@ -0,0 +1,7 @@ +<?php + +namespace Event; + +class SubtaskEvent extends GenericEvent +{ +} diff --git a/app/Event/TaskEvent.php b/app/Event/TaskEvent.php new file mode 100644 index 00000000..e2fb30fe --- /dev/null +++ b/app/Event/TaskEvent.php @@ -0,0 +1,7 @@ +<?php + +namespace Event; + +class TaskEvent extends GenericEvent +{ +} diff --git a/app/Event/WebhookListener.php b/app/Event/WebhookListener.php deleted file mode 100644 index f7e23e07..00000000 --- a/app/Event/WebhookListener.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php - -namespace Event; - -/** - * Webhook task events - * - * @package event - * @author Frederic Guillot - */ -class WebhookListener extends Base -{ - /** - * Url to call - * - * @access private - * @var string - */ - private $url = ''; - - /** - * Set webhook url - * - * @access public - * @param string $url URL to call - */ - public function setUrl($url) - { - $this->url = $url; - } - - /** - * 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) - { - $this->webhook->notify($this->url, $data); - return true; - } -} |