|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace FlightLog\Http\Web\Controller; |
|
5
|
|
|
|
|
6
|
|
|
use FlightLog\Application\Damage\Command\CreateDamageCommand; |
|
7
|
|
|
use FlightLog\Application\Damage\Command\CreateDamageCommandHandler; |
|
8
|
|
|
use FlightLog\Http\Web\Form\DamageCreationForm; |
|
9
|
|
|
use FlightLog\Infrastructure\Damage\Repository\FlightDamageRepository; |
|
10
|
|
|
|
|
11
|
|
|
final class AddFlightDamageController extends WebController |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
public function __construct(\DoliDB $db) |
|
15
|
|
|
{ |
|
16
|
|
|
parent::__construct($db); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Display the form. |
|
21
|
|
|
*/ |
|
22
|
|
|
public function view(){ |
|
23
|
|
|
$id = $this->request->getParam('id'); |
|
24
|
|
|
|
|
25
|
|
|
if($id === null){ |
|
26
|
|
|
print '<p>Paramètre non fournis.</p>'; |
|
27
|
|
|
return; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
$flight = new \Bbcvols($this->db); |
|
31
|
|
|
if($flight->fetch($id) <= 0){ |
|
32
|
|
|
print '<p>Vol non trouvé</p>'; |
|
33
|
|
|
return; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$command = new CreateDamageCommand($flight->getId(), $flight->getPilotId()); |
|
37
|
|
|
$form = new DamageCreationForm('damage_creation', $this->db); |
|
38
|
|
|
$form->bind($command); |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
if($this->request->isPost()){ |
|
41
|
|
|
$form->setData($this->request->getPostParameters()); |
|
42
|
|
|
|
|
43
|
|
|
if(!$form->validate()){ |
|
44
|
|
|
return $this->render('flight_damage/form.php', [ |
|
45
|
|
|
'form' => $form, |
|
46
|
|
|
]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
try{ |
|
50
|
|
|
$this->handle($form->getObject()); |
|
|
|
|
|
|
51
|
|
|
}catch(\Exception $e){ |
|
52
|
|
|
print $e->getMessage(); |
|
53
|
|
|
dol_syslog($e->getMessage(), LOG_ERR); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$this->redirect($_SERVER["PHP_SELF"].'?id='.$id); |
|
58
|
|
|
exit; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $this->render('flight_damage/form.php', [ |
|
62
|
|
|
'form' => $form, |
|
63
|
|
|
]); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param CreateDamageCommand $command |
|
68
|
|
|
* |
|
69
|
|
|
* @throws \Exception |
|
70
|
|
|
*/ |
|
71
|
|
|
private function handle(CreateDamageCommand $command) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->getHandler()->__invoke($command); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return CreateDamageCommandHandler |
|
78
|
|
|
*/ |
|
79
|
|
|
private function getHandler(){ |
|
80
|
|
|
return new CreateDamageCommandHandler($this->db, $this->getDamageRepository()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return FlightDamageRepository |
|
85
|
|
|
*/ |
|
86
|
|
|
private function getDamageRepository(){ |
|
87
|
|
|
return new FlightDamageRepository($this->db); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param string $location |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function redirect($location) |
|
94
|
|
|
{ |
|
95
|
|
|
if (headers_sent()) { |
|
96
|
|
|
echo("<script>location.href='$location'</script>"); |
|
97
|
|
|
return; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
header("Location: $location"); |
|
101
|
|
|
exit; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: