src/Entity/Country.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CountryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=CountryRepository::class)
  9. * @ORM\HasLifecycleCallbacks()
  10. */
  11. class Country
  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="string", length=255, nullable=true)
  25. */
  26. private $description;
  27. /**
  28. * @ORM\Column(type="datetime", nullable=true)
  29. */
  30. private $updateAt;
  31. /**
  32. * @ORM\OneToMany(targetEntity=Region::class, mappedBy="country", orphanRemoval=true)
  33. */
  34. private $regions;
  35. public function __construct()
  36. {
  37. $this->regions = new ArrayCollection();
  38. $this->setUpdateAt(new \DateTime());
  39. }
  40. public function getId(): ?int
  41. {
  42. return $this->id;
  43. }
  44. public function getName(): ?string
  45. {
  46. return $this->name;
  47. }
  48. public function setName(string $name): self
  49. {
  50. $this->name = $name;
  51. return $this;
  52. }
  53. public function getDescription(): ?string
  54. {
  55. return $this->description;
  56. }
  57. public function setDescription(?string $description): self
  58. {
  59. $this->description = $description;
  60. return $this;
  61. }
  62. public function getUpdateAt(): ?\DateTimeInterface
  63. {
  64. return $this->updateAt;
  65. }
  66. public function setUpdateAt(?\DateTimeInterface $updateAt): self
  67. {
  68. $this->updateAt = $updateAt;
  69. return $this;
  70. }
  71. /**
  72. * @return Collection|Region[]
  73. */
  74. public function getRegions(): Collection
  75. {
  76. return $this->regions;
  77. }
  78. public function addRegion(Region $region): self
  79. {
  80. if (!$this->regions->contains($region)) {
  81. $this->regions[] = $region;
  82. $region->setCountry($this);
  83. }
  84. return $this;
  85. }
  86. public function removeRegion(Region $region): self
  87. {
  88. if ($this->regions->contains($region)) {
  89. $this->regions->removeElement($region);
  90. // set the owning side to null (unless already changed)
  91. if ($region->getCountry() === $this) {
  92. $region->setCountry(null);
  93. }
  94. }
  95. return $this;
  96. }
  97. public function __toString() {
  98. return $this->getName();
  99. }
  100. /**
  101. * @ORM\PreUpdate
  102. */
  103. public function __updateDate() {
  104. $this->setUpdateAt(new \DateTime());
  105. }
  106. }