diff options
author | Imbasaur <yarrusg@gmail.com> | 2016-04-13 17:05:59 +0200 |
---|---|---|
committer | Imbasaur <yarrusg@gmail.com> | 2016-04-13 17:05:59 +0200 |
commit | 99f275e5bb033cca33eee87b0e914645730f13d1 (patch) | |
tree | ad845419d56304f2bf014744f0878186f7155a3c /app/Formatter/TaskGanttFormatter.php | |
parent | 13d5bd8e48bd6c0109d1272da58a8879bf9a6737 (diff) | |
parent | cd5bf9d4d214ec9282b706c26bb27cabf150ee63 (diff) |
Merge pull request #1 from fguillot/master
Diffstat (limited to 'app/Formatter/TaskGanttFormatter.php')
-rw-r--r-- | app/Formatter/TaskGanttFormatter.php | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/app/Formatter/TaskGanttFormatter.php b/app/Formatter/TaskGanttFormatter.php new file mode 100644 index 00000000..3209aa37 --- /dev/null +++ b/app/Formatter/TaskGanttFormatter.php @@ -0,0 +1,78 @@ +<?php + +namespace Kanboard\Formatter; + +use Kanboard\Core\Filter\FormatterInterface; + +/** + * Task Gantt Formatter + * + * @package formatter + * @author Frederic Guillot + */ +class TaskGanttFormatter extends BaseFormatter implements FormatterInterface +{ + /** + * Local cache for project columns + * + * @access private + * @var array + */ + private $columns = array(); + + /** + * Apply formatter + * + * @access public + * @return array + */ + public function format() + { + $bars = array(); + + foreach ($this->query->findAll() as $task) { + $bars[] = $this->formatTask($task); + } + + return $bars; + } + + /** + * Format a single task + * + * @access private + * @param array $task + * @return array + */ + private function formatTask(array $task) + { + if (! isset($this->columns[$task['project_id']])) { + $this->columns[$task['project_id']] = $this->column->getList($task['project_id']); + } + + $start = $task['date_started'] ?: time(); + $end = $task['date_due'] ?: $start; + + return array( + 'type' => 'task', + '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_name'], + 'assignee' => $task['assignee_name'] ?: $task['assignee_username'], + 'progress' => $this->task->getProgress($task, $this->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']), + ); + } +} |