src/Entity/Provincia.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProvinciaRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as Serializer;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. #[UniqueEntity('slug')]
  11. #[ORM\Entity(repositoryClass: ProvinciaRepository::class)]
  12. class Provincia {
  13. #[ORM\Id]
  14. #[ORM\GeneratedValue]
  15. #[ORM\Column(type: 'integer')]
  16. #[Serializer\Groups(groups: ['api'])]
  17. private $id;
  18. #[Assert\NotBlank]
  19. #[ORM\Column(type: 'string')]
  20. private ?string $nombre = null;
  21. #[Assert\NotBlank]
  22. #[ORM\ManyToOne(targetEntity: Comunidad::class, inversedBy: 'provincias')]
  23. #[ORM\JoinColumn(nullable: false)]
  24. #[Serializer\Groups(groups: ['api'])]
  25. private ?Comunidad $comunidad = null;
  26. #[ORM\Column(type: 'boolean')]
  27. private bool $visible = true;
  28. #[ORM\Column(type: 'boolean')]
  29. private bool $borrado = false;
  30. #[Assert\NotBlank]
  31. #[Assert\Regex(pattern: '/^[a-z0-9]+(?:-[a-z0-9]+)*$/')]
  32. #[ORM\Column(type: 'string', length: 190, unique: true)]
  33. private ?string $slug = null;
  34. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  35. private ?string $seoTitle = null;
  36. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  37. private ?string $seoDescription = null;
  38. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  39. private ?string $seoKeywords = null;
  40. #[ORM\OneToMany(targetEntity: Comarca::class, mappedBy: 'provincia')]
  41. private Collection $comarcas;
  42. public function __construct()
  43. {
  44. $this->comarcas = new ArrayCollection();
  45. }
  46. public function getId(): ?int
  47. {
  48. return $this->id;
  49. }
  50. public function getNombre(): ?string
  51. {
  52. return $this->nombre;
  53. }
  54. /**
  55. * @param mixed $nombre
  56. */
  57. public function setNombre(?string $nombre): self
  58. {
  59. $this->nombre = $nombre;
  60. return $this;
  61. }
  62. public function getComunidad(): ?Comunidad
  63. {
  64. return $this->comunidad;
  65. }
  66. public function setComunidad(?Comunidad $comunidad): self
  67. {
  68. $this->comunidad = $comunidad;
  69. return $this;
  70. }
  71. public function getSlug(): ?string
  72. {
  73. return $this->slug;
  74. }
  75. public function setSlug(?string $slug): self
  76. {
  77. $this->slug = $slug;
  78. return $this;
  79. }
  80. public function isVisible(): ?bool
  81. {
  82. return $this->visible;
  83. }
  84. public function setVisible(bool $visible): self
  85. {
  86. $this->visible = $visible;
  87. return $this;
  88. }
  89. public function isBorrado(): ?bool
  90. {
  91. return $this->borrado;
  92. }
  93. public function setBorrado(bool $borrado): self
  94. {
  95. $this->borrado = $borrado;
  96. return $this;
  97. }
  98. public function getSeoTitle(): ?string
  99. {
  100. return $this->seoTitle;
  101. }
  102. public function setSeoTitle(?string $seoTitle): self
  103. {
  104. $this->seoTitle = $seoTitle;
  105. return $this;
  106. }
  107. public function getSeoDescription(): ?string
  108. {
  109. return $this->seoDescription;
  110. }
  111. public function setSeoDescription(?string $seoDescription): self
  112. {
  113. $this->seoDescription = $seoDescription;
  114. return $this;
  115. }
  116. public function getSeoKeywords(): ?string
  117. {
  118. return $this->seoKeywords;
  119. }
  120. public function setSeoKeywords(?string $seoKeywords): self
  121. {
  122. $this->seoKeywords = $seoKeywords;
  123. return $this;
  124. }
  125. /**
  126. * @return Collection<int, Comarca>
  127. */
  128. public function getComarcas(): Collection
  129. {
  130. return $this->comarcas;
  131. }
  132. public function addComarca(Comarca $comarca): self
  133. {
  134. if (!$this->comarcas->contains($comarca)) {
  135. $this->comarcas[] = $comarca;
  136. $comarca->setProvincia($this);
  137. }
  138. return $this;
  139. }
  140. public function removeComarca(Comarca $comarca): self
  141. {
  142. // set the owning side to null (unless already changed)
  143. if ($this->comarcas->removeElement($comarca) && $comarca->getProvincia() === $this) {
  144. $comarca->setProvincia(null);
  145. }
  146. return $this;
  147. }
  148. }