|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SDIS62\Core\Ops\Service; |
|
4
|
|
|
|
|
5
|
|
|
use SDIS62\Core\Ops\Entity\Sinistre; |
|
6
|
|
|
use SDIS62\Core\Ops\Repository\SinistreRepositoryInterface; |
|
7
|
|
|
|
|
8
|
|
|
class SinistreService |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Initialisation du service avec les repository utilisés. |
|
12
|
|
|
* |
|
13
|
|
|
* @param SDIS62\Core\Ops\Repository\SinistreRepositoryInterface $sinistre_repository |
|
14
|
|
|
*/ |
|
15
|
|
|
public function __construct(SinistreRepositoryInterface $sinistre_repository) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->sinistre_repository = $sinistre_repository; |
|
|
|
|
|
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Retourne un ensemble de sinistre. |
|
22
|
|
|
* |
|
23
|
|
|
* @param int $count Par défaut: 20 |
|
24
|
|
|
* @param int $page Par défaut: 1 |
|
25
|
|
|
* |
|
26
|
|
|
* @return SDIS62\Core\User\Entity\Sinistre[] |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getAll($count = 20, $page = 1) |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->sinistre_repository->getAll($count, $page); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Retourne un sinistre correspondant à l'id spécifié. |
|
35
|
|
|
* |
|
36
|
|
|
* @param mixed $id_sinistre |
|
37
|
|
|
* |
|
38
|
|
|
* @return SDIS62\Core\Ops\Entity\Sinistre |
|
39
|
|
|
*/ |
|
40
|
|
|
public function find($id_sinistre) |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->sinistre_repository->find($id_sinistre); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Sauvegarde d'un sinistre. |
|
47
|
|
|
* |
|
48
|
|
|
* @param array $data |
|
49
|
|
|
* @param array $id_sinistre Optionnel |
|
50
|
|
|
* |
|
51
|
|
|
* @return SDIS62\Core\Ops\Entity\Sinistre |
|
52
|
|
|
*/ |
|
53
|
|
|
public function save($data, $id_sinistre = null) |
|
54
|
|
|
{ |
|
55
|
|
|
$sinistre = empty($id_sinistre) ? new Sinistre($data['name']) : $this->sinistre_repository->find($id_sinistre); |
|
56
|
|
|
|
|
57
|
|
|
if (!empty($data['name'])) { |
|
58
|
|
|
$sinistre->setName($data['name']); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$this->sinistre_repository->save($sinistre); |
|
62
|
|
|
|
|
63
|
|
|
return $sinistre; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Suppression d'un sinistre. |
|
68
|
|
|
* |
|
69
|
|
|
* @param mixed $id_sinistre |
|
70
|
|
|
* |
|
71
|
|
|
* @return SDIS62\Core\Ops\Entity\Sinistre |
|
72
|
|
|
*/ |
|
73
|
|
|
public function delete($id_sinistre) |
|
74
|
|
|
{ |
|
75
|
|
|
$sinistre = $this->find($id_sinistre); |
|
76
|
|
|
|
|
77
|
|
|
if (empty($sinistre)) { |
|
78
|
|
|
return; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$this->sinistre_repository->delete($sinistre); |
|
82
|
|
|
|
|
83
|
|
|
return $sinistre; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: