First commit

This commit is contained in:
Frederic Guillot
2017-04-01 14:35:41 -04:00
commit ada7a33402
20 changed files with 623 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
<?php
namespace Kanboard\Plugin\Calendar\Formatter;
use Kanboard\Formatter\BaseFormatter;
/**
* 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;
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace Kanboard\Plugin\Calendar\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';
}
}