src/Entity/Country.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. /**
  9. * @ORM\Entity()
  10. * @UniqueEntity("libelle")
  11. * @UniqueEntity("code")
  12. * @ORM\Table(uniqueConstraints={
  13. * @ORM\UniqueConstraint(columns={"label", "code"})
  14. * })
  15. */
  16. class Country
  17. {
  18. /**
  19. * @ORM\Id
  20. * @ORM\GeneratedValue
  21. * @ORM\Column(type="integer")
  22. */
  23. private ?int $id = null;
  24. /**
  25. * @ORM\Column(type="string")
  26. * @Assert\NotBlank()
  27. * @Assert\Type("string")
  28. */
  29. private ?string $label = '';
  30. /**
  31. * @ORM\Column(type="string")
  32. * @Assert\NotBlank()
  33. * @Assert\Type("string")
  34. */
  35. private ?string $code = '';
  36. /**
  37. * @ORM\Column(type="string")
  38. * @Assert\NotBlank()
  39. * @Assert\Type("string")
  40. */
  41. private ?string $code3 = '';
  42. /**
  43. * @ORM\Column(type="string", nullable="true")
  44. * @Assert\Type("string")
  45. */
  46. private ?string $codeINSEE = null;
  47. /**
  48. * @ORM\OneToMany(targetEntity=User::class, mappedBy="country")
  49. */
  50. private Collection $users;
  51. public function __construct()
  52. {
  53. $this->users = new ArrayCollection();
  54. }
  55. /**
  56. * @return string
  57. */
  58. public function __toString(): string
  59. {
  60. return $this->label;
  61. }
  62. /**
  63. * @return int|null
  64. */
  65. public function getId(): ?int
  66. {
  67. return $this->id;
  68. }
  69. /**
  70. * @return string
  71. */
  72. public function getLabel(): string
  73. {
  74. return $this->label;
  75. }
  76. /**
  77. * @param string $label
  78. * @return Country
  79. */
  80. public function setLabel(string $label): Country
  81. {
  82. $this->label = trim($label);
  83. return $this;
  84. }
  85. /**
  86. * @return string
  87. */
  88. public function getCode(): string
  89. {
  90. return $this->code;
  91. }
  92. /**
  93. * @param string $code
  94. * @return Country
  95. */
  96. public function setCode(string $code): Country
  97. {
  98. $this->code = trim($code);
  99. return $this;
  100. }
  101. /**
  102. * @return ?string
  103. */
  104. public function getCodeINSEE(): ?string
  105. {
  106. return $this->codeINSEE;
  107. }
  108. /**
  109. * @param string $codeINSEE
  110. * @return Country
  111. */
  112. public function setCodeINSEE(?string $codeINSEE = null): Country
  113. {
  114. $this->codeINSEE = $codeINSEE;
  115. return $this;
  116. }
  117. /**
  118. * @return bool
  119. */
  120. public function isEtranger(): bool
  121. {
  122. return $this->label != 'France';
  123. }
  124. /**
  125. * @return bool
  126. */
  127. public function isFrance(): bool
  128. {
  129. return $this->label == 'France';
  130. }
  131. /**
  132. * @return string
  133. */
  134. public function getCode3(): string
  135. {
  136. return $this->code3;
  137. }
  138. /**
  139. * @param string $code3
  140. * @return Country
  141. */
  142. public function setCode3(string $code3): Country
  143. {
  144. $this->code3 = $code3;
  145. return $this;
  146. }
  147. /**
  148. * @return Collection|User[]
  149. */
  150. public function getUsers(): Collection
  151. {
  152. return $this->users;
  153. }
  154. public function addUser(User $user): self
  155. {
  156. if (!$this->users->contains($user)) {
  157. $this->users[] = $user;
  158. $user->setCountry($this);
  159. }
  160. return $this;
  161. }
  162. }