From 17a3781bd8c03e6b653104dbcb996a1ff1213959 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Fri, 14 Aug 2015 17:03:55 -0400 Subject: Add Gantt chart for projects --- app/Model/TaskFilter.php | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'app/Model/TaskFilter.php') diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php index 956ffbe8..8da4a214 100644 --- a/app/Model/TaskFilter.php +++ b/app/Model/TaskFilter.php @@ -86,6 +86,38 @@ class TaskFilter extends Base return $this; } + /** + * Prepare filter for Gantt chart + * + * @access public + * @return TaskFilter + */ + public function gantt() + { + $this->query = $this->db->table(Task::TABLE); + $this->query->join(Board::TABLE, 'id', 'column_id', Task::TABLE); + $this->query->join(User::TABLE, 'id', 'owner_id', Task::TABLE); + + $this->query->columns( + Task::TABLE.'.id', + Task::TABLE.'.title', + Task::TABLE.'.project_id', + Task::TABLE.'.column_id', + Task::TABLE.'.color_id', + Task::TABLE.'.date_started', + Task::TABLE.'.date_due', + Task::TABLE.'.date_creation', + Task::TABLE.'.is_active', + Task::TABLE.'.position', + Board::TABLE.'.position AS column_position', + Board::TABLE.'.title AS column_title', + User::TABLE.'.name AS assignee_name', + User::TABLE.'.username AS assignee_username' + ); + + return $this; + } + /** * Create a new query * @@ -674,6 +706,50 @@ class TaskFilter extends Base }); } + /** + * Format tasks to be displayed in the Gantt chart + * + * @access public + * @return array + */ + public function toGanttBars() + { + $bars = array(); + $columns = array(); + + foreach ($this->query->findAll() as $task) { + if (! isset($column_count[$task['project_id']])) { + $columns[$task['project_id']] = $this->board->getColumnsList($task['project_id']); + } + + $start = $task['date_started'] ?: time(); + $end = $task['date_due'] ?: $start; + + $bars[] = array( + 'id' => $task['id'], + 'title' => $task['title'], + 'start' => array( + (int) date('Y', $start), + (int) date('n', $start), + (int) date('j', $start), + ), + 'end' => array( + (int) date('Y', $end), + (int) date('n', $end), + (int) date('j', $end), + ), + 'column_title' => $task['column_title'], + 'assignee' => $task['assignee_name'] ?: $task['assignee_username'], + 'progress' => $this->task->getProgress($task, $columns[$task['project_id']]).'%', + 'link' => $this->helper->url->href('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), + 'color' => $this->color->getColorProperties($task['color_id']), + 'not_defined' => empty($task['date_due']) || empty($task['date_started']), + ); + } + + return $bars; + } + /** * Format the results to the ajax autocompletion * -- cgit v1.2.3