src/Entity/Region.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RegionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=RegionRepository::class)
  9. * @ORM\HasLifecycleCallbacks()
  10. */
  11. class Region
  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\ManyToOne(targetEntity=Country::class, inversedBy="regions")
  29. * @ORM\JoinColumn(nullable=false)
  30. */
  31. private $country;
  32. /**
  33. * @ORM\Column(type="datetime", nullable=true)
  34. */
  35. private $updateAt;
  36. /**
  37. * @ORM\OneToMany(targetEntity=Department::class, mappedBy="region")
  38. */
  39. private $departments;
  40. public function __construct()
  41. {
  42. $this->departments = 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 getCountry(): ?Country
  68. {
  69. return $this->country;
  70. }
  71. public function setCountry(?Country $country): self
  72. {
  73. $this->country = $country;
  74. return $this;
  75. }
  76. public function getUpdateAt(): ?\DateTimeInterface
  77. {
  78. return $this->updateAt;
  79. }
  80. public function setUpdateAt(?\DateTimeInterface $updateAt): self
  81. {
  82. $this->updateAt = $updateAt;
  83. return $this;
  84. }
  85. /**
  86. * @return Collection|Department[]
  87. */
  88. public function getDepartments(): Collection
  89. {
  90. return $this->departments;
  91. }
  92. public function addDepartment(Department $department): self
  93. {
  94. if (!$this->departments->contains($department)) {
  95. $this->departments[] = $department;
  96. $department->setRegion($this);
  97. }
  98. return $this;
  99. }
  100. public function removeDepartment(Department $department): self
  101. {
  102. if ($this->departments->contains($department)) {
  103. $this->departments->removeElement($department);
  104. // set the owning side to null (unless already changed)
  105. if ($department->getRegion() === $this) {
  106. $department->setRegion(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. }