diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-04-09 22:42:17 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-04-09 22:42:17 -0400 |
commit | 11858be4e8d5aba983700c6cba1c4d0a33ea8e9d (patch) | |
tree | 38427e86d52185df95e2b891e4bcd50aeb56eeb9 /app/Formatter | |
parent | 42813d702d1c3e5659301bc771f8dbb37a6d15cd (diff) |
Filter refactoring
Diffstat (limited to 'app/Formatter')
-rw-r--r-- | app/Formatter/BaseFormatter.php | 37 | ||||
-rw-r--r-- | app/Formatter/BaseTaskCalendarFormatter.php (renamed from app/Formatter/TaskFilterCalendarEvent.php) | 37 | ||||
-rw-r--r-- | app/Formatter/BoardFormatter.php | 56 | ||||
-rw-r--r-- | app/Formatter/FormatterInterface.php | 14 | ||||
-rw-r--r-- | app/Formatter/GroupAutoCompleteFormatter.php | 28 | ||||
-rw-r--r-- | app/Formatter/ProjectGanttFormatter.php | 39 | ||||
-rw-r--r-- | app/Formatter/SubtaskTimeTrackingCalendarFormatter.php | 38 | ||||
-rw-r--r-- | app/Formatter/TaskAutoCompleteFormatter.php (renamed from app/Formatter/TaskFilterAutoCompleteFormatter.php) | 12 | ||||
-rw-r--r-- | app/Formatter/TaskCalendarFormatter.php (renamed from app/Formatter/TaskFilterCalendarFormatter.php) | 30 | ||||
-rw-r--r-- | app/Formatter/TaskGanttFormatter.php (renamed from app/Formatter/TaskFilterGanttFormatter.php) | 14 | ||||
-rw-r--r-- | app/Formatter/TaskICalFormatter.php (renamed from app/Formatter/TaskFilterICalendarFormatter.php) | 17 | ||||
-rw-r--r-- | app/Formatter/UserAutoCompleteFormatter.php (renamed from app/Formatter/UserFilterAutoCompleteFormatter.php) | 6 |
12 files changed, 210 insertions, 118 deletions
diff --git a/app/Formatter/BaseFormatter.php b/app/Formatter/BaseFormatter.php new file mode 100644 index 00000000..a9f0ad15 --- /dev/null +++ b/app/Formatter/BaseFormatter.php @@ -0,0 +1,37 @@ +<?php + +namespace Kanboard\Formatter; + +use Kanboard\Core\Base; +use Kanboard\Core\Filter\FormatterInterface; +use PicoDb\Table; + +/** + * Class BaseFormatter + * + * @package formatter + * @author Frederic Guillot + */ +abstract class BaseFormatter extends Base +{ + /** + * Query object + * + * @access protected + * @var Table + */ + protected $query; + + /** + * Set query + * + * @access public + * @param Table $query + * @return FormatterInterface + */ + public function withQuery(Table $query) + { + $this->query = $query; + return $this; + } +} diff --git a/app/Formatter/TaskFilterCalendarEvent.php b/app/Formatter/BaseTaskCalendarFormatter.php index 12ea8687..8fab3e9a 100644 --- a/app/Formatter/TaskFilterCalendarEvent.php +++ b/app/Formatter/BaseTaskCalendarFormatter.php @@ -2,7 +2,7 @@ namespace Kanboard\Formatter; -use Kanboard\Model\TaskFilter; +use Kanboard\Core\Filter\FormatterInterface; /** * Common class to handle calendar events @@ -10,7 +10,7 @@ use Kanboard\Model\TaskFilter; * @package formatter * @author Frederic Guillot */ -abstract class TaskFilterCalendarEvent extends TaskFilter +abstract class BaseTaskCalendarFormatter extends BaseFormatter { /** * Column used for event start date @@ -29,20 +29,12 @@ abstract class TaskFilterCalendarEvent extends TaskFilter protected $endColumn = 'date_completed'; /** - * Full day event flag - * - * @access private - * @var boolean - */ - private $fullDay = false; - - /** * 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 TaskFilterCalendarEvent + * @return FormatterInterface */ public function setColumns($start_column, $end_column = '') { @@ -50,27 +42,4 @@ abstract class TaskFilterCalendarEvent extends TaskFilter $this->endColumn = $end_column ?: $start_column; return $this; } - - /** - * When called calendar events will be full day - * - * @access public - * @return TaskFilterCalendarEvent - */ - public function setFullDay() - { - $this->fullDay = true; - return $this; - } - - /** - * Return true if the events are full day - * - * @access public - * @return boolean - */ - public function isFullDay() - { - return $this->fullDay; - } } diff --git a/app/Formatter/BoardFormatter.php b/app/Formatter/BoardFormatter.php new file mode 100644 index 00000000..6a96b3e6 --- /dev/null +++ b/app/Formatter/BoardFormatter.php @@ -0,0 +1,56 @@ +<?php + +namespace Kanboard\Formatter; + +use Kanboard\Core\Filter\FormatterInterface; +use Kanboard\Model\Task; + +/** + * Board Formatter + * + * @package formatter + * @author Frederic Guillot + */ +class BoardFormatter extends BaseFormatter implements FormatterInterface +{ + /** + * Project id + * + * @access protected + * @var integer + */ + protected $projectId; + + /** + * Set ProjectId + * + * @access public + * @param integer $projectId + * @return $this + */ + public function setProjectId($projectId) + { + $this->projectId = $projectId; + return $this; + } + + /** + * Apply formatter + * + * @access public + * @return array + */ + public function format() + { + $tasks = $this->query + ->eq(Task::TABLE.'.project_id', $this->projectId) + ->asc(Task::TABLE.'.position') + ->findAll(); + + return $this->board->getBoard($this->projectId, function ($project_id, $column_id, $swimlane_id) use ($tasks) { + return array_filter($tasks, function (array $task) use ($column_id, $swimlane_id) { + return $task['column_id'] == $column_id && $task['swimlane_id'] == $swimlane_id; + }); + }); + } +} diff --git a/app/Formatter/FormatterInterface.php b/app/Formatter/FormatterInterface.php deleted file mode 100644 index 0bb61292..00000000 --- a/app/Formatter/FormatterInterface.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -namespace Kanboard\Formatter; - -/** - * Formatter Interface - * - * @package formatter - * @author Frederic Guillot - */ -interface FormatterInterface -{ - public function format(); -} diff --git a/app/Formatter/GroupAutoCompleteFormatter.php b/app/Formatter/GroupAutoCompleteFormatter.php index 7023e367..4d552886 100644 --- a/app/Formatter/GroupAutoCompleteFormatter.php +++ b/app/Formatter/GroupAutoCompleteFormatter.php @@ -2,8 +2,12 @@ namespace Kanboard\Formatter; +use Kanboard\Core\Filter\FormatterInterface; +use Kanboard\Core\Group\GroupProviderInterface; +use PicoDb\Table; + /** - * Autocomplete formatter for groups + * Auto-complete formatter for groups * * @package formatter * @author Frederic Guillot @@ -14,25 +18,35 @@ class GroupAutoCompleteFormatter implements FormatterInterface * Groups found * * @access private - * @var array + * @var GroupProviderInterface[] */ private $groups; /** - * Format groups for the ajax autocompletion + * Format groups for the ajax auto-completion * * @access public - * @param array $groups - * @return GroupAutoCompleteFormatter + * @param GroupProviderInterface[] $groups */ - public function setGroups(array $groups) + public function __construct(array $groups) { $this->groups = $groups; + } + + /** + * Set query + * + * @access public + * @param Table $query + * @return FormatterInterface + */ + public function withQuery(Table $query) + { return $this; } /** - * Format groups for the ajax autocompletion + * Format groups for the ajax auto-completion * * @access public * @return array diff --git a/app/Formatter/ProjectGanttFormatter.php b/app/Formatter/ProjectGanttFormatter.php index 4f73e217..aee1f27f 100644 --- a/app/Formatter/ProjectGanttFormatter.php +++ b/app/Formatter/ProjectGanttFormatter.php @@ -2,7 +2,7 @@ namespace Kanboard\Formatter; -use Kanboard\Model\Project; +use Kanboard\Core\Filter\FormatterInterface; /** * Gantt chart formatter for projects @@ -10,41 +10,9 @@ use Kanboard\Model\Project; * @package formatter * @author Frederic Guillot */ -class ProjectGanttFormatter extends Project implements FormatterInterface +class ProjectGanttFormatter extends BaseFormatter implements FormatterInterface { /** - * List of projects - * - * @access private - * @var array - */ - private $projects = array(); - - /** - * Filter projects to generate the Gantt chart - * - * @access public - * @param int[] $project_ids - * @return ProjectGanttFormatter - */ - public function filter(array $project_ids) - { - if (empty($project_ids)) { - $this->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 @@ -52,10 +20,11 @@ class ProjectGanttFormatter extends Project implements FormatterInterface */ public function format() { + $projects = $this->query->findAll(); $colors = $this->color->getDefaultColors(); $bars = array(); - foreach ($this->projects as $project) { + 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); diff --git a/app/Formatter/SubtaskTimeTrackingCalendarFormatter.php b/app/Formatter/SubtaskTimeTrackingCalendarFormatter.php new file mode 100644 index 00000000..c5d4e2be --- /dev/null +++ b/app/Formatter/SubtaskTimeTrackingCalendarFormatter.php @@ -0,0 +1,38 @@ +<?php + +namespace Kanboard\Formatter; + +use Kanboard\Core\Filter\FormatterInterface; + +class SubtaskTimeTrackingCalendarFormatter extends BaseFormatter implements FormatterInterface +{ + /** + * Format calendar events + * + * @access public + * @return array + */ + public function format() + { + $events = array(); + + foreach ($this->query->findAll() as $row) { + $user = isset($row['username']) ? ' ('.($row['user_fullname'] ?: $row['username']).')' : ''; + + $events[] = array( + 'id' => $row['id'], + 'subtask_id' => $row['subtask_id'], + 'title' => t('#%d', $row['task_id']).' '.$row['subtask_title'].$user, + 'start' => date('Y-m-d\TH:i:s', $row['start']), + 'end' => date('Y-m-d\TH:i:s', $row['end'] ?: time()), + 'backgroundColor' => $this->color->getBackgroundColor($row['color_id']), + 'borderColor' => $this->color->getBorderColor($row['color_id']), + 'textColor' => 'black', + 'url' => $this->helper->url->to('task', 'show', array('task_id' => $row['task_id'], 'project_id' => $row['project_id'])), + 'editable' => false, + ); + } + + return $events; + } +} diff --git a/app/Formatter/TaskFilterAutoCompleteFormatter.php b/app/Formatter/TaskAutoCompleteFormatter.php index c9af4654..480ee797 100644 --- a/app/Formatter/TaskFilterAutoCompleteFormatter.php +++ b/app/Formatter/TaskAutoCompleteFormatter.php @@ -2,19 +2,19 @@ namespace Kanboard\Formatter; +use Kanboard\Core\Filter\FormatterInterface; use Kanboard\Model\Task; -use Kanboard\Model\TaskFilter; /** - * Autocomplete formatter for task filter + * Task AutoComplete Formatter * - * @package formatter - * @author Frederic Guillot + * @package formatter + * @author Frederic Guillot */ -class TaskFilterAutoCompleteFormatter extends TaskFilter implements FormatterInterface +class TaskAutoCompleteFormatter extends BaseFormatter implements FormatterInterface { /** - * Format the tasks for the ajax autocompletion + * Apply formatter * * @access public * @return array diff --git a/app/Formatter/TaskFilterCalendarFormatter.php b/app/Formatter/TaskCalendarFormatter.php index 1b5d6ca4..60b9a062 100644 --- a/app/Formatter/TaskFilterCalendarFormatter.php +++ b/app/Formatter/TaskCalendarFormatter.php @@ -2,15 +2,37 @@ namespace Kanboard\Formatter; +use Kanboard\Core\Filter\FormatterInterface; + /** * Calendar event formatter for task filter * * @package formatter * @author Frederic Guillot */ -class TaskFilterCalendarFormatter extends TaskFilterCalendarEvent implements FormatterInterface +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 @@ -31,8 +53,8 @@ class TaskFilterCalendarFormatter extends TaskFilterCalendarEvent implements For 'url' => $this->helper->url->to('task', '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->isFullDay(), - 'allday' => $this->isFullDay(), + 'editable' => $this->fullDay, + 'allday' => $this->fullDay, ); } @@ -47,6 +69,6 @@ class TaskFilterCalendarFormatter extends TaskFilterCalendarEvent implements For */ private function getDateTimeFormat() { - return $this->isFullDay() ? 'Y-m-d' : 'Y-m-d\TH:i:s'; + return $this->fullDay ? 'Y-m-d' : 'Y-m-d\TH:i:s'; } } diff --git a/app/Formatter/TaskFilterGanttFormatter.php b/app/Formatter/TaskGanttFormatter.php index a4eef1ee..3209aa37 100644 --- a/app/Formatter/TaskFilterGanttFormatter.php +++ b/app/Formatter/TaskGanttFormatter.php @@ -2,15 +2,15 @@ namespace Kanboard\Formatter; -use Kanboard\Model\TaskFilter; +use Kanboard\Core\Filter\FormatterInterface; /** - * Gantt chart formatter for task filter + * Task Gantt Formatter * - * @package formatter - * @author Frederic Guillot + * @package formatter + * @author Frederic Guillot */ -class TaskFilterGanttFormatter extends TaskFilter implements FormatterInterface +class TaskGanttFormatter extends BaseFormatter implements FormatterInterface { /** * Local cache for project columns @@ -19,9 +19,9 @@ class TaskFilterGanttFormatter extends TaskFilter implements FormatterInterface * @var array */ private $columns = array(); - + /** - * Format tasks to be displayed in the Gantt chart + * Apply formatter * * @access public * @return array diff --git a/app/Formatter/TaskFilterICalendarFormatter.php b/app/Formatter/TaskICalFormatter.php index 25b3aea0..a149f725 100644 --- a/app/Formatter/TaskFilterICalendarFormatter.php +++ b/app/Formatter/TaskICalFormatter.php @@ -6,14 +6,15 @@ use DateTime; use Eluceo\iCal\Component\Calendar; use Eluceo\iCal\Component\Event; use Eluceo\iCal\Property\Event\Attendees; +use Kanboard\Core\Filter\FormatterInterface; /** - * iCal event formatter for task filter + * iCal event formatter for tasks * * @package formatter * @author Frederic Guillot */ -class TaskFilterICalendarFormatter extends TaskFilterCalendarEvent implements FormatterInterface +class TaskICalFormatter extends BaseTaskCalendarFormatter implements FormatterInterface { /** * Calendar object @@ -39,7 +40,7 @@ class TaskFilterICalendarFormatter extends TaskFilterCalendarEvent implements Fo * * @access public * @param \Eluceo\iCal\Component\Calendar $vCalendar - * @return TaskFilterICalendarFormatter + * @return FormatterInterface */ public function setCalendar(Calendar $vCalendar) { @@ -48,10 +49,10 @@ class TaskFilterICalendarFormatter extends TaskFilterCalendarEvent implements Fo } /** - * Transform results to ical events + * Transform results to iCal events * * @access public - * @return TaskFilterICalendarFormatter + * @return FormatterInterface */ public function addDateTimeEvents() { @@ -73,10 +74,10 @@ class TaskFilterICalendarFormatter extends TaskFilterCalendarEvent implements Fo } /** - * Transform results to all day ical events + * Transform results to all day iCal events * * @access public - * @return TaskFilterICalendarFormatter + * @return FormatterInterface */ public function addFullDayEvents() { @@ -96,7 +97,7 @@ class TaskFilterICalendarFormatter extends TaskFilterCalendarEvent implements Fo } /** - * Get common events for task ical events + * Get common events for task iCal events * * @access protected * @param array $task diff --git a/app/Formatter/UserFilterAutoCompleteFormatter.php b/app/Formatter/UserAutoCompleteFormatter.php index b98e0d69..c46a24d0 100644 --- a/app/Formatter/UserFilterAutoCompleteFormatter.php +++ b/app/Formatter/UserAutoCompleteFormatter.php @@ -3,15 +3,15 @@ namespace Kanboard\Formatter; use Kanboard\Model\User; -use Kanboard\Model\UserFilter; +use Kanboard\Core\Filter\FormatterInterface; /** - * Autocomplete formatter for user filter + * Auto-complete formatter for user filter * * @package formatter * @author Frederic Guillot */ -class UserFilterAutoCompleteFormatter extends UserFilter implements FormatterInterface +class UserAutoCompleteFormatter extends BaseFormatter implements FormatterInterface { /** * Format the tasks for the ajax autocompletion |