|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* \Wicked\Timely\Entities\Task |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Bernhard Wick <[email protected]> |
|
15
|
|
|
* @copyright 2016 Bernhard Wick |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/wick-ed/timely |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Wicked\Timely\Entities; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Task entity |
|
24
|
|
|
* |
|
25
|
|
|
* @author Bernhard Wick <[email protected]> |
|
26
|
|
|
* @copyright 2016 Bernhard Wick |
|
27
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
28
|
|
|
* @link https://github.com/wick-ed/timely |
|
29
|
|
|
*/ |
|
30
|
|
|
class Task |
|
31
|
|
|
{ |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* First booking of this task |
|
35
|
|
|
* |
|
36
|
|
|
* @var \Wicked\Timely\Entities\Booking $startBooking |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $startBooking; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Last booking of this task |
|
42
|
|
|
* |
|
43
|
|
|
* @var \Wicked\Timely\Entities\Booking $endBooking |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $endBooking; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Bookings within this task |
|
49
|
|
|
* |
|
50
|
|
|
* @var \Wicked\Timely\Entities\Booking[] $intermediateBookings |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $intermediateBookings; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Intermediate tasks, done within this task instance |
|
56
|
|
|
* |
|
57
|
|
|
* @var \Wicked\Timely\Entities\Task[] $intermediateTasks |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $intermediateTasks; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* The task's duration |
|
63
|
|
|
* |
|
64
|
|
|
* @var integer $duration |
|
65
|
|
|
*/ |
|
66
|
|
|
protected $duration; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Whether or not the task is being clipped due to filtering |
|
70
|
|
|
* |
|
71
|
|
|
* @var boolean $isClipped |
|
72
|
|
|
*/ |
|
73
|
|
|
protected $isClipped = false; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Getter for the first booking of the task instance |
|
77
|
|
|
* |
|
78
|
|
|
* @return \Wicked\Timely\Entities\Booking |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getStartBooking() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->startBooking; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Getter for the first booking of the task instance |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getStartTime() |
|
91
|
|
|
{ |
|
92
|
|
|
$firstIntermediate = reset($this->intermediateBookings); |
|
93
|
|
|
if ($this->isClipped() && $firstIntermediate instanceof Pause && $firstIntermediate->isPauseEnd()) { |
|
94
|
|
|
return $firstIntermediate->getTime(); |
|
95
|
|
|
} |
|
96
|
|
|
return $this->getStartBooking()->getTime(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Getter for the first booking of the task instance |
|
101
|
|
|
* |
|
102
|
|
|
* @return string |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getComment() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->getStartBooking()->getComment(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Getter for the last booking of the task instance |
|
111
|
|
|
* |
|
112
|
|
|
* @return \Wicked\Timely\Entities\Booking |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getEndBooking() |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->endBooking; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Getter for the first booking of the task instance |
|
121
|
|
|
* |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getEndTime() |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->getEndBooking()->getTime(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Getter for the intermediate bookings |
|
131
|
|
|
* |
|
132
|
|
|
* @return \Wicked\Timely\Entities\Booking[] |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getIntermediateBookings() |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->intermediateBookings; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Getter for the task's ticket id |
|
141
|
|
|
* |
|
142
|
|
|
* @return string |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getTicketId() |
|
145
|
|
|
{ |
|
146
|
|
|
return $this->getStartBooking()->getTicketId(); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Getter for the task duration |
|
151
|
|
|
* |
|
152
|
|
|
* @return integer |
|
153
|
|
|
*/ |
|
154
|
|
|
public function getDuration() |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->duration; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Getter for the task duration |
|
161
|
|
|
* |
|
162
|
|
|
* @return integer |
|
163
|
|
|
*/ |
|
164
|
|
|
protected function isClipped() |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->isClipped; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Default constructor |
|
171
|
|
|
* |
|
172
|
|
|
* @param \Wicked\Timely\Entities\Booking $startBooking The first booking of the task |
|
173
|
|
|
* @param \Wicked\Timely\Entities\Booking $endBooking The last booking of the task |
|
174
|
|
|
* @param \Wicked\Timely\Entities\Booking[] $intermediateBookings Bookings within this task |
|
175
|
|
|
*/ |
|
176
|
|
|
public function __construct($startBooking, $endBooking, $intermediateBookings) |
|
177
|
|
|
{ |
|
178
|
|
|
// set the properties |
|
179
|
|
|
$this->startBooking = $startBooking; |
|
180
|
|
|
$this->endBooking = $endBooking; |
|
181
|
|
|
$this->intermediateBookings = $intermediateBookings; |
|
182
|
|
|
// calculate the duration |
|
183
|
|
|
$this->duration = $this->calculateDuration($startBooking, $endBooking, $intermediateBookings); |
|
184
|
|
|
// determine if we are being clipped |
|
185
|
|
|
foreach ($intermediateBookings as $intermediateBooking) { |
|
186
|
|
|
if ($intermediateBooking instanceof Clipping) { |
|
187
|
|
|
$this->isClipped = true; |
|
188
|
|
|
break; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Calculates the duration of a task by given bookings |
|
195
|
|
|
* |
|
196
|
|
|
* @param \Wicked\Timely\Entities\Booking $startBooking The first booking of the task |
|
197
|
|
|
* @param \Wicked\Timely\Entities\Booking $endBooking The last booking of the task |
|
198
|
|
|
* @param \Wicked\Timely\Entities\Booking[] $intermediateBookings Bookings within this task |
|
199
|
|
|
* |
|
200
|
|
|
* @return integer |
|
201
|
|
|
*/ |
|
202
|
|
|
protected function calculateDuration($startBooking, $endBooking, array $intermediateBookings) |
|
203
|
|
|
{ |
|
204
|
|
|
// get any potential clippings and include them as task borders |
|
205
|
|
|
foreach ($intermediateBookings as $intermediateBooking) { |
|
206
|
|
|
if ($intermediateBooking->canStartTask()) { |
|
207
|
|
|
$startBooking = $intermediateBooking; |
|
208
|
|
|
|
|
209
|
|
|
} elseif ($intermediateBooking->getTicketId() === Clipping::CLIPPING_TAG_REAR) { |
|
210
|
|
|
$endBooking = $intermediateBooking; |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
// get the raw time without breaks and such |
|
215
|
|
|
$rawTime = strtotime($endBooking->getTime()) - strtotime($startBooking->getTime()); |
|
216
|
|
|
|
|
217
|
|
|
// subtract the breaks |
|
218
|
|
|
if (count($intermediateBookings) > 1) { |
|
219
|
|
|
$this->intermediateTasks = TaskFactory::getTasksFromBookings(array_merge(array($endBooking), $intermediateBookings), false, true); |
|
220
|
|
|
foreach ($this->intermediateTasks as $intermediateTask) { |
|
221
|
|
|
$rawTime -= $intermediateTask->getDuration(); |
|
222
|
|
|
} |
|
223
|
|
|
} |
|
224
|
|
|
// return what we got |
|
225
|
|
|
return $rawTime; |
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
|