src/Entity/City.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CityRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=CityRepository::class)
  9. * @ORM\HasLifecycleCallbacks()
  10. */
  11. class City
  12. {
  13. /**
  14. * @ORM\Id
  15. * @ORM\GeneratedValue
  16. * @ORM\Column(type="integer")
  17. */
  18. private $id;
  19. /**
  20. * @ORM\Column(type="string", length=255)
  21. */
  22. private $name;
  23. /**
  24. * @ORM\Column(type="text", nullable=true)
  25. */
  26. private $description;
  27. /**
  28. * @ORM\Column(type="datetime", nullable=true)
  29. */
  30. private $updateAt;
  31. /**
  32. * @ORM\ManyToOne(targetEntity=Department::class, inversedBy="cities", cascade ={"persist"})
  33. * @ORM\JoinColumn(nullable=false)
  34. */
  35. private $department;
  36. /**
  37. * @ORM\OneToMany(targetEntity=Subdivision::class, mappedBy="city", orphanRemoval=true)
  38. */
  39. private $subdivisions;
  40. public function __construct()
  41. {
  42. $this->subdivisions = new ArrayCollection();
  43. $this->setUpdateAt(new \DateTime());
  44. }
  45. public function getId(): ?int
  46. {
  47. return $this->id;
  48. }
  49. public function getName(): ?string
  50. {
  51. return $this->name;
  52. }
  53. public function setName(string $name): self
  54. {
  55. $this->name = $name;
  56. return $this;
  57. }
  58. public function getDescription(): ?string
  59. {
  60. return $this->description;
  61. }
  62. public function setDescription(?string $description): self
  63. {
  64. $this->description = $description;
  65. return $this;
  66. }
  67. public function getUpdateAt(): ?\DateTimeInterface
  68. {
  69. return $this->updateAt;
  70. }
  71. public function setUpdateAt(?\DateTimeInterface $updateAt): self
  72. {
  73. $this->updateAt = $updateAt;
  74. return $this;
  75. }
  76. public function getDepartment(): ?Department
  77. {
  78. return $this->department;
  79. }
  80. public function setDepartment(?Department $department): self
  81. {
  82. $this->department = $department;
  83. return $this;
  84. }
  85. /**
  86. * @return Collection|Subdivision[]
  87. */
  88. public function getSubdivisions(): Collection
  89. {
  90. return $this->subdivisions;
  91. }
  92. public function addSubdivision(Subdivision $subdivision): self
  93. {
  94. if (!$this->subdivisions->contains($subdivision)) {
  95. $this->subdivisions[] = $subdivision;
  96. $subdivision->setCity($this);
  97. }
  98. return $this;
  99. }
  100. public function removeSubdivision(Subdivision $subdivision): self
  101. {
  102. if ($this->subdivisions->contains($subdivision)) {
  103. $this->subdivisions->removeElement($subdivision);
  104. // set the owning side to null (unless already changed)
  105. if ($subdivision->getCity() === $this) {
  106. $subdivision->setCity(null);
  107. }
  108. }
  109. return $this;
  110. }
  111. public function __toString() {
  112. return $this->getName();
  113. }
  114. /**
  115. * @ORM\PreUpdate
  116. */
  117. public function __updateDate() {
  118. $this->setUpdateAt(new \DateTime());
  119. }
  120. }