From 689687dd4ee186cb9cf5d0230b4648e242c53b10 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 20 Sep 2015 22:18:56 -0400 Subject: Add formatters --- app/Formatter/ProjectGanttFormatter.php | 90 +++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 app/Formatter/ProjectGanttFormatter.php (limited to 'app/Formatter/ProjectGanttFormatter.php') diff --git a/app/Formatter/ProjectGanttFormatter.php b/app/Formatter/ProjectGanttFormatter.php new file mode 100644 index 00000000..652b947d --- /dev/null +++ b/app/Formatter/ProjectGanttFormatter.php @@ -0,0 +1,90 @@ +projects = array(); + } + else { + + $this->projects = $this->db + ->table(self::TABLE) + ->asc('start_date') + ->in('id', $project_ids) + ->eq('is_active', self::ACTIVE) + ->eq('is_private', 0) + ->findAll(); + } + + return $this; + } + + /** + * Format projects to be displayed in the Gantt chart + * + * @access public + * @return array + */ + public function format() + { + $colors = $this->color->getDefaultColors(); + $bars = array(); + + foreach ($this->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; + } +} -- cgit v1.2.3