1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace App\Src\UseCases\Domain\Context\Model; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use App\Src\UseCases\Domain\Ports\ContextRepository; |
8
|
|
|
|
9
|
|
|
class Context |
10
|
|
|
{ |
11
|
|
|
private $uid; |
12
|
|
|
private $postalCode; |
13
|
|
|
private $characteristics; |
14
|
|
|
private $description; |
15
|
|
|
private $sector; |
16
|
|
|
private $structure; |
17
|
|
|
private $departmentNumber; |
18
|
|
|
private $coordinates; |
19
|
|
|
|
20
|
|
|
private $contextRepository; |
21
|
|
|
|
22
|
|
|
public function __construct( |
23
|
|
|
string $id, |
24
|
|
|
string $postalCode, |
25
|
|
|
array $characteristics = [], |
26
|
|
|
string $description = null, |
27
|
|
|
string $sector = null, |
28
|
|
|
string $structure = null, |
29
|
|
|
string $departmentNumber = null, |
30
|
|
|
array $coordinates = [] |
31
|
|
|
) |
32
|
|
|
{ |
33
|
|
|
$this->uid = $id; |
34
|
|
|
$this->postalCode = $postalCode; |
35
|
|
|
$this->characteristics = $characteristics; |
36
|
|
|
$this->description = $description; |
37
|
|
|
$this->sector = $sector; |
38
|
|
|
$this->structure = $structure; |
39
|
|
|
$this->departmentNumber = $departmentNumber; |
40
|
|
|
$this->coordinates = $coordinates; |
41
|
|
|
$this->contextRepository = app(ContextRepository::class); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function id():string |
45
|
|
|
{ |
46
|
|
|
return $this->uid; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function create(string $userId) |
50
|
|
|
{ |
51
|
|
|
$this->contextRepository->add($this, $userId); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function update(array $params, string $userId) |
55
|
|
|
{ |
56
|
|
|
$this->description = $params['description'] ?? $this->description; |
57
|
|
|
$this->postalCode = $params['postal_code'] ?? $this->postalCode; |
58
|
|
|
$this->characteristics = $params['characteristics'] ?? $this->characteristics; |
59
|
|
|
$this->sector = $params['sector'] ?? $this->sector; |
60
|
|
|
$this->structure = $params['structure'] ?? $this->structure; |
61
|
|
|
$this->departmentNumber = $params['department_number'] ?? $this->departmentNumber; |
62
|
|
|
$this->coordinates = $params['coordinates'] ?? $this->coordinates; |
63
|
|
|
$this->contextRepository->update($this, $userId); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function addCharacteristics(array $characteristics, string $userId) |
67
|
|
|
{ |
68
|
|
|
$this->characteristics = array_values(array_unique(array_merge($this->characteristics, $characteristics))); |
69
|
|
|
$this->contextRepository->update($this, $userId); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function toArray() |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
'uuid' => $this->uid, |
76
|
|
|
'postal_code' => $this->postalCode, |
77
|
|
|
'characteristics' => $this->characteristics, |
78
|
|
|
'description' => $this->description, |
79
|
|
|
'sector' => $this->sector, |
80
|
|
|
'structure' => $this->structure, |
81
|
|
|
'coordinates' => $this->coordinates, |
82
|
|
|
'department_number' => $this->departmentNumber, |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|