1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace FlightLog\Application\Pilot\Command; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use FlightLog\Domain\Pilot\Pilot; |
8
|
|
|
use FlightLog\Domain\Pilot\ValueObject\EndDate; |
9
|
|
|
use FlightLog\Domain\Pilot\ValueObject\FireCertificationNumber; |
10
|
|
|
use FlightLog\Domain\Pilot\ValueObject\FirstHelpCertificationNumber; |
11
|
|
|
use FlightLog\Domain\Pilot\ValueObject\LastTrainingDate; |
12
|
|
|
use FlightLog\Domain\Pilot\ValueObject\PilotId; |
13
|
|
|
use FlightLog\Domain\Pilot\ValueObject\PilotLicenceNumber; |
14
|
|
|
use FlightLog\Domain\Pilot\ValueObject\PilotTrainingLicenceNumber; |
15
|
|
|
use FlightLog\Domain\Pilot\ValueObject\RadioLicenceDate; |
16
|
|
|
use FlightLog\Domain\Pilot\ValueObject\RadioLicenceNumber; |
17
|
|
|
use FlightLog\Domain\Pilot\ValueObject\StartDate; |
18
|
|
|
use FlightLog\Infrastructure\Pilot\Repository\PilotRepository; |
19
|
|
|
|
20
|
|
|
final class CreateUpdatePilotInformationCommandHandler |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var PilotRepository |
25
|
|
|
*/ |
26
|
|
|
private $pilotRepository; |
27
|
|
|
|
28
|
|
|
public function __construct(PilotRepository $pilotRepository) |
29
|
|
|
{ |
30
|
|
|
$this->pilotRepository = $pilotRepository; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param CreateUpdatePilotInformationCommand $command |
35
|
|
|
* |
36
|
|
|
* @throws \Exception |
37
|
|
|
*/ |
38
|
|
|
public function __invoke(CreateUpdatePilotInformationCommand $command) |
39
|
|
|
{ |
40
|
|
|
$pilotId = PilotId::create($command->getPilotId()); |
41
|
|
|
$pilot = $this->getOrCreatePilot($pilotId); |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
if ($command->getIsMedicalOwner()) { |
45
|
|
|
$pilot->medical(); |
46
|
|
|
} else { |
47
|
|
|
$pilot->removeMedical(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if ($command->getIsPilotClassA()) { |
51
|
|
|
$pilot->hasClassA(); |
52
|
|
|
} else { |
53
|
|
|
$pilot->removeClassA(); |
54
|
|
|
} |
55
|
|
|
if ($command->getIsPilotClassB()) { |
56
|
|
|
$pilot->hasClassB(); |
57
|
|
|
} else { |
58
|
|
|
$pilot->removeClassB(); |
59
|
|
|
} |
60
|
|
|
if ($command->getIsPilotClassC()) { |
61
|
|
|
$pilot->hasClassC(); |
62
|
|
|
} else { |
63
|
|
|
$pilot->removeClassC(); |
64
|
|
|
} |
65
|
|
|
if ($command->getIsPilotClassD()) { |
66
|
|
|
$pilot->hasClassD(); |
67
|
|
|
} else { |
68
|
|
|
$pilot->removeClassD(); |
69
|
|
|
} |
70
|
|
|
if ($command->getIsPilotGaz()) { |
71
|
|
|
$pilot->gazPilot(); |
72
|
|
|
} else { |
73
|
|
|
$pilot->removeGazPilot(); |
74
|
|
|
} |
75
|
|
|
if ($command->getIsHasQualifStatic()) { |
76
|
|
|
$pilot->staticQualif(); |
77
|
|
|
} else { |
78
|
|
|
$pilot->removeStaticQualif(); |
79
|
|
|
} |
80
|
|
|
if ($command->getIsHasQualifNight()) { |
81
|
|
|
$pilot->nightQualif(); |
82
|
|
|
} else { |
83
|
|
|
$pilot->removeNightQualif(); |
84
|
|
|
} |
85
|
|
|
if ($command->getIsHasQualifPro()) { |
86
|
|
|
$pilot->proQualif(); |
87
|
|
|
} else { |
88
|
|
|
$pilot->removeProQualif(); |
89
|
|
|
} |
90
|
|
|
if ($command->getIsHasQualifInstructor()) { |
91
|
|
|
$pilot->instructorQualif(); |
92
|
|
|
} else { |
93
|
|
|
$pilot->removeInstructorQualif(); |
94
|
|
|
} |
95
|
|
|
if ($command->getIsHasQualifExaminator()) { |
96
|
|
|
$pilot->examinatorQualif(); |
97
|
|
|
} else { |
98
|
|
|
$pilot->removeExaminatorQualif(); |
99
|
|
|
} |
100
|
|
|
if ($command->getIsHasRadio()) { |
101
|
|
|
$pilot->radio(); |
102
|
|
|
} else { |
103
|
|
|
$pilot->removeRadio(); |
104
|
|
|
} |
105
|
|
|
if ($command->getIsHasTrainingFirstHelp()) { |
106
|
|
|
$pilot->trainingFirstHelp(); |
107
|
|
|
} else { |
108
|
|
|
$pilot->removeTrainingFirstHelp(); |
109
|
|
|
} |
110
|
|
|
if ($command->getIsHasTrainingFire()) { |
111
|
|
|
$pilot->trainingFire(); |
112
|
|
|
} else { |
113
|
|
|
$pilot->removeTrainingFire(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$pilot->attributePilotLicenceNumber(PilotLicenceNumber::create($command->getPilotLicenceNumber())); |
117
|
|
|
$pilot->attributeTrainingPilotLicenceNumber(PilotTrainingLicenceNumber::create($command->getTrainingPilotLicenceNumber())); |
118
|
|
|
$pilot->attributeRadioLicenceNumber(RadioLicenceNumber::create($command->getRadioLicenceNumber())); |
119
|
|
|
$pilot->attributeCertificationNumberTrainingFirstHelp(FirstHelpCertificationNumber::create($command->getCertificationNumberTrainingFirstHelp())); |
120
|
|
|
$pilot->attributeCertificationNumberTrainingFire(FireCertificationNumber::create($command->getCertificationNumberTrainingFire())); |
121
|
|
|
|
122
|
|
|
$pilot->attributeLastTrainingFlightDate(LastTrainingDate::fromString($command->getLastTrainingFlightDate())); |
123
|
|
|
$pilot->attributeEndMedicalDate(EndDate::fromString($command->getEndMedicalDate())); |
124
|
|
|
$pilot->attributeStartMedicalDate(StartDate::fromString($command->getStartMedicalDate())); |
125
|
|
|
$pilot->attributeLastOpcDate(LastTrainingDate::fromString($command->getLastOpcDate())); |
126
|
|
|
$pilot->attributeLastProRefreshDate(LastTrainingDate::fromString($command->getLastProRefreshDate())); |
127
|
|
|
$pilot->attributeLastInstructorRefreshDate(LastTrainingDate::fromString($command->getLastInstructorRefreshDate())); |
128
|
|
|
$pilot->attributeLastExaminatorRefreshDate(LastTrainingDate::fromString($command->getLastExaminatorRefreshDate())); |
129
|
|
|
$pilot->attributeLastTrainingFireDate(LastTrainingDate::fromString($command->getLastTrainingFireDate())); |
130
|
|
|
$pilot->attributeRadioLicenceDate(RadioLicenceDate::fromString($command->getRadioLicenceDate())); |
131
|
|
|
$pilot->attributeLastTrainingFirstHelpDate(LastTrainingDate::fromString($command->getLastTrainingFirstHelpDate())); |
132
|
|
|
|
133
|
|
|
$this->pilotRepository->save($pilot); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param PilotId $pilotId |
138
|
|
|
* |
139
|
|
|
* @return Pilot |
140
|
|
|
* |
141
|
|
|
* @throws \Exception |
142
|
|
|
*/ |
143
|
|
|
private function getOrCreatePilot(PilotId $pilotId): Pilot |
144
|
|
|
{ |
145
|
|
|
if ($this->pilotRepository->exist($pilotId)) { |
146
|
|
|
return $this->pilotRepository->getById($pilotId); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
return Pilot::create($pilotId); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
} |