Add formatters
This commit is contained in:
@@ -2,11 +2,6 @@
|
||||
|
||||
namespace Model;
|
||||
|
||||
use DateTime;
|
||||
use Eluceo\iCal\Component\Calendar;
|
||||
use Eluceo\iCal\Component\Event;
|
||||
use Eluceo\iCal\Property\Event\Attendees;
|
||||
|
||||
/**
|
||||
* Task Filter
|
||||
*
|
||||
@@ -137,7 +132,7 @@ class TaskFilter extends Base
|
||||
*/
|
||||
public function copy()
|
||||
{
|
||||
$filter = clone($this);
|
||||
$filter = new static($this->container);
|
||||
$filter->query = clone($this->query);
|
||||
$filter->query->condition = clone($this->query->condition);
|
||||
return $filter;
|
||||
@@ -674,223 +669,6 @@ class TaskFilter extends Base
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Format tasks to be displayed in the Gantt chart
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function toGanttBars()
|
||||
{
|
||||
$bars = array();
|
||||
$columns = array();
|
||||
|
||||
foreach ($this->query->findAll() as $task) {
|
||||
if (! isset($column_count[$task['project_id']])) {
|
||||
$columns[$task['project_id']] = $this->board->getColumnsList($task['project_id']);
|
||||
}
|
||||
|
||||
$start = $task['date_started'] ?: time();
|
||||
$end = $task['date_due'] ?: $start;
|
||||
|
||||
$bars[] = 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, $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']),
|
||||
);
|
||||
}
|
||||
|
||||
return $bars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the results to the ajax autocompletion
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function toAutoCompletion()
|
||||
{
|
||||
return $this->query->columns(Task::TABLE.'.id', Task::TABLE.'.title')->callback(function(array $results) {
|
||||
|
||||
foreach ($results as &$result) {
|
||||
$result['value'] = $result['title'];
|
||||
$result['label'] = '#'.$result['id'].' - '.$result['title'];
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
||||
})->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 array
|
||||
*/
|
||||
public function toDateTimeCalendarEvents($start_column, $end_column)
|
||||
{
|
||||
$events = array();
|
||||
|
||||
foreach ($this->query->findAll() as $task) {
|
||||
|
||||
$events[] = array_merge(
|
||||
$this->getTaskCalendarProperties($task),
|
||||
array(
|
||||
'start' => date('Y-m-d\TH:i:s', $task[$start_column]),
|
||||
'end' => date('Y-m-d\TH:i:s', $task[$end_column] ?: time()),
|
||||
'editable' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform results to all day calendar events
|
||||
*
|
||||
* @access public
|
||||
* @param string $column Column name for the date
|
||||
* @return array
|
||||
*/
|
||||
public function toAllDayCalendarEvents($column = 'date_due')
|
||||
{
|
||||
$events = array();
|
||||
|
||||
foreach ($this->query->findAll() as $task) {
|
||||
|
||||
$events[] = array_merge(
|
||||
$this->getTaskCalendarProperties($task),
|
||||
array(
|
||||
'start' => date('Y-m-d', $task[$column]),
|
||||
'end' => date('Y-m-d', $task[$column]),
|
||||
'allday' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform results to ical events
|
||||
*
|
||||
* @access public
|
||||
* @param string $start_column Column name for the start date
|
||||
* @param string $end_column Column name for the end date
|
||||
* @param Calendar $vCalendar Calendar object
|
||||
* @return Calendar
|
||||
*/
|
||||
public function addDateTimeIcalEvents($start_column, $end_column, Calendar $vCalendar = null)
|
||||
{
|
||||
if ($vCalendar === null) {
|
||||
$vCalendar = new Calendar('Kanboard');
|
||||
}
|
||||
|
||||
foreach ($this->query->findAll() as $task) {
|
||||
|
||||
$start = new DateTime;
|
||||
$start->setTimestamp($task[$start_column]);
|
||||
|
||||
$end = new DateTime;
|
||||
$end->setTimestamp($task[$end_column] ?: time());
|
||||
|
||||
$vEvent = $this->getTaskIcalEvent($task, 'task-#'.$task['id'].'-'.$start_column.'-'.$end_column);
|
||||
$vEvent->setDtStart($start);
|
||||
$vEvent->setDtEnd($end);
|
||||
|
||||
$vCalendar->addComponent($vEvent);
|
||||
}
|
||||
|
||||
return $vCalendar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform results to all day ical events
|
||||
*
|
||||
* @access public
|
||||
* @param string $column Column name for the date
|
||||
* @param Calendar $vCalendar Calendar object
|
||||
* @return Calendar
|
||||
*/
|
||||
public function addAllDayIcalEvents($column = 'date_due', Calendar $vCalendar = null)
|
||||
{
|
||||
if ($vCalendar === null) {
|
||||
$vCalendar = new Calendar('Kanboard');
|
||||
}
|
||||
|
||||
foreach ($this->query->findAll() as $task) {
|
||||
|
||||
$date = new DateTime;
|
||||
$date->setTimestamp($task[$column]);
|
||||
|
||||
$vEvent = $this->getTaskIcalEvent($task, 'task-#'.$task['id'].'-'.$column);
|
||||
$vEvent->setDtStart($date);
|
||||
$vEvent->setDtEnd($date);
|
||||
$vEvent->setNoTime(true);
|
||||
|
||||
$vCalendar->addComponent($vEvent);
|
||||
}
|
||||
|
||||
return $vCalendar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get common events for task ical events
|
||||
*
|
||||
* @access protected
|
||||
* @param array $task
|
||||
* @param string $uid
|
||||
* @return Event
|
||||
*/
|
||||
protected function getTaskIcalEvent(array &$task, $uid)
|
||||
{
|
||||
$dateCreation = new DateTime;
|
||||
$dateCreation->setTimestamp($task['date_creation']);
|
||||
|
||||
$dateModif = new DateTime;
|
||||
$dateModif->setTimestamp($task['date_modification']);
|
||||
|
||||
$vEvent = new Event($uid);
|
||||
$vEvent->setCreated($dateCreation);
|
||||
$vEvent->setModified($dateModif);
|
||||
$vEvent->setUseTimezone(true);
|
||||
$vEvent->setSummary(t('#%d', $task['id']).' '.$task['title']);
|
||||
$vEvent->setUrl($this->helper->url->base().$this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])));
|
||||
|
||||
if (! empty($task['owner_id'])) {
|
||||
$vEvent->setOrganizer($task['assignee_name'] ?: $task['assignee_username'], $task['assignee_email']);
|
||||
}
|
||||
|
||||
if (! empty($task['creator_id'])) {
|
||||
$attendees = new Attendees;
|
||||
$attendees->add('MAILTO:'.($task['creator_email'] ?: $task['creator_username'].'@kanboard.local'));
|
||||
$vEvent->setAttendees($attendees);
|
||||
}
|
||||
|
||||
return $vEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter with an operator
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user