summaryrefslogtreecommitdiff
path: root/app/Event/ProjectActivityListener.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-10-12 21:38:56 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-10-12 21:38:56 -0400
commit074056352de98fc567b4d13184c72887c75625d0 (patch)
tree7d262c3a5d5f779648f51aa0eb7d9f279c05d89d /app/Event/ProjectActivityListener.php
parent4061927d215c846ff8eb196301bf61532018042b (diff)
Project activity refactoring and listeners improvements
Diffstat (limited to 'app/Event/ProjectActivityListener.php')
-rw-r--r--app/Event/ProjectActivityListener.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/app/Event/ProjectActivityListener.php b/app/Event/ProjectActivityListener.php
new file mode 100644
index 00000000..8958bd2b
--- /dev/null
+++ b/app/Event/ProjectActivityListener.php
@@ -0,0 +1,61 @@
+<?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->registry->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;
+ }
+}