From 5905bf4974e47cae816d13576c6bcfa9e959cd56 Mon Sep 17 00:00:00 2001 From: Baudouin Feildel Date: Fri, 2 Mar 2018 15:30:26 +0100 Subject: [PATCH] Use completion or due date for the event end --- Controller/CalendarController.php | 17 +++++++-------- Formatter/TaskCalendarFormatter.php | 32 +++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/Controller/CalendarController.php b/Controller/CalendarController.php index 94a1e5e..1a03cea 100644 --- a/Controller/CalendarController.php +++ b/Controller/CalendarController.php @@ -56,10 +56,10 @@ class CalendarController extends BaseController $startAndDueDateQueryBuilder ->getQuery() - ->addCondition($this->getConditionForTasksWithStartAndDueDate($startRange, $endRange, $startColumn, 'date_due')); + ->addCondition($this->getConditionForTasksWithStartAndDueDate($startRange, $endRange, $startColumn, 'date_due', 'date_completed')); $startAndDueDateEvents = $startAndDueDateQueryBuilder - ->format($this->taskCalendarFormatter->setColumns($startColumn, 'date_due')); + ->format($this->taskCalendarFormatter->setColumns($startColumn, 'date_due', 'date_completed')); $events = array_merge($dueDateOnlyEvents, $startAndDueDateEvents); @@ -91,10 +91,10 @@ class CalendarController extends BaseController $startAndDueDateQueryBuilder ->getQuery() - ->addCondition($this->getConditionForTasksWithStartAndDueDate($startRange, $endRange, $startColumn, 'date_due')); + ->addCondition($this->getConditionForTasksWithStartAndDueDate($startRange, $endRange, $startColumn, 'date_due', 'date_completed')); $startAndDueDateEvents = $startAndDueDateQueryBuilder - ->format($this->taskCalendarFormatter->setColumns($startColumn, 'date_due')); + ->format($this->taskCalendarFormatter->setColumns($startColumn, 'date_due', 'date_completed')); $events = array_merge($dueDateOnlyEvents, $startAndDueDateEvents); @@ -119,17 +119,18 @@ class CalendarController extends BaseController } } - protected function getConditionForTasksWithStartAndDueDate($startTime, $endTime, $startColumn, $endColumn) + protected function getConditionForTasksWithStartAndDueDate($startTime, $endTime, $startColumn, $expectedEndColumn, $effectiveEndColumn) { $startTime = strtotime($startTime); $endTime = strtotime($endTime); $startColumn = $this->db->escapeIdentifier($startColumn); - $endColumn = $this->db->escapeIdentifier($endColumn); + $expectedEndColumn = $this->db->escapeIdentifier($expectedEndColumn); + $effectiveEndColumn = $this->db->escapeIdentifier($effectiveEndColumn); $conditions = array( "($startColumn >= '$startTime' AND $startColumn <= '$endTime')", - "($startColumn <= '$startTime' AND $endColumn >= '$startTime')", - "($startColumn <= '$startTime' AND ($endColumn = '0' OR $endColumn IS NULL))", + "($startColumn <= '$startTime' AND ($expectedEndColumn >= '$startTime' OR $effectiveEndColumn >= '$startTime'))", + "($startColumn <= '$startTime' AND ($expectedEndColumn = '0' OR $expectedEndColumn IS NULL) AND ($effectiveEndColumn = '0' OR $effectiveEndColumn IS NULL))", ); return $startColumn.' IS NOT NULL AND '.$startColumn.' > 0 AND ('.implode(' OR ', $conditions).')'; diff --git a/Formatter/TaskCalendarFormatter.php b/Formatter/TaskCalendarFormatter.php index 9286eaf..c61e16d 100644 --- a/Formatter/TaskCalendarFormatter.php +++ b/Formatter/TaskCalendarFormatter.php @@ -23,25 +23,35 @@ class TaskCalendarFormatter extends BaseFormatter implements FormatterInterface protected $startColumn = ''; /** - * Column used for event end date + * Column used for event expected end date * * @access protected * @var string */ - protected $endColumn = ''; + protected $expectedEndColumn = ''; + + /** + * Column used for event effective end date + * + * @access protected + * @var string + */ + protected $effectiveEndColumn = ''; /** * 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 + * @param string $start_column Column name for the start date + * @param string $expected_end_column Column name for the expected end date + * @param string $effective_end_column Column name for the effective end date * @return $this */ - public function setColumns($start_column, $end_column = '') + public function setColumns($start_column, $expected_end_column = '', $effective_end_column = '') { $this->startColumn = $start_column; - $this->endColumn = $end_column ?: $start_column; + $this->expectedEndColumn = $expected_end_column ?: $start_column; + $this->effectiveEndColumn = $effective_end_column ?: $this->expectedEndColumn; return $this; } @@ -60,8 +70,14 @@ class TaskCalendarFormatter extends BaseFormatter implements FormatterInterface $startDate->setTimestamp($task[$this->startColumn]); $endDate = new DateTime(); - if (! empty($task[$this->endColumn])) { - $endDate->setTimestamp($task[$this->endColumn]); + if (! empty($task[$this->expectedEndColumn])) { + $endDate->setTimestamp($task[$this->expectedEndColumn]); + } + + if ($this->expectedEndColumn != $this->effectiveEndColumn && + ! empty($task[$this->effectiveEndColumn]) && + $task[$this->effectiveEndColumn] != $task[$this->expectedEndColumn]) { + $endDate->setTimestamp($task[$this->effectiveEndColumn]); } $allDay = $startDate == $endDate && $endDate->format('Hi') == '0000';