From fd60964c239627d2d55c6eca0888be84a8f6653f Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 22 Aug 2015 16:20:53 -0400 Subject: Add global Gantt chart for all projects --- app/Model/Project.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'app/Model/Project.php') diff --git a/app/Model/Project.php b/app/Model/Project.php index 161a0cae..52500820 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -114,6 +114,54 @@ class Project extends Base return $this->db->table(self::TABLE)->eq('id', $project_id)->eq('is_private', 1)->exists(); } + /** + * Get all projects to generate the Gantt chart + * + * @access public + * @param array $project_ids + * @return array + */ + public function getGanttBars(array $project_ids) + { + if (empty($project_ids)) { + return array(); + } + + $colors = $this->color->getDefaultColors(); + $projects = $this->db->table(self::TABLE)->asc('start_date')->in('id', $project_ids)->eq('is_active', self::ACTIVE)->eq('is_private', 0)->findAll(); + $bars = array(); + + foreach ($projects as $project) { + $start = empty($project['start_date']) ? time() : strtotime($project['start_date']); + $end = empty($project['end_date']) ? $start : strtotime($project['end_date']); + $color = next($colors) ?: reset($colors); + + $bars[] = array( + 'type' => 'project', + 'id' => $project['id'], + 'title' => $project['name'], + '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), + ), + 'link' => $this->helper->url->href('project', 'show', array('project_id' => $project['id'])), + 'board_link' => $this->helper->url->href('board', 'show', array('project_id' => $project['id'])), + 'gantt_link' => $this->helper->url->href('gantt', 'project', array('project_id' => $project['id'])), + 'color' => $color, + 'not_defined' => empty($project['start_date']) || empty($project['end_date']), + 'users' => $this->projectPermission->getProjectUsers($project['id']), + ); + } + + return $bars; + } + /** * Get all projects * @@ -271,8 +319,7 @@ class Project extends Base { foreach ($projects as &$project) { $this->getColumnStats($project); - $project['managers'] = $this->projectPermission->getManagers($project['id']); - $project['members'] = $this->projectPermission->getOnlyMembers($project['id']); + $project = array_merge($project, $this->projectPermission->getProjectUsers($project['id'])); } return $projects; -- cgit v1.2.3