|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Jitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) Jitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Jitamin\Http\Controllers; |
|
13
|
|
|
|
|
14
|
|
|
use Eluceo\iCal\Component\Calendar as iCalendar; |
|
15
|
|
|
use Jitamin\Filter\TaskAssigneeFilter; |
|
16
|
|
|
use Jitamin\Filter\TaskProjectFilter; |
|
17
|
|
|
use Jitamin\Filter\TaskStatusFilter; |
|
18
|
|
|
use Jitamin\Formatter\TaskICalFormatter; |
|
19
|
|
|
use Jitamin\Foundation\Exceptions\AccessForbiddenException; |
|
20
|
|
|
use Jitamin\Foundation\Filter\QueryBuilder; |
|
21
|
|
|
use Jitamin\Model\TaskModel; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* iCalendar Controller. |
|
25
|
|
|
*/ |
|
26
|
|
|
class ICalendarController extends Controller |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Get user iCalendar. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function user() |
|
32
|
|
|
{ |
|
33
|
|
|
$token = $this->request->getStringParam('token'); |
|
|
|
|
|
|
34
|
|
|
$user = $this->userModel->getByToken($token); |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
// Token verification |
|
37
|
|
|
if (empty($user)) { |
|
38
|
|
|
throw AccessForbiddenException::getInstance()->withoutLayout(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// Common filter |
|
42
|
|
|
$queryBuilder = new QueryBuilder(); |
|
43
|
|
|
$queryBuilder |
|
44
|
|
|
->withQuery($this->taskFinderModel->getICalQuery()) |
|
|
|
|
|
|
45
|
|
|
->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN)) |
|
46
|
|
|
->withFilter(new TaskAssigneeFilter($user['id'])); |
|
47
|
|
|
|
|
48
|
|
|
// Calendar properties |
|
49
|
|
|
$calendar = new iCalendar('Jitamin'); |
|
50
|
|
|
$calendar->setName($user['name'] ?: $user['username']); |
|
51
|
|
|
$calendar->setDescription($user['name'] ?: $user['username']); |
|
52
|
|
|
$calendar->setPublishedTTL('PT1H'); |
|
53
|
|
|
|
|
54
|
|
|
$this->renderCalendar($queryBuilder, $calendar); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get project iCalendar. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function project() |
|
61
|
|
|
{ |
|
62
|
|
|
$token = $this->request->getStringParam('token'); |
|
|
|
|
|
|
63
|
|
|
$project = $this->projectModel->getByToken($token); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
// Token verification |
|
66
|
|
|
if (empty($project)) { |
|
67
|
|
|
throw AccessForbiddenException::getInstance()->withoutLayout(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
// Common filter |
|
71
|
|
|
$queryBuilder = new QueryBuilder(); |
|
72
|
|
|
$queryBuilder |
|
73
|
|
|
->withQuery($this->taskFinderModel->getICalQuery()) |
|
|
|
|
|
|
74
|
|
|
->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN)) |
|
75
|
|
|
->withFilter(new TaskProjectFilter($project['id'])); |
|
76
|
|
|
|
|
77
|
|
|
// Calendar properties |
|
78
|
|
|
$calendar = new iCalendar('Jitamin'); |
|
79
|
|
|
$calendar->setName($project['name']); |
|
80
|
|
|
$calendar->setDescription($project['name']); |
|
81
|
|
|
$calendar->setPublishedTTL('PT1H'); |
|
82
|
|
|
|
|
83
|
|
|
$this->renderCalendar($queryBuilder, $calendar); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Common method to render iCal events. |
|
88
|
|
|
* |
|
89
|
|
|
* @param QueryBuilder $queryBuilder |
|
90
|
|
|
* @param iCalendar $calendar |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function renderCalendar(QueryBuilder $queryBuilder, iCalendar $calendar) |
|
93
|
|
|
{ |
|
94
|
|
|
$start = $this->request->getStringParam('start', strtotime('-2 month')); |
|
|
|
|
|
|
95
|
|
|
$end = $this->request->getStringParam('end', strtotime('+6 months')); |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
$this->helper->ical->addTaskDateDueEvents($queryBuilder, $calendar, $start, $end); |
|
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
$formatter = new TaskICalFormatter($this->container); |
|
100
|
|
|
$this->response->ical($formatter->setCalendar($calendar)->format()); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.