src/Entity/Department.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DepartmentRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=DepartmentRepository::class)
  9. * @ORM\HasLifecycleCallbacks()
  10. */
  11. class Department
  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=Region::class, inversedBy="departments")
  33. * @ORM\JoinColumn(nullable=false)
  34. */
  35. private $region;
  36. /**
  37. * @ORM\OneToMany(targetEntity=City::class, mappedBy="department", orphanRemoval=true)
  38. */
  39. private $cities;
  40. public function __construct()
  41. {
  42. $this->cities = new ArrayCollection();
  43. }
  44. public function getId(): ?int
  45. {
  46. return $this->id;
  47. }
  48. public function getName(): ?string
  49. {
  50. return $this->name;
  51. }
  52. public function setName(string $name): self
  53. {
  54. $this->name = $name;
  55. return $this;
  56. }
  57. public function getDescription(): ?string
  58. {
  59. return $this->description;
  60. }
  61. public function setDescription(?string $description): self
  62. {
  63. $this->description = $description;
  64. return $this;
  65. }
  66. public function getUpdateAt(): ?\DateTimeInterface
  67. {
  68. return $this->updateAt;
  69. }
  70. public function setUpdateAt(?\DateTimeInterface $updateAt): self
  71. {
  72. $this->updateAt = $updateAt;
  73. return $this;
  74. }
  75. public function getRegion(): ?Region
  76. {
  77. return $this->region;
  78. }
  79. public function setRegion(?Region $region): self
  80. {
  81. $this->region = $region;
  82. return $this;
  83. }
  84. /**
  85. * @return Collection|City[]
  86. */
  87. public function getCities(): Collection
  88. {
  89. return $this->cities;
  90. }
  91. public function addCity(City $city): self
  92. {
  93. if (!$this->cities->contains($city)) {
  94. $this->cities[] = $city;
  95. $city->setDepartment($this);
  96. }
  97. return $this;
  98. }
  99. public function removeCity(City $city): self
  100. {
  101. if ($this->cities->contains($city)) {
  102. $this->cities->removeElement($city);
  103. // set the owning side to null (unless already changed)
  104. if ($city->getDepartment() === $this) {
  105. $city->setDepartment(null);
  106. }
  107. }
  108. return $this;
  109. }
  110. public function __toString() {
  111. return $this->getName();
  112. }
  113. /**
  114. * @ORM\PreUpdate
  115. */
  116. public function __updateDate() {
  117. $this->setUpdateAt(new \DateTime());
  118. }
  119. }