Use completion or due date for the event end
This commit is contained in:
committed by
Frédéric Guillot
parent
9f30934369
commit
5905bf4974
@@ -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).')';
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user