src/Entity/Country.php line 259

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CountryRepository;
  4. use Cocur\Slugify\Slugify;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. /**
  11. * @ORM\Entity(repositoryClass=CountryRepository::class)
  12. * @Vich\Uploadable
  13. */
  14. class Country
  15. {
  16. /**
  17. * @ORM\Id
  18. * @ORM\GeneratedValue
  19. * @ORM\Column(type="integer")
  20. */
  21. private $id;
  22. /**
  23. * @ORM\Column(type="integer", nullable=true)
  24. */
  25. private $position;
  26. /**
  27. * @ORM\Column(type="string", length=255)
  28. */
  29. private $title;
  30. /**
  31. * @ORM\OneToMany(targetEntity=Departement::class, mappedBy="country")
  32. */
  33. private $departements;
  34. /**
  35. * @ORM\Column(type="string", length=255, nullable=true)
  36. */
  37. private $slug;
  38. /**
  39. * @ORM\Column(type="text", nullable=true)
  40. */
  41. private $topDescription;
  42. /**
  43. * @ORM\Column(type="text", nullable=true)
  44. */
  45. private $bottomDescription;
  46. /**
  47. * @ORM\ManyToMany(targetEntity=Sejour::class, mappedBy="themes")
  48. */
  49. private $sejours;
  50. /**
  51. * @ORM\Column(type="string", length=255)
  52. */
  53. private $country;
  54. /**
  55. * @ORM\Column(type="boolean")
  56. */
  57. private $isActive;
  58. /**
  59. * @ORM\Column(type="string", length=255, nullable=true)
  60. */
  61. private $flag;
  62. /**
  63. * @Vich\UploadableField(mapping="frontend_image", fileNameProperty="flag")
  64. *
  65. * @var File|null
  66. */
  67. private $flagFile;
  68. public function __construct()
  69. {
  70. $this->departements = new ArrayCollection();
  71. }
  72. public function getId(): ?int
  73. {
  74. return $this->id;
  75. }
  76. public function getPosition(): ?int
  77. {
  78. return $this->position;
  79. }
  80. public function setPosition(int $pos): self
  81. {
  82. $this->position = $pos;
  83. return $this;
  84. }
  85. public function getTitle(): ?string
  86. {
  87. return $this->title;
  88. }
  89. public function setTitle(string $name): self
  90. {
  91. $this->title = $name;
  92. $slugify = new Slugify();
  93. $this->slug = $slugify->Slugify($name, '_');
  94. return $this;
  95. }
  96. /**
  97. * @return Collection|Departement[]
  98. */
  99. public function getDepartements(): Collection
  100. {
  101. return $this->departements;
  102. }
  103. public function addDepartement(Departement $departement): self
  104. {
  105. if (!$this->departements->contains($departement)) {
  106. $this->departements[] = $departement;
  107. $departement->setCountry($this);
  108. }
  109. return $this;
  110. }
  111. public function removeDepartement(Departement $departement): self
  112. {
  113. if ($this->departements->removeElement($departement)) {
  114. // set the owning side to null (unless already changed)
  115. if ($departement->getCountry() === $this) {
  116. $departement->setCountry(null);
  117. }
  118. }
  119. return $this;
  120. }
  121. public function getSlug(): ?string
  122. {
  123. return $this->slug;
  124. }
  125. public function setSlug(?string $slug): self
  126. {
  127. $this->slug = $slug;
  128. return $this;
  129. }
  130. public function getCountry(): ?string
  131. {
  132. return $this->country;
  133. }
  134. public function setCountry(?string $country): self
  135. {
  136. $this->country = $country;
  137. return $this;
  138. }
  139. public function getTopDescription(): ?string
  140. {
  141. return $this->topDescription;
  142. }
  143. public function setTopDescription(?string $topDescription): self
  144. {
  145. $this->topDescription = $topDescription;
  146. return $this;
  147. }
  148. public function getBottomDescription(): ?string
  149. {
  150. return $this->bottomDescription;
  151. }
  152. public function setBottomDescription(?string $bottomDescription): self
  153. {
  154. $this->bottomDescription = $bottomDescription;
  155. return $this;
  156. }
  157. /**
  158. * @return Collection|Sejour[]
  159. */
  160. public function getSejours(): Collection
  161. {
  162. return $this->sejours;
  163. }
  164. public function addSejour(Sejour $sejour): self
  165. {
  166. if (!$this->sejours->contains($sejour)) {
  167. $this->sejours[] = $sejour;
  168. $sejour->addCountry($this);
  169. }
  170. return $this;
  171. }
  172. public function removeSejour(Sejour $sejour): self
  173. {
  174. if ($this->sejours->removeElement($sejour)) {
  175. $sejour->removeCountry($this);
  176. }
  177. return $this;
  178. }
  179. public function getIsActive(): ?bool
  180. {
  181. return $this->isActive;
  182. }
  183. public function setIsActive(bool $isActive): self
  184. {
  185. $this->isActive = $isActive;
  186. return $this;
  187. }
  188. public function getFlag(): ?string
  189. {
  190. return $this->flag;
  191. }
  192. public function setFlag(?string $flag): self
  193. {
  194. $this->flag = $flag;
  195. if ($flag !== null) {
  196. $this->updatedDate = new \Datetime();
  197. }
  198. return $this;
  199. }
  200. public function getFlagFile(): ?File
  201. {
  202. return $this->flagFile;
  203. }
  204. public function setFlagFile(?File $flagFile): self
  205. {
  206. $this->flagFile = $flagFile;
  207. if ($flagFile) {
  208. // It is required that at least one field changes if you are using doctrine
  209. // otherwise the event listeners won't be called and the file is lost
  210. $this->updatedAt = new \DateTimeImmutable();
  211. }
  212. return $this;
  213. }
  214. }