|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use App\Entity\Traits\EntityIdTrait; |
|
8
|
|
|
use App\Entity\Traits\EntityMetaTrait; |
|
9
|
|
|
use App\Entity\Traits\EntityNameTrait; |
|
10
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
11
|
|
|
use Doctrine\Common\Collections\Collection; |
|
12
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
13
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\CityRepository") |
|
17
|
|
|
* @UniqueEntity("slug") |
|
18
|
|
|
*/ |
|
19
|
|
|
class City |
|
20
|
|
|
{ |
|
21
|
|
|
use EntityIdTrait; |
|
22
|
|
|
use EntityMetaTrait; |
|
23
|
|
|
use EntityNameTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Property", mappedBy="city") |
|
27
|
|
|
*/ |
|
28
|
|
|
private $properties; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\District", mappedBy="city") |
|
32
|
|
|
* @ORM\OrderBy({"name" = "ASC"}) |
|
33
|
|
|
*/ |
|
34
|
|
|
private $districts; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Neighborhood", mappedBy="city") |
|
38
|
|
|
* @ORM\OrderBy({"name" = "ASC"}) |
|
39
|
|
|
*/ |
|
40
|
|
|
private $neighborhoods; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Metro", mappedBy="city", orphanRemoval=true) |
|
44
|
|
|
* @ORM\OrderBy({"name" = "ASC"}) |
|
45
|
|
|
*/ |
|
46
|
|
|
private $metro_stations; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
|
50
|
|
|
*/ |
|
51
|
|
|
private $title; |
|
52
|
|
|
|
|
53
|
|
|
public function __construct() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->properties = new ArrayCollection(); |
|
56
|
|
|
$this->neighborhoods = new ArrayCollection(); |
|
57
|
|
|
$this->metro_stations = new ArrayCollection(); |
|
58
|
|
|
$this->districts = new ArrayCollection(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getProperties(): Collection |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->properties; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function addProperty(Property $property): self |
|
67
|
|
|
{ |
|
68
|
|
|
if (!$this->properties->contains($property)) { |
|
69
|
|
|
$this->properties[] = $property; |
|
70
|
|
|
$property->setCity($this); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function removeProperty(Property $property): self |
|
77
|
|
|
{ |
|
78
|
|
|
if ($this->properties->contains($property)) { |
|
79
|
|
|
$this->properties->removeElement($property); |
|
80
|
|
|
// set the owning side to null (unless already changed) |
|
81
|
|
|
if ($property->getCity() === $this) { |
|
82
|
|
|
$property->setCity(null); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getNeighborhoods(): Collection |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->neighborhoods; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function addNeighborhood(Neighborhood $neighborhood): self |
|
95
|
|
|
{ |
|
96
|
|
|
if (!$this->neighborhoods->contains($neighborhood)) { |
|
97
|
|
|
$this->neighborhoods[] = $neighborhood; |
|
98
|
|
|
$neighborhood->setCity($this); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function removeNeighborhood(Neighborhood $neighborhood): self |
|
105
|
|
|
{ |
|
106
|
|
|
if ($this->neighborhoods->contains($neighborhood)) { |
|
107
|
|
|
$this->neighborhoods->removeElement($neighborhood); |
|
108
|
|
|
// set the owning side to null (unless already changed) |
|
109
|
|
|
if ($neighborhood->getCity() === $this) { |
|
110
|
|
|
$neighborhood->setCity(null); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function getMetroStations(): Collection |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->metro_stations; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function addMetroStation(Metro $metroStation): self |
|
123
|
|
|
{ |
|
124
|
|
|
if (!$this->metro_stations->contains($metroStation)) { |
|
125
|
|
|
$this->metro_stations[] = $metroStation; |
|
126
|
|
|
$metroStation->setCity($this); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
return $this; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function removeMetroStation(Metro $metroStation): self |
|
133
|
|
|
{ |
|
134
|
|
|
if ($this->metro_stations->contains($metroStation)) { |
|
135
|
|
|
$this->metro_stations->removeElement($metroStation); |
|
136
|
|
|
// set the owning side to null (unless already changed) |
|
137
|
|
|
if ($metroStation->getCity() === $this) { |
|
138
|
|
|
$metroStation->setCity(null); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
return $this; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function getDistricts(): Collection |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->districts; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
public function addDistrict(District $district): self |
|
151
|
|
|
{ |
|
152
|
|
|
if (!$this->districts->contains($district)) { |
|
153
|
|
|
$this->districts[] = $district; |
|
154
|
|
|
$district->setCity($this); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
return $this; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public function removeDistrict(District $district): self |
|
161
|
|
|
{ |
|
162
|
|
|
if ($this->districts->contains($district)) { |
|
163
|
|
|
$this->districts->removeElement($district); |
|
164
|
|
|
// set the owning side to null (unless already changed) |
|
165
|
|
|
if ($district->getCity() === $this) { |
|
166
|
|
|
$district->setCity(null); |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
return $this; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function getTitle(): ?string |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->title; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public function setTitle(?string $title): self |
|
179
|
|
|
{ |
|
180
|
|
|
$this->title = $title; |
|
181
|
|
|
|
|
182
|
|
|
return $this; |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|