summaryrefslogtreecommitdiff
path: root/app/Formatter
diff options
context:
space:
mode:
Diffstat (limited to 'app/Formatter')
-rw-r--r--app/Formatter/BaseTaskCalendarFormatter.php43
-rw-r--r--app/Formatter/TaskICalFormatter.php40
2 files changed, 24 insertions, 59 deletions
diff --git a/app/Formatter/BaseTaskCalendarFormatter.php b/app/Formatter/BaseTaskCalendarFormatter.php
deleted file mode 100644
index 3d9ead4d..00000000
--- a/app/Formatter/BaseTaskCalendarFormatter.php
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-
-namespace Kanboard\Formatter;
-
-/**
- * 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;
- }
-}
diff --git a/app/Formatter/TaskICalFormatter.php b/app/Formatter/TaskICalFormatter.php
index ad2a4449..387074e5 100644
--- a/app/Formatter/TaskICalFormatter.php
+++ b/app/Formatter/TaskICalFormatter.php
@@ -8,6 +8,7 @@ use Eluceo\iCal\Component\Event;
use Eluceo\iCal\Property\Event\Attendees;
use Eluceo\iCal\Property\Event\Organizer;
use Kanboard\Core\Filter\FormatterInterface;
+use PicoDb\Table;
/**
* iCal event formatter for tasks
@@ -15,15 +16,15 @@ use Kanboard\Core\Filter\FormatterInterface;
* @package formatter
* @author Frederic Guillot
*/
-class TaskICalFormatter extends BaseTaskCalendarFormatter implements FormatterInterface
+class TaskICalFormatter extends BaseFormatter implements FormatterInterface
{
/**
* Calendar object
*
- * @access private
+ * @access protected
* @var \Eluceo\iCal\Component\Calendar
*/
- private $vCalendar;
+ protected $vCalendar;
/**
* Get Ical events
@@ -41,7 +42,7 @@ class TaskICalFormatter extends BaseTaskCalendarFormatter implements FormatterIn
*
* @access public
* @param \Eluceo\iCal\Component\Calendar $vCalendar
- * @return FormatterInterface
+ * @return $this
*/
public function setCalendar(Calendar $vCalendar)
{
@@ -53,18 +54,21 @@ class TaskICalFormatter extends BaseTaskCalendarFormatter implements FormatterIn
* Transform results to iCal events
*
* @access public
- * @return FormatterInterface
+ * @param Table $query
+ * @param string $startColumn
+ * @param string $endColumn
+ * @return $this
*/
- public function addDateTimeEvents()
+ public function addTasksWithStartAndDueDate(Table $query, $startColumn, $endColumn)
{
- foreach ($this->query->findAll() as $task) {
+ foreach ($query->findAll() as $task) {
$start = new DateTime;
- $start->setTimestamp($task[$this->startColumn]);
+ $start->setTimestamp($task[$startColumn]);
$end = new DateTime;
- $end->setTimestamp($task[$this->endColumn] ?: time());
+ $end->setTimestamp($task[$endColumn] ?: time());
- $vEvent = $this->getTaskIcalEvent($task, 'task-#'.$task['id'].'-'.$this->startColumn.'-'.$this->endColumn);
+ $vEvent = $this->getTaskIcalEvent($task, 'task-#'.$task['id'].'-'.$startColumn.'-'.$endColumn);
$vEvent->setDtStart($start);
$vEvent->setDtEnd($end);
@@ -78,18 +82,22 @@ class TaskICalFormatter extends BaseTaskCalendarFormatter implements FormatterIn
* Transform results to all day iCal events
*
* @access public
- * @return FormatterInterface
+ * @param Table $query
+ * @return $this
*/
- public function addFullDayEvents()
+ public function addTasksWithDueDateOnly(Table $query)
{
- foreach ($this->query->findAll() as $task) {
+ foreach ($query->findAll() as $task) {
$date = new DateTime;
- $date->setTimestamp($task[$this->startColumn]);
+ $date->setTimestamp($task['date_due']);
- $vEvent = $this->getTaskIcalEvent($task, 'task-#'.$task['id'].'-'.$this->startColumn);
+ $vEvent = $this->getTaskIcalEvent($task, 'task-#'.$task['id'].'-date_due');
$vEvent->setDtStart($date);
$vEvent->setDtEnd($date);
- $vEvent->setNoTime(true);
+
+ if ($date->format('Hi') === '0000') {
+ $vEvent->setNoTime(true);
+ }
$this->vCalendar->addComponent($vEvent);
}