1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TrelloBurndown\Model; |
4
|
|
|
|
5
|
|
|
use TrelloBurndown\Helper\DateHelper; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Sprint. |
9
|
|
|
*/ |
10
|
|
|
class Sprint |
11
|
|
|
{ |
12
|
|
|
use DateHelper; |
13
|
|
|
/** |
14
|
|
|
* @var \DateTime |
15
|
|
|
*/ |
16
|
|
|
private $start; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \DateInterval |
20
|
|
|
*/ |
21
|
|
|
private $duration; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @const String |
25
|
|
|
*/ |
26
|
|
|
const INTERVAL = 'P1D'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return \DateTime |
30
|
|
|
*/ |
31
|
7 |
|
public function getStart() |
32
|
|
|
{ |
33
|
7 |
|
return $this->start; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return \DateInterval |
38
|
|
|
*/ |
39
|
1 |
|
public function getDuration() |
40
|
|
|
{ |
41
|
1 |
|
return $this->duration; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param \DateTime $start |
46
|
|
|
*/ |
47
|
12 |
|
public function setStart(\DateTime $start) |
48
|
|
|
{ |
49
|
12 |
|
$this->start = $start; |
50
|
12 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param \DateInterval $duration |
54
|
|
|
*/ |
55
|
12 |
|
public function setDuration(\DateInterval $duration) |
56
|
|
|
{ |
57
|
12 |
|
$this->duration = $duration; |
58
|
12 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Calculate the end of sprint from start and duration. |
62
|
|
|
* |
63
|
|
|
* @return \DateTime|null |
64
|
|
|
*/ |
65
|
8 |
|
public function getEnd() |
66
|
|
|
{ |
67
|
8 |
|
if ($this->start instanceof \DateTime && $this->duration instanceof \DateInterval) { |
68
|
8 |
|
$end = clone $this->start; |
69
|
|
|
|
70
|
8 |
|
return $end->add($this->duration); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get all days in the sprint from start date |
78
|
|
|
* and during duration. |
79
|
|
|
* |
80
|
|
|
* @return \DatePeriod|null |
81
|
|
|
*/ |
82
|
7 |
|
public function getSprintDays() |
83
|
|
|
{ |
84
|
7 |
|
if ($this->start instanceof \DateTime && $this->duration instanceof \DateInterval) { |
85
|
7 |
|
$interval = new \DateInterval(self::INTERVAL); |
86
|
|
|
|
87
|
7 |
|
$end = $this->getEnd(); |
88
|
|
|
|
89
|
7 |
|
$firstDay = clone $this->start; |
90
|
|
|
|
91
|
7 |
|
return new \DatePeriod( |
92
|
7 |
|
$firstDay->add($interval), |
93
|
|
|
$interval, |
94
|
|
|
$end |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Calculate the next day in the sprint. |
103
|
|
|
* |
104
|
|
|
* @return \DateTime |
105
|
|
|
*/ |
106
|
5 |
|
public function getNextDayInSprint() |
107
|
|
|
{ |
108
|
5 |
|
$today = new \DateTime(); |
109
|
5 |
|
$today->setTime(0, 0, 0); |
110
|
|
|
|
111
|
5 |
|
if ($today->format('N') == 5) { |
112
|
|
|
return $today->modify('+3 days'); |
113
|
|
|
} |
114
|
|
|
|
115
|
5 |
|
if ($today->format('N') == 6) { |
116
|
|
|
return $today->modify('+2 days'); |
117
|
|
|
} |
118
|
|
|
|
119
|
5 |
|
return $today->modify('+1 days'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Calculate the total work days in the sprint. |
124
|
|
|
* This function does not return week-end days but |
125
|
|
|
* return non-work-days such as christmas. |
126
|
|
|
* |
127
|
|
|
* @return null|int |
128
|
|
|
*/ |
129
|
3 |
|
public function getTotalWorkDays() |
130
|
|
|
{ |
131
|
3 |
|
$days = $this->getSprintDays(); |
132
|
3 |
|
$total = 0; |
133
|
|
|
|
134
|
3 |
|
if (!$days instanceof \DatePeriod) { |
135
|
|
|
return; |
136
|
|
|
} |
137
|
|
|
|
138
|
3 |
|
foreach ($days as $day) { |
139
|
3 |
|
if ($this->isWeekend($day)) { |
140
|
3 |
|
continue; |
141
|
|
|
} |
142
|
3 |
|
++$total; |
143
|
|
|
} |
144
|
|
|
|
145
|
3 |
|
return $total; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|