1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cp\Calendar\Builder; |
4
|
|
|
|
5
|
|
|
use Cp\DomainObject\Plan; |
6
|
|
|
use Jsvrcek\ICS\CalendarExport; |
7
|
|
|
use Jsvrcek\ICS\Model\Calendar; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class CalendarBuilder |
11
|
|
|
*/ |
12
|
|
|
class CalendarBuilder |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var CalendarExport |
16
|
|
|
*/ |
17
|
|
|
private $calendarExport; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var CalendarEventBuilder |
21
|
|
|
*/ |
22
|
|
|
private $calendarEventBuilder; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* CalendarBuilder constructor. |
26
|
|
|
* |
27
|
|
|
* @param CalendarExport $calendarExport |
28
|
|
|
* @param CalendarEventBuilder $calendarEventBuilder |
29
|
|
|
*/ |
30
|
3 |
|
public function __construct(CalendarExport $calendarExport, CalendarEventBuilder $calendarEventBuilder) |
31
|
|
|
{ |
32
|
3 |
|
$this->calendarExport = $calendarExport; |
33
|
3 |
|
$this->calendarEventBuilder = $calendarEventBuilder; |
34
|
3 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param Plan $plan |
38
|
|
|
*/ |
39
|
2 |
|
public function build(Plan $plan) |
40
|
|
|
{ |
41
|
2 |
|
$calendar = new Calendar(); |
42
|
2 |
|
$calendar->setProdId($plan->getName()); |
43
|
2 |
|
$initialDate = new \DateTime(); |
44
|
2 |
|
$initialDate->modify('- '.$this->getRecoveryDay($plan->getConfiguration()->getNumberOfSeance())[0].' day'); |
45
|
|
|
|
46
|
2 |
|
foreach ($plan->getWeeks() as $week) { |
47
|
2 |
|
$events = $this->calendarEventBuilder->build($week); |
48
|
2 |
|
foreach ($events as $key => $event) { |
49
|
2 |
|
$event->setStart(clone $initialDate->modify('+'.$this->getRecoveryDay(count($events))[$key].' day')); |
50
|
2 |
|
$calendar->addEvent($event); |
51
|
2 |
|
} |
52
|
2 |
|
} |
53
|
|
|
|
54
|
2 |
|
$this->calendarExport->addCalendar($calendar); |
55
|
2 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param int $numSeance |
59
|
|
|
* |
60
|
|
|
* @return array |
|
|
|
|
61
|
|
|
*/ |
62
|
3 |
|
public function getRecoveryDay($numSeance) |
63
|
|
|
{ |
64
|
|
|
switch ($numSeance) { |
65
|
3 |
|
case 3: |
66
|
3 |
|
return [3, 3, 3]; |
67
|
1 |
|
case 4: |
68
|
1 |
|
return [2, 2, 2, 2]; |
69
|
2 |
|
case 5: |
70
|
1 |
|
return [1, 2, 1, 2, 1]; |
71
|
1 |
View Code Duplication |
case 6: |
|
|
|
|
72
|
1 |
|
return [1, 1, 1, 1, 1, 1]; |
73
|
1 |
View Code Duplication |
case 7: |
|
|
|
|
74
|
1 |
|
return [1, 1, 1, 1, 1, 1, 1]; |
75
|
|
|
|
76
|
1 |
|
default: |
77
|
1 |
|
return null; |
78
|
1 |
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param Plan $plan |
83
|
|
|
* |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
1 |
|
public function exportCalendar(Plan $plan) |
87
|
|
|
{ |
88
|
1 |
|
$this->build($plan); |
89
|
|
|
|
90
|
1 |
|
return $this->calendarExport->getStream(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.