src/Entity/Country.php line 16

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. use Gedmo\Mapping\Annotation as Gedmo;
  8. use JMS\Serializer\Annotation as Serializer;
  9. /**
  10. * @ORM\Entity(repositoryClass=CountryRepository::class)
  11. * @Serializer\ExclusionPolicy("ALL")
  12. */
  13. class Country
  14. {
  15. /**
  16. * @ORM\Id
  17. * @ORM\GeneratedValue
  18. * @ORM\Column(type="integer")
  19. * @Serializer\Expose
  20. */
  21. private $id;
  22. /**
  23. * @ORM\Column(type="string", length=191, unique=true)
  24. * @Serializer\Expose
  25. */
  26. private $name;
  27. /**
  28. * @ORM\OneToMany(targetEntity=Visitor::class, mappedBy="country")
  29. */
  30. private $visitors;
  31. /**
  32. * @ORM\OneToMany(targetEntity=User::class, mappedBy="country")
  33. */
  34. private $users;
  35. /**
  36. * @ORM\Column(type="string", length=255, nullable=true)
  37. * @Serializer\Expose
  38. */
  39. private $code;
  40. /**
  41. * @Gedmo\Slug(fields={"name"})
  42. * @ORM\Column(length=191)
  43. */
  44. private $slug;
  45. /**
  46. * @ORM\OneToMany(targetEntity=SubsidiaryCompany::class, mappedBy="country")
  47. */
  48. private $subsidiaryCompanies;
  49. public function __construct()
  50. {
  51. $this->visitors = new ArrayCollection();
  52. $this->users = new ArrayCollection();
  53. $this->subsidiaryCompanies = new ArrayCollection();
  54. }
  55. public function getId(): ?int
  56. {
  57. return $this->id;
  58. }
  59. public function getName(): ?string
  60. {
  61. return $this->name;
  62. }
  63. public function setName(string $name): self
  64. {
  65. $this->name = $name;
  66. return $this;
  67. }
  68. /**
  69. * @return Collection<int, Visitor>
  70. */
  71. public function getVisitors(): Collection
  72. {
  73. return $this->visitors;
  74. }
  75. public function addVisitor(Visitor $visitor): self
  76. {
  77. if (!$this->visitors->contains($visitor)) {
  78. $this->visitors[] = $visitor;
  79. $visitor->setCountry($this);
  80. }
  81. return $this;
  82. }
  83. public function removeVisitor(Visitor $visitor): self
  84. {
  85. if ($this->visitors->removeElement($visitor)) {
  86. // set the owning side to null (unless already changed)
  87. if ($visitor->getCountry() === $this) {
  88. $visitor->setCountry(null);
  89. }
  90. }
  91. return $this;
  92. }
  93. /**
  94. * @return Collection<int, User>
  95. */
  96. public function getUsers(): Collection
  97. {
  98. return $this->users;
  99. }
  100. public function addUser(User $user): self
  101. {
  102. if (!$this->users->contains($user)) {
  103. $this->users[] = $user;
  104. $user->setCountry($this);
  105. }
  106. return $this;
  107. }
  108. public function removeUser(User $user): self
  109. {
  110. if ($this->users->removeElement($user)) {
  111. // set the owning side to null (unless already changed)
  112. if ($user->getCountry() === $this) {
  113. $user->setCountry(null);
  114. }
  115. }
  116. return $this;
  117. }
  118. public function getCode(): ?string
  119. {
  120. return $this->code;
  121. }
  122. public function setCode(?string $code): self
  123. {
  124. $this->code = $code;
  125. return $this;
  126. }
  127. /**
  128. * @return Collection<int, SubsidiaryCompany>
  129. */
  130. public function getSubsidiaryCompanies(): Collection
  131. {
  132. return $this->subsidiaryCompanies;
  133. }
  134. public function addSubsidiaryCompany(SubsidiaryCompany $subsidiaryCompany): self
  135. {
  136. if (!$this->subsidiaryCompanies->contains($subsidiaryCompany)) {
  137. $this->subsidiaryCompanies[] = $subsidiaryCompany;
  138. $subsidiaryCompany->setCountry($this);
  139. }
  140. return $this;
  141. }
  142. public function removeSubsidiaryCompany(SubsidiaryCompany $subsidiaryCompany): self
  143. {
  144. if ($this->subsidiaryCompanies->removeElement($subsidiaryCompany)) {
  145. // set the owning side to null (unless already changed)
  146. if ($subsidiaryCompany->getCountry() === $this) {
  147. $subsidiaryCompany->setCountry(null);
  148. }
  149. }
  150. return $this;
  151. }
  152. }