src/Entity/Comarca.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ComarcaRepository;
  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\Component\Validator\Constraints as Assert;
  9. #[ORM\Entity(repositoryClass: ComarcaRepository::class)]
  10. class Comarca
  11. {
  12. #[ORM\Id]
  13. #[ORM\GeneratedValue]
  14. #[ORM\Column(type: 'integer')]
  15. #[Serializer\Groups(groups: ['api'])]
  16. private $id;
  17. #[Assert\NotBlank]
  18. #[ORM\Column(type: 'string', length: 255)]
  19. #[Serializer\Groups(groups: ['api'])]
  20. private ?string $nombre = null;
  21. #[ORM\Column(type: 'boolean')]
  22. private bool $visible = true;
  23. #[ORM\Column(type: 'boolean')]
  24. private bool $borrado = false;
  25. #[ORM\OneToMany(targetEntity: Localidad::class, mappedBy: 'comarca')]
  26. private Collection $localidades;
  27. #[ORM\ManyToOne(targetEntity: Provincia::class, inversedBy: 'comarcas')]
  28. #[ORM\JoinColumn(nullable: false)]
  29. private ?Provincia $provincia = null;
  30. public function __construct()
  31. {
  32. $this->localidades = new ArrayCollection();
  33. }
  34. public function getId(): ?int
  35. {
  36. return $this->id;
  37. }
  38. public function getNombre(): ?string
  39. {
  40. return $this->nombre;
  41. }
  42. public function setNombre(?string $nombre): self
  43. {
  44. $this->nombre = $nombre;
  45. return $this;
  46. }
  47. public function isVisible(): ?bool
  48. {
  49. return $this->visible;
  50. }
  51. public function setVisible(bool $visible): self
  52. {
  53. $this->visible = $visible;
  54. return $this;
  55. }
  56. public function isBorrado(): ?bool
  57. {
  58. return $this->borrado;
  59. }
  60. public function setBorrado(bool $borrado): self
  61. {
  62. $this->borrado = $borrado;
  63. return $this;
  64. }
  65. /**
  66. * @return Collection<int, Localidad>
  67. */
  68. public function getLocalidades(): Collection
  69. {
  70. return $this->localidades;
  71. }
  72. public function addLocalidade(Localidad $localidade): self
  73. {
  74. if (!$this->localidades->contains($localidade)) {
  75. $this->localidades[] = $localidade;
  76. $localidade->setComarca($this);
  77. }
  78. return $this;
  79. }
  80. public function removeLocalidade(Localidad $localidade): self
  81. {
  82. // set the owning side to null (unless already changed)
  83. if ($this->localidades->removeElement($localidade) && $localidade->getComarca() === $this) {
  84. $localidade->setComarca(null);
  85. }
  86. return $this;
  87. }
  88. public function getProvincia(): ?Provincia
  89. {
  90. return $this->provincia;
  91. }
  92. public function setProvincia(?Provincia $provincia): self
  93. {
  94. $this->provincia = $provincia;
  95. return $this;
  96. }
  97. }