From 58b0159e87f778819b6045ae5a099fa06b4f1a72 Mon Sep 17 00:00:00 2001 From: BlueTeck Date: Sun, 29 Mar 2015 12:48:24 +0200 Subject: add activity stream to task #693 --- app/Controller/Task.php | 16 +++++++++++++++ app/Model/ProjectActivity.php | 46 +++++++++++++++++++++++++++++++++++++++++++ app/Template/task/events.php | 25 +++++++++++++++++++++++ app/Template/task/sidebar.php | 3 +++ 4 files changed, 90 insertions(+) create mode 100644 app/Template/task/events.php (limited to 'app') diff --git a/app/Controller/Task.php b/app/Controller/Task.php index 64017582..9bd6e711 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -84,6 +84,22 @@ class Task extends Base ))); } + /** + * Display task activities + * + * @access public + */ + public function activites() + { + $task = $this->getTask(); + $this->response->html($this->taskLayout('task/events', array( + 'title' => $task['title'], + 'task' => $task, + 'ajax' => $this->request->isAjax(), + 'events' => $this->projectActivity->getTasks([$task['id']]), + ))); + } + /** * Display a form to create a new task * diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php index c5fbbd38..46d71fc7 100644 --- a/app/Model/ProjectActivity.php +++ b/app/Model/ProjectActivity.php @@ -50,6 +50,52 @@ class ProjectActivity extends Base return $this->db->table(self::TABLE)->insert($values); } + /** + * Get all events for the given task + * + * @access public + * @param integer[] $task_ids Task ids + * @param integer $limit Maximum events number + * @param integer $start Timestamp of earliest activity + * @param integer $end Timestamp of latest activity + * @return array + */ + public function getTasks(array $task_ids, $limit = 50, $start = null, $end = null) + { + $query = $this->db->table(self::TABLE) + ->columns( + self::TABLE.'.*', + User::TABLE.'.username AS author_username', + User::TABLE.'.name AS author_name' + ) + ->in('task_id', $task_ids) + ->join(User::TABLE, 'id', 'creator_id') + ->desc(self::TABLE.'.id') + ->limit($limit); + + if(!is_null($start)){ + $query->gte('date_creation', $start); + } + + if(!is_null($end)){ + $query->lte('date_creation', $end); + } + + $events = $query->findAll(); + + foreach ($events as &$event) { + + $event += $this->decode($event['data']); + unset($event['data']); + + $event['author'] = $event['author_name'] ?: $event['author_username']; + $event['event_title'] = $this->getTitle($event); + $event['event_content'] = $this->getContent($event); + } + + return $events; + } + /** * Get all events for the given project * diff --git a/app/Template/task/events.php b/app/Template/task/events.php new file mode 100644 index 00000000..188f46fe --- /dev/null +++ b/app/Template/task/events.php @@ -0,0 +1,25 @@ + + + +

+ + + +
+

+ contains($event['event_name'], 'subtask')): ?> + + contains($event['event_name'], 'task')): ?> + + contains($event['event_name'], 'comment')): ?> + + +   +

+
+
+ + + \ No newline at end of file diff --git a/app/Template/task/sidebar.php b/app/Template/task/sidebar.php index cb3b3c69..e911d5cd 100644 --- a/app/Template/task/sidebar.php +++ b/app/Template/task/sidebar.php @@ -4,6 +4,9 @@
  • a(t('Summary'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
  • +
  • + a(t('Activity stream'), 'task', 'activites', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?> +
  • a(t('Transitions'), 'task', 'transitions', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
  • -- cgit v1.2.3