summaryrefslogtreecommitdiff
path: root/app/Controller/ICalendarController.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2017-11-08 14:50:02 -0800
committerFrederic Guillot <fred@kanboard.net>2017-11-08 14:50:02 -0800
commitcafbd1f5a7e60d931e4dbd700b12e5f50319340d (patch)
tree10379ec3d0ced6dbdc1da2b78071added257f101 /app/Controller/ICalendarController.php
parent5e98a66aeb108b84ca4f2ae824c0a191fbd514cd (diff)
Improve iCalendar feed to include tasks with start/end date and due date with a time
Diffstat (limited to 'app/Controller/ICalendarController.php')
-rw-r--r--app/Controller/ICalendarController.php97
1 files changed, 57 insertions, 40 deletions
diff --git a/app/Controller/ICalendarController.php b/app/Controller/ICalendarController.php
index 4fe8b78a..20e2a9d7 100644
--- a/app/Controller/ICalendarController.php
+++ b/app/Controller/ICalendarController.php
@@ -5,6 +5,7 @@ namespace Kanboard\Controller;
use Kanboard\Core\Controller\AccessForbiddenException;
use Kanboard\Core\Filter\QueryBuilder;
use Kanboard\Filter\TaskAssigneeFilter;
+use Kanboard\Filter\TaskDueDateRangeFilter;
use Kanboard\Filter\TaskProjectFilter;
use Kanboard\Filter\TaskStatusFilter;
use Kanboard\Model\TaskModel;
@@ -18,81 +19,97 @@ use Eluceo\iCal\Component\Calendar as iCalendar;
*/
class ICalendarController extends BaseController
{
- /**
- * Get user iCalendar
- *
- * @access public
- */
public function user()
{
$token = $this->request->getStringParam('token');
$user = $this->userModel->getByToken($token);
- // Token verification
if (empty($user)) {
throw AccessForbiddenException::getInstance()->withoutLayout();
}
- // Common filter
- $queryBuilder = new QueryBuilder();
- $queryBuilder
- ->withQuery($this->taskFinderModel->getICalQuery())
- ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))
- ->withFilter(new TaskAssigneeFilter($user['id']));
+ $startRange = $this->request->getStringParam('start', strtotime('-2 months'));
+ $endRange = $this->request->getStringParam('end', strtotime('+6 months'));
+
+ $startColumn = $this->configModel->get('calendar_project_tasks', 'date_started');
- // Calendar properties
$calendar = new iCalendar('Kanboard');
$calendar->setName($user['name'] ?: $user['username']);
$calendar->setDescription($user['name'] ?: $user['username']);
$calendar->setPublishedTTL('PT1H');
- $this->renderCalendar($queryBuilder, $calendar);
+ $queryDueDateOnly = QueryBuilder::create()
+ ->withQuery($this->taskFinderModel->getICalQuery())
+ ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))
+ ->withFilter(new TaskDueDateRangeFilter(array($startRange, $endRange)))
+ ->withFilter(new TaskAssigneeFilter($user['id']))
+ ->getQuery();
+
+ $queryStartAndDueDate = QueryBuilder::create()
+ ->withQuery($this->taskFinderModel->getICalQuery())
+ ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))
+ ->withFilter(new TaskAssigneeFilter($user['id']))
+ ->getQuery()
+ ->addCondition($this->getConditionForTasksWithStartAndDueDate($startRange, $endRange, $startColumn, 'date_due'));
+
+ $this->response->ical($this->taskICalFormatter
+ ->setCalendar($calendar)
+ ->addTasksWithDueDateOnly($queryDueDateOnly)
+ ->addTasksWithStartAndDueDate($queryStartAndDueDate, $startColumn, 'date_due')
+ ->format());
}
- /**
- * Get project iCalendar
- *
- * @access public
- */
public function project()
{
$token = $this->request->getStringParam('token');
$project = $this->projectModel->getByToken($token);
- // Token verification
if (empty($project)) {
throw AccessForbiddenException::getInstance()->withoutLayout();
}
- // Common filter
- $queryBuilder = new QueryBuilder();
- $queryBuilder
- ->withQuery($this->taskFinderModel->getICalQuery())
- ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))
- ->withFilter(new TaskProjectFilter($project['id']));
+ $startRange = $this->request->getStringParam('start', strtotime('-2 months'));
+ $endRange = $this->request->getStringParam('end', strtotime('+6 months'));
+
+ $startColumn = $this->configModel->get('calendar_project_tasks', 'date_started');
- // Calendar properties
$calendar = new iCalendar('Kanboard');
$calendar->setName($project['name']);
$calendar->setDescription($project['name']);
$calendar->setPublishedTTL('PT1H');
- $this->renderCalendar($queryBuilder, $calendar);
+ $queryDueDateOnly = QueryBuilder::create()
+ ->withQuery($this->taskFinderModel->getICalQuery())
+ ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))
+ ->withFilter(new TaskProjectFilter($project['id']))
+ ->withFilter(new TaskDueDateRangeFilter(array($startRange, $endRange)))
+ ->getQuery();
+
+ $queryStartAndDueDate = QueryBuilder::create()
+ ->withQuery($this->taskFinderModel->getICalQuery())
+ ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))
+ ->withFilter(new TaskProjectFilter($project['id']))
+ ->getQuery()
+ ->addCondition($this->getConditionForTasksWithStartAndDueDate($startRange, $endRange, $startColumn, 'date_due'));
+
+ $this->response->ical($this->taskICalFormatter
+ ->setCalendar($calendar)
+ ->addTasksWithDueDateOnly($queryDueDateOnly)
+ ->addTasksWithStartAndDueDate($queryStartAndDueDate, $startColumn, 'date_due')
+ ->format());
}
- /**
- * Common method to render iCal events
- *
- * @access private
- * @param QueryBuilder $queryBuilder
- * @param iCalendar $calendar
- */
- private function renderCalendar(QueryBuilder $queryBuilder, iCalendar $calendar)
+ protected function getConditionForTasksWithStartAndDueDate($start_time, $end_time, $start_column, $end_column)
{
- $start = $this->request->getStringParam('start', strtotime('-2 month'));
- $end = $this->request->getStringParam('end', strtotime('+6 months'));
+ $start_column = $this->db->escapeIdentifier($start_column);
+ $end_column = $this->db->escapeIdentifier($end_column);
+
+ $conditions = array(
+ "($start_column >= '$start_time' AND $start_column <= '$end_time')",
+ "($start_column <= '$start_time' AND $end_column >= '$start_time')",
+ "($start_column <= '$start_time' AND ($end_column = '0' OR $end_column IS NULL))",
+ );
- $this->helper->ical->addTaskDateDueEvents($queryBuilder, $calendar, $start, $end);
- $this->response->ical($this->taskICalFormatter->setCalendar($calendar)->format());
+ return $start_column.' IS NOT NULL AND '.$start_column.' > 0 AND ('.implode(' OR ', $conditions).')';
}
}