|
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\EntityNameTrait; |
|
9
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
10
|
|
|
use Doctrine\Common\Collections\Collection; |
|
11
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
12
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\MetroRepository") |
|
16
|
|
|
* @UniqueEntity("slug") |
|
17
|
|
|
*/ |
|
18
|
|
|
class Metro |
|
19
|
|
|
{ |
|
20
|
|
|
use EntityIdTrait; |
|
21
|
|
|
use EntityNameTrait; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\City", inversedBy="metro_stations") |
|
25
|
|
|
* @ORM\JoinColumn(nullable=false) |
|
26
|
|
|
*/ |
|
27
|
|
|
private $city; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Property", mappedBy="metro_station") |
|
31
|
|
|
*/ |
|
32
|
|
|
private $properties; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->properties = new ArrayCollection(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getCity(): ?City |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->city; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function setCity(?City $city): self |
|
45
|
|
|
{ |
|
46
|
|
|
$this->city = $city; |
|
47
|
|
|
|
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getProperties(): Collection |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->properties; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function addProperty(Property $property): self |
|
57
|
|
|
{ |
|
58
|
|
|
if (!$this->properties->contains($property)) { |
|
59
|
|
|
$this->properties[] = $property; |
|
60
|
|
|
$property->setMetroStation($this); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function removeProperty(Property $property): self |
|
67
|
|
|
{ |
|
68
|
|
|
if ($this->properties->contains($property)) { |
|
69
|
|
|
$this->properties->removeElement($property); |
|
70
|
|
|
// set the owning side to null (unless already changed) |
|
71
|
|
|
if ($property->getMetroStation() === $this) { |
|
72
|
|
|
$property->setMetroStation(null); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|