Filter refactoring

This commit is contained in:
Frederic Guillot
2016-04-09 22:42:17 -04:00
parent 42813d702d
commit 11858be4e8
101 changed files with 3235 additions and 2841 deletions

View File

@@ -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;
}
}

View File

@@ -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
@@ -28,21 +28,13 @@ 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;
}
}

View File

@@ -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;
});
});
}
}

View File

@@ -1,14 +0,0 @@
<?php
namespace Kanboard\Formatter;
/**
* Formatter Interface
*
* @package formatter
* @author Frederic Guillot
*/
interface FormatterInterface
{
public function format();
}

View File

@@ -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

View File

@@ -2,7 +2,7 @@
namespace Kanboard\Formatter;
use Kanboard\Model\Project;
use Kanboard\Core\Filter\FormatterInterface;
/**
* Gantt chart formatter for projects
@@ -10,40 +10,8 @@ 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
*
@@ -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);

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -2,14 +2,36 @@
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
*
@@ -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';
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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