|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace FlightLog\Infrastructure\Damage\Repository; |
|
5
|
|
|
|
|
6
|
|
|
use FlightLog\Domain\Damage\AuthorId; |
|
7
|
|
|
use FlightLog\Domain\Damage\DamageAmount; |
|
8
|
|
|
use FlightLog\Domain\Damage\DamageId; |
|
9
|
|
|
use FlightLog\Domain\Damage\FlightDamage; |
|
10
|
|
|
use FlightLog\Domain\Damage\FlightId; |
|
11
|
|
|
use FlightLog\Infrastructure\Common\Repository\AbstractDomainRepository; |
|
12
|
|
|
|
|
13
|
|
|
final class FlightDamageRepository extends AbstractDomainRepository |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @param \DoliDB $db |
|
18
|
|
|
*/ |
|
19
|
|
|
public function __construct(\DoliDB $db) |
|
20
|
|
|
{ |
|
21
|
|
|
parent::__construct($db, 'bbc_flight_damages'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param FlightDamage $flightDamage |
|
26
|
|
|
* |
|
27
|
|
|
* @throws \Exception |
|
28
|
|
|
*/ |
|
29
|
|
|
public function save(FlightDamage $flightDamage) |
|
30
|
|
|
{ |
|
31
|
|
|
$fields = [ |
|
32
|
|
|
'flight_id' => $flightDamage->getFlightId()->getId(), |
|
33
|
|
|
'billed' => $flightDamage->isBilled(), |
|
34
|
|
|
'amount' => $flightDamage->amount()->getValue(), |
|
35
|
|
|
'author_id' => $flightDamage->getAuthor()->getId() |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
if($flightDamage->getId()){ |
|
39
|
|
|
$this->update($flightDamage->getId()->getId(), $fields); |
|
40
|
|
|
return; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$this->write($fields); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param DamageId $id |
|
48
|
|
|
* |
|
49
|
|
|
* @return FlightDamage |
|
50
|
|
|
* |
|
51
|
|
|
* @throws \Exception |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getById(DamageId $id){ |
|
54
|
|
|
$damage = $this->get($id->getId()); |
|
55
|
|
|
|
|
56
|
|
|
if(null === $damage){ |
|
57
|
|
|
throw new \Exception('Damage not found'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return FlightDamage::load( |
|
61
|
|
|
FlightId::create($damage['flight_id']), |
|
62
|
|
|
new DamageAmount($damage['amount']), |
|
63
|
|
|
$damage['billed'], |
|
64
|
|
|
AuthorId::create($damage['author_id']), |
|
65
|
|
|
DamageId::create($damage['rowid']) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
} |