|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\DTO; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
|
|
7
|
|
|
class Property |
|
8
|
|
|
{ |
|
9
|
|
|
private ?float $price = null; |
|
10
|
|
|
private ?float $area = null; |
|
11
|
|
|
private ?int $roomsCount = null; |
|
12
|
|
|
private ?string $location = null; |
|
13
|
|
|
private ?string $buildingName = null; |
|
14
|
|
|
private bool $newBuild = false; |
|
15
|
|
|
/** @var PropertyAd[] */ |
|
16
|
|
|
private array $ads = []; |
|
17
|
|
|
|
|
18
|
|
|
public function getPrice(): ?float |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->price; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function setPrice(?float $price): Property |
|
24
|
|
|
{ |
|
25
|
|
|
$this->price = $price; |
|
26
|
|
|
|
|
27
|
|
|
return $this; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function getArea(): ?float |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->area; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function setArea(?float $area): Property |
|
36
|
|
|
{ |
|
37
|
|
|
$this->area = $area; |
|
38
|
|
|
|
|
39
|
|
|
return $this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getRoomsCount(): ?int |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->roomsCount; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function setRoomsCount(?int $roomsCount): Property |
|
48
|
|
|
{ |
|
49
|
|
|
$this->roomsCount = $roomsCount; |
|
50
|
|
|
|
|
51
|
|
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getLocation(): ?string |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->location; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function setLocation(?string $location): Property |
|
60
|
|
|
{ |
|
61
|
|
|
$this->location = $location; |
|
62
|
|
|
|
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getBuildingName(): ?string |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->buildingName; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function setBuildingName(?string $buildingName): Property |
|
72
|
|
|
{ |
|
73
|
|
|
$this->buildingName = $buildingName; |
|
74
|
|
|
|
|
75
|
|
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function isNewBuild(): bool |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->newBuild; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function setNewBuild(bool $newBuild): Property |
|
84
|
|
|
{ |
|
85
|
|
|
$this->newBuild = $newBuild; |
|
86
|
|
|
|
|
87
|
|
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return PropertyAd[] |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getAds(): array |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->ads; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param PropertyAd[] $ads |
|
100
|
|
|
*/ |
|
101
|
|
|
public function setAds(array $ads): Property |
|
102
|
|
|
{ |
|
103
|
|
|
$this->ads = $ads; |
|
104
|
|
|
|
|
105
|
|
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getAd(): PropertyAd |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->ads[0]; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function setAd(PropertyAd $ad): Property |
|
114
|
|
|
{ |
|
115
|
|
|
$this->ads = [$ad]; |
|
116
|
|
|
|
|
117
|
|
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function addAd(PropertyAd $ad): Property |
|
121
|
|
|
{ |
|
122
|
|
|
$this->ads[] = $ad; |
|
123
|
|
|
|
|
124
|
|
|
return $this; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function getPublishedAt(): DateTime |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->getAd()->getPublishedAt(); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function equals(Property $property): bool |
|
133
|
|
|
{ |
|
134
|
|
|
// If the properties are new-build, they are the same ones if the name of their apartment building are equal |
|
135
|
|
|
if ($this->newBuild && null !== $this->buildingName && $property->isNewBuild()) { |
|
136
|
|
|
return $this->buildingName === $property->getBuildingName(); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
$sameArea = null !== $this->area && abs($this->area - $property->getArea()) <= 1; |
|
140
|
|
|
|
|
141
|
|
|
// Properties are equal if their price are equal, as long as the price doesn't finish with a so common "000" |
|
142
|
|
|
// or if their area are pretty much equal |
|
143
|
|
|
return |
|
144
|
|
|
(null !== $this->price && $this->price === $property->getPrice()) && |
|
145
|
|
|
((null !== $this->area && null !== $property->getArea()) ? $sameArea : true) && |
|
146
|
|
|
('000' !== substr($this->price, -3) || $sameArea); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|