|
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\Helper; |
|
13
|
|
|
|
|
14
|
|
|
use Jitamin\Filter\TaskDueDateRangeFilter; |
|
15
|
|
|
use Jitamin\Formatter\SubtaskTimeTrackingCalendarFormatter; |
|
16
|
|
|
use Jitamin\Formatter\TaskCalendarFormatter; |
|
17
|
|
|
use Jitamin\Foundation\Base; |
|
18
|
|
|
use Jitamin\Foundation\Filter\QueryBuilder; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Calendar Helper. |
|
22
|
|
|
*/ |
|
23
|
|
|
class CalendarHelper extends Base |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Get formatted calendar task due events. |
|
27
|
|
|
* |
|
28
|
|
|
* @param QueryBuilder $queryBuilder |
|
29
|
|
|
* @param string $start |
|
30
|
|
|
* @param string $end |
|
31
|
|
|
* |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getTaskDateDueEvents(QueryBuilder $queryBuilder, $start, $end) |
|
35
|
|
|
{ |
|
36
|
|
|
$formatter = new TaskCalendarFormatter($this->container); |
|
37
|
|
|
$formatter->setFullDay(); |
|
38
|
|
|
$formatter->setColumns('date_due'); |
|
39
|
|
|
|
|
40
|
|
|
return $queryBuilder |
|
41
|
|
|
->withFilter(new TaskDueDateRangeFilter([$start, $end])) |
|
42
|
|
|
->format($formatter); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get formatted calendar task events. |
|
47
|
|
|
* |
|
48
|
|
|
* @param QueryBuilder $queryBuilder |
|
49
|
|
|
* @param string $start |
|
50
|
|
|
* @param string $end |
|
51
|
|
|
* |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getTaskEvents(QueryBuilder $queryBuilder, $start, $end) |
|
55
|
|
|
{ |
|
56
|
|
|
$startColumn = $this->settingModel->get('calendar_project_tasks', 'date_started'); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
$queryBuilder->getQuery()->addCondition($this->getCalendarCondition( |
|
59
|
|
|
$this->dateParser->getTimestampFromIsoFormat($start), |
|
|
|
|
|
|
60
|
|
|
$this->dateParser->getTimestampFromIsoFormat($end), |
|
|
|
|
|
|
61
|
|
|
$startColumn, |
|
62
|
|
|
'date_due' |
|
63
|
|
|
)); |
|
64
|
|
|
|
|
65
|
|
|
$formatter = new TaskCalendarFormatter($this->container); |
|
66
|
|
|
$formatter->setColumns($startColumn, 'date_due'); |
|
67
|
|
|
|
|
68
|
|
|
return $queryBuilder->format($formatter); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get formatted calendar subtask time tracking events. |
|
73
|
|
|
* |
|
74
|
|
|
* @param int $user_id |
|
75
|
|
|
* @param string $start |
|
76
|
|
|
* @param string $end |
|
77
|
|
|
* |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getSubtaskTimeTrackingEvents($user_id, $start, $end) |
|
81
|
|
|
{ |
|
82
|
|
|
$formatter = new SubtaskTimeTrackingCalendarFormatter($this->container); |
|
83
|
|
|
|
|
84
|
|
|
return $formatter |
|
85
|
|
|
->withQuery($this->subtaskTimeTrackingModel->getUserQuery($user_id) |
|
|
|
|
|
|
86
|
|
|
->addCondition($this->getCalendarCondition( |
|
87
|
|
|
$this->dateParser->getTimestampFromIsoFormat($start), |
|
|
|
|
|
|
88
|
|
|
$this->dateParser->getTimestampFromIsoFormat($end), |
|
|
|
|
|
|
89
|
|
|
'start', |
|
90
|
|
|
'end' |
|
91
|
|
|
)) |
|
92
|
|
|
) |
|
93
|
|
|
->format(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Build SQL condition for a given time range. |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $start_time Start timestamp |
|
100
|
|
|
* @param string $end_time End timestamp |
|
101
|
|
|
* @param string $start_column Start column name |
|
102
|
|
|
* @param string $end_column End column name |
|
103
|
|
|
* |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getCalendarCondition($start_time, $end_time, $start_column, $end_column) |
|
107
|
|
|
{ |
|
108
|
|
|
$start_column = $this->db->escapeIdentifier($start_column); |
|
|
|
|
|
|
109
|
|
|
$end_column = $this->db->escapeIdentifier($end_column); |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
$conditions = [ |
|
112
|
|
|
"($start_column >= '$start_time' AND $start_column <= '$end_time')", |
|
113
|
|
|
"($start_column <= '$start_time' AND $end_column >= '$start_time')", |
|
114
|
|
|
"($start_column <= '$start_time' AND ($end_column = '0' OR $end_column IS NULL))", |
|
115
|
|
|
]; |
|
116
|
|
|
|
|
117
|
|
|
return $start_column.' IS NOT NULL AND '.$start_column.' > 0 AND ('.implode(' OR ', $conditions).')'; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
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.