diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-05-17 22:09:44 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-05-17 22:09:44 -0400 |
commit | ac6e7bdfbf3479c655d7b883e50b6b01aa08784d (patch) | |
tree | acf23fc0c3417bb8a3ad8423b945942ab69969a2 /app/Controller | |
parent | 16973bb2220be77e8969e29f560b46a0fbf80f66 (diff) |
Add iCalendar public access for projects
Diffstat (limited to 'app/Controller')
-rw-r--r-- | app/Controller/Ical.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/app/Controller/Ical.php b/app/Controller/Ical.php new file mode 100644 index 00000000..55cc64a6 --- /dev/null +++ b/app/Controller/Ical.php @@ -0,0 +1,52 @@ +<?php + +namespace Controller; + +use Model\Task as TaskModel; + +/** + * iCalendar controller + * + * @package controller + * @author Frederic Guillot + */ +class Ical extends Base +{ + /** + * Get project iCalendar + * + * @access public + */ + public function project() + { + $token = $this->request->getStringParam('token'); + $project = $this->project->getByToken($token); + + // Token verification + if (empty($project)) { + $this->forbidden(true); + } + + $start = $this->request->getStringParam('start', strtotime('-1 month')); + $end = $this->request->getStringParam('end', strtotime('+2 months')); + + // Common filter + $filter = $this->taskFilter + ->create() + ->filterByProject($project['id']); + + // Tasks + if ($this->config->get('calendar_project_tasks', 'date_started') === 'date_creation') { + $calendar = $filter->copy()->filterByCreationDateRange($start, $end)->addDateTimeIcalEvents('date_creation', 'date_completed'); + } + else { + $calendar = $filter->copy()->filterByStartDateRange($start, $end)->addDateTimeIcalEvents('date_started', 'date_completed'); + } + + // Tasks with due date + $calendar = $filter->copy()->filterByDueDateRange($start, $end)->addAllDayIcalEvents('date_due', $calendar); + + $this->response->contentType('text/calendar; charset=utf-8'); + echo $calendar->render(); + } +} |