diff options
Diffstat (limited to 'app/Formatter')
-rw-r--r-- | app/Formatter/BaseTaskCalendarFormatter.php | 43 | ||||
-rw-r--r-- | app/Formatter/GroupAutoCompleteFormatter.php | 3 | ||||
-rw-r--r-- | app/Formatter/ProjectApiFormatter.php | 39 | ||||
-rw-r--r-- | app/Formatter/ProjectGanttFormatter.php | 57 | ||||
-rw-r--r-- | app/Formatter/ProjectsApiFormatter.php | 38 | ||||
-rw-r--r-- | app/Formatter/TaskApiFormatter.php | 37 | ||||
-rw-r--r-- | app/Formatter/TaskCalendarFormatter.php | 74 | ||||
-rw-r--r-- | app/Formatter/TaskGanttFormatter.php | 78 | ||||
-rw-r--r-- | app/Formatter/TaskICalFormatter.php | 40 | ||||
-rw-r--r-- | app/Formatter/TaskListSubtaskAssigneeFormatter.php | 56 | ||||
-rw-r--r-- | app/Formatter/TasksApiFormatter.php | 38 | ||||
-rw-r--r-- | app/Formatter/UserAutoCompleteFormatter.php | 50 | ||||
-rw-r--r-- | app/Formatter/UserMentionFormatter.php | 4 |
13 files changed, 272 insertions, 285 deletions
diff --git a/app/Formatter/BaseTaskCalendarFormatter.php b/app/Formatter/BaseTaskCalendarFormatter.php deleted file mode 100644 index 3d9ead4d..00000000 --- a/app/Formatter/BaseTaskCalendarFormatter.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php - -namespace Kanboard\Formatter; - -/** - * Common class to handle calendar events - * - * @package formatter - * @author Frederic Guillot - */ -abstract class BaseTaskCalendarFormatter extends BaseFormatter -{ - /** - * Column used for event start date - * - * @access protected - * @var string - */ - protected $startColumn = 'date_started'; - - /** - * Column used for event end date - * - * @access protected - * @var string - */ - protected $endColumn = 'date_completed'; - - /** - * Transform results to calendar events - * - * @access public - * @param string $start_column Column name for the start date - * @param string $end_column Column name for the end date - * @return $this - */ - public function setColumns($start_column, $end_column = '') - { - $this->startColumn = $start_column; - $this->endColumn = $end_column ?: $start_column; - return $this; - } -} diff --git a/app/Formatter/GroupAutoCompleteFormatter.php b/app/Formatter/GroupAutoCompleteFormatter.php index d811de7f..9d740b7f 100644 --- a/app/Formatter/GroupAutoCompleteFormatter.php +++ b/app/Formatter/GroupAutoCompleteFormatter.php @@ -4,12 +4,11 @@ namespace Kanboard\Formatter; use Kanboard\Core\Filter\FormatterInterface; use Kanboard\Core\Group\GroupProviderInterface; -use PicoDb\Table; /** * Auto-complete formatter for groups * - * @package formatter + * @package Kanboard\Formatter * @author Frederic Guillot */ class GroupAutoCompleteFormatter extends BaseFormatter implements FormatterInterface diff --git a/app/Formatter/ProjectApiFormatter.php b/app/Formatter/ProjectApiFormatter.php new file mode 100644 index 00000000..5521d57c --- /dev/null +++ b/app/Formatter/ProjectApiFormatter.php @@ -0,0 +1,39 @@ +<?php + +namespace Kanboard\Formatter; + +use Kanboard\Core\Filter\FormatterInterface; + +/** + * Class ProjectApiFormatter + * + * @package Kanboard\Formatter + */ +class ProjectApiFormatter extends BaseFormatter implements FormatterInterface +{ + protected $project = null; + + public function withProject($project) + { + $this->project = $project; + return $this; + } + + /** + * Apply formatter + * + * @access public + * @return mixed + */ + public function format() + { + if (! empty($this->project)) { + $this->project['url'] = array( + 'board' => $this->helper->url->to('BoardViewController', 'show', array('project_id' => $this->project['id']), '', true), + 'list' => $this->helper->url->to('TaskListController', 'show', array('project_id' => $this->project['id']), '', true), + ); + } + + return $this->project; + } +} diff --git a/app/Formatter/ProjectGanttFormatter.php b/app/Formatter/ProjectGanttFormatter.php deleted file mode 100644 index af04f498..00000000 --- a/app/Formatter/ProjectGanttFormatter.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php - -namespace Kanboard\Formatter; - -use Kanboard\Core\Filter\FormatterInterface; - -/** - * Gantt chart formatter for projects - * - * @package formatter - * @author Frederic Guillot - */ -class ProjectGanttFormatter extends BaseFormatter implements FormatterInterface -{ - /** - * Format projects to be displayed in the Gantt chart - * - * @access public - * @return array - */ - public function format() - { - $projects = $this->query->findAll(); - $colors = $this->colorModel->getDefaultColors(); - $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('ProjectViewController', 'show', array('project_id' => $project['id'])), - 'board_link' => $this->helper->url->href('BoardViewController', 'show', array('project_id' => $project['id'])), - 'gantt_link' => $this->helper->url->href('TaskGanttController', 'show', array('project_id' => $project['id'])), - 'color' => $color, - 'not_defined' => empty($project['start_date']) || empty($project['end_date']), - 'users' => $this->projectUserRoleModel->getAllUsersGroupedByRole($project['id']), - ); - } - - return $bars; - } -} diff --git a/app/Formatter/ProjectsApiFormatter.php b/app/Formatter/ProjectsApiFormatter.php new file mode 100644 index 00000000..0bf97da4 --- /dev/null +++ b/app/Formatter/ProjectsApiFormatter.php @@ -0,0 +1,38 @@ +<?php + +namespace Kanboard\Formatter; + +use Kanboard\Core\Filter\FormatterInterface; + +/** + * Class ProjectsApiFormatter + * + * @package Kanboard\Formatter + */ +class ProjectsApiFormatter extends BaseFormatter implements FormatterInterface +{ + protected $projects = array(); + + public function withProjects($projects) + { + $this->projects = $projects; + return $this; + } + + /** + * Apply formatter + * + * @access public + * @return mixed + */ + public function format() + { + if (! empty($this->projects)) { + foreach ($this->projects as &$project) { + $project = $this->projectApiFormatter->withProject($project)->format(); + } + } + + return $this->projects; + } +} diff --git a/app/Formatter/TaskApiFormatter.php b/app/Formatter/TaskApiFormatter.php new file mode 100644 index 00000000..60840beb --- /dev/null +++ b/app/Formatter/TaskApiFormatter.php @@ -0,0 +1,37 @@ +<?php + +namespace Kanboard\Formatter; + +use Kanboard\Core\Filter\FormatterInterface; + +/** + * Class TaskApiFormatter + * + * @package Kanboard\Formatter + */ +class TaskApiFormatter extends BaseFormatter implements FormatterInterface +{ + protected $task = null; + + public function withTask($task) + { + $this->task = $task; + return $this; + } + + /** + * Apply formatter + * + * @access public + * @return mixed + */ + public function format() + { + if (! empty($this->task)) { + $this->task['url'] = $this->helper->url->to('TaskViewController', 'show', array('task_id' => $this->task['id'], 'project_id' => $this->task['project_id']), '', true); + $this->task['color'] = $this->colorModel->getColorProperties($this->task['color_id']); + } + + return $this->task; + } +} diff --git a/app/Formatter/TaskCalendarFormatter.php b/app/Formatter/TaskCalendarFormatter.php deleted file mode 100644 index 75d2a83e..00000000 --- a/app/Formatter/TaskCalendarFormatter.php +++ /dev/null @@ -1,74 +0,0 @@ -<?php - -namespace Kanboard\Formatter; - -use Kanboard\Core\Filter\FormatterInterface; - -/** - * Calendar event formatter for task filter - * - * @package formatter - * @author Frederic Guillot - */ -class TaskCalendarFormatter extends BaseTaskCalendarFormatter implements FormatterInterface -{ - /** - * Full day event flag - * - * @access private - * @var boolean - */ - private $fullDay = false; - - /** - * When called calendar events will be full day - * - * @access public - * @return FormatterInterface - */ - public function setFullDay() - { - $this->fullDay = true; - return $this; - } - - /** - * Transform tasks to calendar events - * - * @access public - * @return array - */ - public function format() - { - $events = array(); - - foreach ($this->query->findAll() as $task) { - $events[] = array( - 'timezoneParam' => $this->timezoneModel->getCurrentTimezone(), - 'id' => $task['id'], - 'title' => t('#%d', $task['id']).' '.$task['title'], - 'backgroundColor' => $this->colorModel->getBackgroundColor($task['color_id']), - 'borderColor' => $this->colorModel->getBorderColor($task['color_id']), - 'textColor' => 'black', - 'url' => $this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), - 'start' => date($this->getDateTimeFormat(), $task[$this->startColumn]), - 'end' => date($this->getDateTimeFormat(), $task[$this->endColumn] ?: time()), - 'editable' => $this->fullDay, - 'allday' => $this->fullDay, - ); - } - - return $events; - } - - /** - * Get DateTime format for event - * - * @access private - * @return string - */ - private function getDateTimeFormat() - { - return $this->fullDay ? 'Y-m-d' : 'Y-m-d\TH:i:s'; - } -} diff --git a/app/Formatter/TaskGanttFormatter.php b/app/Formatter/TaskGanttFormatter.php deleted file mode 100644 index ddb3f93a..00000000 --- a/app/Formatter/TaskGanttFormatter.php +++ /dev/null @@ -1,78 +0,0 @@ -<?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->columnModel->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->taskModel->getProgress($task, $this->columns[$task['project_id']]).'%', - 'link' => $this->helper->url->href('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), - 'color' => $this->colorModel->getColorProperties($task['color_id']), - 'not_defined' => empty($task['date_due']) || empty($task['date_started']), - ); - } -} diff --git a/app/Formatter/TaskICalFormatter.php b/app/Formatter/TaskICalFormatter.php index ad2a4449..387074e5 100644 --- a/app/Formatter/TaskICalFormatter.php +++ b/app/Formatter/TaskICalFormatter.php @@ -8,6 +8,7 @@ use Eluceo\iCal\Component\Event; use Eluceo\iCal\Property\Event\Attendees; use Eluceo\iCal\Property\Event\Organizer; use Kanboard\Core\Filter\FormatterInterface; +use PicoDb\Table; /** * iCal event formatter for tasks @@ -15,15 +16,15 @@ use Kanboard\Core\Filter\FormatterInterface; * @package formatter * @author Frederic Guillot */ -class TaskICalFormatter extends BaseTaskCalendarFormatter implements FormatterInterface +class TaskICalFormatter extends BaseFormatter implements FormatterInterface { /** * Calendar object * - * @access private + * @access protected * @var \Eluceo\iCal\Component\Calendar */ - private $vCalendar; + protected $vCalendar; /** * Get Ical events @@ -41,7 +42,7 @@ class TaskICalFormatter extends BaseTaskCalendarFormatter implements FormatterIn * * @access public * @param \Eluceo\iCal\Component\Calendar $vCalendar - * @return FormatterInterface + * @return $this */ public function setCalendar(Calendar $vCalendar) { @@ -53,18 +54,21 @@ class TaskICalFormatter extends BaseTaskCalendarFormatter implements FormatterIn * Transform results to iCal events * * @access public - * @return FormatterInterface + * @param Table $query + * @param string $startColumn + * @param string $endColumn + * @return $this */ - public function addDateTimeEvents() + public function addTasksWithStartAndDueDate(Table $query, $startColumn, $endColumn) { - foreach ($this->query->findAll() as $task) { + foreach ($query->findAll() as $task) { $start = new DateTime; - $start->setTimestamp($task[$this->startColumn]); + $start->setTimestamp($task[$startColumn]); $end = new DateTime; - $end->setTimestamp($task[$this->endColumn] ?: time()); + $end->setTimestamp($task[$endColumn] ?: time()); - $vEvent = $this->getTaskIcalEvent($task, 'task-#'.$task['id'].'-'.$this->startColumn.'-'.$this->endColumn); + $vEvent = $this->getTaskIcalEvent($task, 'task-#'.$task['id'].'-'.$startColumn.'-'.$endColumn); $vEvent->setDtStart($start); $vEvent->setDtEnd($end); @@ -78,18 +82,22 @@ class TaskICalFormatter extends BaseTaskCalendarFormatter implements FormatterIn * Transform results to all day iCal events * * @access public - * @return FormatterInterface + * @param Table $query + * @return $this */ - public function addFullDayEvents() + public function addTasksWithDueDateOnly(Table $query) { - foreach ($this->query->findAll() as $task) { + foreach ($query->findAll() as $task) { $date = new DateTime; - $date->setTimestamp($task[$this->startColumn]); + $date->setTimestamp($task['date_due']); - $vEvent = $this->getTaskIcalEvent($task, 'task-#'.$task['id'].'-'.$this->startColumn); + $vEvent = $this->getTaskIcalEvent($task, 'task-#'.$task['id'].'-date_due'); $vEvent->setDtStart($date); $vEvent->setDtEnd($date); - $vEvent->setNoTime(true); + + if ($date->format('Hi') === '0000') { + $vEvent->setNoTime(true); + } $this->vCalendar->addComponent($vEvent); } diff --git a/app/Formatter/TaskListSubtaskAssigneeFormatter.php b/app/Formatter/TaskListSubtaskAssigneeFormatter.php new file mode 100644 index 00000000..73391766 --- /dev/null +++ b/app/Formatter/TaskListSubtaskAssigneeFormatter.php @@ -0,0 +1,56 @@ +<?php + +namespace Kanboard\Formatter; + +/** + * Class TaskListSubtaskAssigneeFormatter + * + * @package Kanboard\Formatter + * @author Frederic Guillot + */ +class TaskListSubtaskAssigneeFormatter extends TaskListFormatter +{ + protected $userId = 0; + protected $withoutEmptyTasks = false; + + /** + * Set assignee + * + * @param integer $userId + * @return $this + */ + public function withUserId($userId) + { + $this->userId = $userId; + return $this; + } + + public function withoutEmptyTasks() + { + $this->withoutEmptyTasks = true; + return $this; + } + + /** + * Apply formatter + * + * @access public + * @return array + */ + public function format() + { + $tasks = parent::format(); + $taskIds = array_column($tasks, 'id'); + $subtasks = $this->subtaskModel->getAllByTaskIdsAndAssignee($taskIds, $this->userId); + $subtasks = array_column_index($subtasks, 'task_id'); + array_merge_relation($tasks, $subtasks, 'subtasks', 'id'); + + if ($this->withoutEmptyTasks) { + $tasks = array_filter($tasks, function (array $task) { + return count($task['subtasks']) > 0; + }); + } + + return $tasks; + } +} diff --git a/app/Formatter/TasksApiFormatter.php b/app/Formatter/TasksApiFormatter.php new file mode 100644 index 00000000..95b14095 --- /dev/null +++ b/app/Formatter/TasksApiFormatter.php @@ -0,0 +1,38 @@ +<?php + +namespace Kanboard\Formatter; + +use Kanboard\Core\Filter\FormatterInterface; + +/** + * Class TasksApiFormatter + * + * @package Kanboard\Formatter + */ +class TasksApiFormatter extends BaseFormatter implements FormatterInterface +{ + protected $tasks = array(); + + public function withTasks($tasks) + { + $this->tasks = $tasks; + return $this; + } + + /** + * Apply formatter + * + * @access public + * @return mixed + */ + public function format() + { + if (! empty($this->tasks)) { + foreach ($this->tasks as &$task) { + $task = $this->taskApiFormatter->withTask($task)->format(); + } + } + + return $this->tasks; + } +} diff --git a/app/Formatter/UserAutoCompleteFormatter.php b/app/Formatter/UserAutoCompleteFormatter.php index c81af00a..aa02cd22 100644 --- a/app/Formatter/UserAutoCompleteFormatter.php +++ b/app/Formatter/UserAutoCompleteFormatter.php @@ -2,37 +2,59 @@ namespace Kanboard\Formatter; -use Kanboard\Model\UserModel; +use Kanboard\Core\User\UserProviderInterface; use Kanboard\Core\Filter\FormatterInterface; /** - * Auto-complete formatter for user filter + * Auto-complete formatter for users * - * @package formatter + * @package Kanboard\Formatter * @author Frederic Guillot */ class UserAutoCompleteFormatter extends BaseFormatter implements FormatterInterface { /** - * Format the tasks for the ajax auto-completion + * Users found + * + * @access protected + * @var UserProviderInterface[] + */ + protected $users; + + /** + * Set users + * + * @access public + * @param UserProviderInterface[] $users + * @return $this + */ + public function withUsers(array $users) + { + $this->users = $users; + return $this; + } + + /** + * Format the users for the ajax auto-completion * * @access public * @return array */ public function format() { - $users = $this->query->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name')->findAll(); + $result = array(); - foreach ($users as &$user) { - if (empty($user['name'])) { - $user['value'] = $user['username'].' (#'.$user['id'].')'; - $user['label'] = $user['username']; - } else { - $user['value'] = $user['name'].' (#'.$user['id'].')'; - $user['label'] = $user['name'].' ('.$user['username'].')'; - } + foreach ($this->users as $user) { + $result[] = array( + 'id' => $user->getInternalId(), + 'username' => $user->getUsername(), + 'external_id' => $user->getExternalId(), + 'external_id_column' => $user->getExternalIdColumn(), + 'value' => $user->getName() === '' ? $user->getUsername() : $user->getName(), + 'label' => $user->getName() === '' ? $user->getUsername() : $user->getName().' ('.$user->getUsername().')', + ); } - return $users; + return $result; } } diff --git a/app/Formatter/UserMentionFormatter.php b/app/Formatter/UserMentionFormatter.php index 395fc463..9ea76881 100644 --- a/app/Formatter/UserMentionFormatter.php +++ b/app/Formatter/UserMentionFormatter.php @@ -2,13 +2,15 @@ namespace Kanboard\Formatter; +use Kanboard\Core\Filter\FormatterInterface; + /** * Class UserMentionFormatter * * @package Kanboard\Formatter * @author Frederic Guillot */ -class UserMentionFormatter extends BaseFormatter +class UserMentionFormatter extends BaseFormatter implements FormatterInterface { protected $users = array(); |