Add formatters
This commit is contained in:
@@ -120,26 +120,6 @@ abstract class Base extends \Core\Base
|
||||
return $start_column.' IS NOT NULL AND '.$start_column.' > 0 AND ('.implode(' OR ', $conditions).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get common properties for task calendar events
|
||||
*
|
||||
* @access protected
|
||||
* @param array $task
|
||||
* @return array
|
||||
*/
|
||||
protected function getTaskCalendarProperties(array &$task)
|
||||
{
|
||||
return array(
|
||||
'timezoneParam' => $this->config->getCurrentTimezone(),
|
||||
'id' => $task['id'],
|
||||
'title' => t('#%d', $task['id']).' '.$task['title'],
|
||||
'backgroundColor' => $this->color->getBackgroundColor($task['color_id']),
|
||||
'borderColor' => $this->color->getBorderColor($task['color_id']),
|
||||
'textColor' => 'black',
|
||||
'url' => $this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Group a collection of records by a column
|
||||
*
|
||||
|
||||
@@ -114,54 +114,6 @@ class Project extends Base
|
||||
return $this->db->table(self::TABLE)->eq('id', $project_id)->eq('is_private', 1)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects to generate the Gantt chart
|
||||
*
|
||||
* @access public
|
||||
* @param array $project_ids
|
||||
* @return array
|
||||
*/
|
||||
public function getGanttBars(array $project_ids)
|
||||
{
|
||||
if (empty($project_ids)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$colors = $this->color->getDefaultColors();
|
||||
$projects = $this->db->table(self::TABLE)->asc('start_date')->in('id', $project_ids)->eq('is_active', self::ACTIVE)->eq('is_private', 0)->findAll();
|
||||
$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('project', 'show', array('project_id' => $project['id'])),
|
||||
'board_link' => $this->helper->url->href('board', 'show', array('project_id' => $project['id'])),
|
||||
'gantt_link' => $this->helper->url->href('gantt', 'project', array('project_id' => $project['id'])),
|
||||
'color' => $color,
|
||||
'not_defined' => empty($project['start_date']) || empty($project['end_date']),
|
||||
'users' => $this->projectPermission->getProjectUsers($project['id']),
|
||||
);
|
||||
}
|
||||
|
||||
return $bars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
*
|
||||
|
||||
@@ -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