src/Entity/TipoReserva.php line 15

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\Serializer\Annotation\Groups;
  7. /**
  8. * Entidad que representa un tipo de recurso en el sistema
  9. *
  10. * @ORM\Entity
  11. */
  12. class TipoReserva
  13. {
  14. /**
  15. * ID del tipo de recurso
  16. *
  17. * @ORM\Id
  18. * @ORM\Column(type="integer")
  19. * @ORM\GeneratedValue(strategy="AUTO")
  20. * @Groups({"tipo_recurso_read", "recurso_read", "recurso_write"})
  21. */
  22. private $id;
  23. /**
  24. * Nombre del tipo de recurso
  25. *
  26. * @ORM\Column(type="string", length=100, nullable=true)
  27. * @Groups({"tipo_recurso_read", "recurso_read", "recurso_write"})
  28. */
  29. private $nombre;
  30. /**
  31. * @ORM\OneToMany(targetEntity=\App\Entity\Reserva::class, mappedBy="tipoReserva")
  32. */
  33. private $reservas;
  34. /**
  35. * Descripción del tipo de recurso
  36. *
  37. * @ORM\Column(type="string", length=255, nullable=true)
  38. * @Groups({"tipo_recurso_read", "recurso_read"})
  39. */
  40. private $descripcion;
  41. /**
  42. * Código del tipo de recurso
  43. *
  44. * @ORM\Column(type="string", length=50, nullable=true)
  45. * @Groups({"tipo_recurso_read", "recurso_read"})
  46. */
  47. private $codigo;
  48. /**
  49. * Recursos asociados a este tipo
  50. * @ORM\OneToMany(targetEntity=\App\Entity\Recurso::class, mappedBy="tipoReserva")
  51. */
  52. private $recursos;
  53. /**
  54. * Constructor
  55. */
  56. public function __construct()
  57. {
  58. $this->recursos = new ArrayCollection();
  59. $this->reservas = new ArrayCollection();
  60. }
  61. /**
  62. * Obtiene el ID del tipo de recurso
  63. *
  64. * @return int|null ID del tipo de recurso
  65. */
  66. public function getId(): ?int
  67. {
  68. return $this->id;
  69. }
  70. /**
  71. * Establece el ID del tipo de recurso
  72. *
  73. * @param int|null $id ID del tipo de recurso
  74. *
  75. * @return self
  76. */
  77. public function setId(?int $id): self
  78. {
  79. $this->id = $id;
  80. return $this;
  81. }
  82. /**
  83. * Obtiene el nombre del tipo de recurso
  84. *
  85. * @return string|null Nombre del tipo de recurso
  86. */
  87. public function getNombre(): ?string
  88. {
  89. return $this->nombre;
  90. }
  91. /**
  92. * Establece el nombre del tipo de recurso
  93. *
  94. * @param string $nombre Nombre del tipo de recurso
  95. *
  96. * @return self
  97. */
  98. public function setNombre(string $nombre): self
  99. {
  100. $this->nombre = $nombre;
  101. return $this;
  102. }
  103. /**
  104. * Obtiene la descripción del tipo de recurso
  105. *
  106. * @return string|null Descripción del tipo de recurso
  107. */
  108. public function getDescripcion(): ?string
  109. {
  110. return $this->descripcion;
  111. }
  112. /**
  113. * Establece la descripción del tipo de recurso
  114. *
  115. * @param string|null $descripcion Descripción del tipo de recurso
  116. *
  117. * @return self
  118. */
  119. public function setDescripcion(?string $descripcion): self
  120. {
  121. $this->descripcion = $descripcion;
  122. return $this;
  123. }
  124. /**
  125. * Obtiene el código del tipo de recurso
  126. *
  127. * @return string|null Código del tipo de recurso
  128. */
  129. public function getCodigo(): ?string
  130. {
  131. return $this->codigo;
  132. }
  133. /**
  134. * Establece el código del tipo de recurso
  135. *
  136. * @param string|null $codigo Código del tipo de recurso
  137. *
  138. * @return self
  139. */
  140. public function setCodigo(?string $codigo): self
  141. {
  142. $this->codigo = $codigo;
  143. return $this;
  144. }
  145. /**
  146. * Obtiene los recursos asociados a este tipo
  147. *
  148. * @return Collection|Recurso[] Recursos asociados
  149. */
  150. public function getRecursos(): Collection
  151. {
  152. return $this->recursos;
  153. }
  154. /**
  155. * Agrega un recurso a este tipo
  156. *
  157. * @param Recurso $recurso Recurso a agregar
  158. *
  159. * @return self
  160. */
  161. public function addRecurso(Recurso $recurso): self
  162. {
  163. if (!$this->recursos->contains($recurso)) {
  164. $this->recursos[] = $recurso;
  165. $recurso->setTipoRecurso($this);
  166. }
  167. return $this;
  168. }
  169. /**
  170. * Elimina un recurso de este tipo
  171. *
  172. * @param Recurso $recurso Recurso a eliminar
  173. *
  174. * @return self
  175. */
  176. public function removeRecurso(Recurso $recurso): self
  177. {
  178. if ($this->recursos->removeElement($recurso)) {
  179. // Establecer el lado propietario como null (a menos que ya haya cambiado)
  180. if ($recurso->getTipoRecurso() === $this) {
  181. $recurso->setTipoRecurso(null);
  182. }
  183. }
  184. return $this;
  185. }
  186. /**
  187. * Convierte el objeto a string
  188. *
  189. * @return string Representación en string
  190. */
  191. public function __toString(): string
  192. {
  193. return (string) $this->nombre;
  194. }
  195. /**
  196. * @return Collection<int, Reserva>
  197. */
  198. public function getReservas(): Collection
  199. {
  200. return $this->reservas;
  201. }
  202. public function addReserva(Reserva $reserva): static
  203. {
  204. if (!$this->reservas->contains($reserva)) {
  205. $this->reservas->add($reserva);
  206. $reserva->setTipoReserva($this);
  207. }
  208. return $this;
  209. }
  210. public function removeReserva(Reserva $reserva): static
  211. {
  212. if ($this->reservas->removeElement($reserva)) {
  213. // set the owning side to null (unless already changed)
  214. if ($reserva->getTipoReserva() === $this) {
  215. $reserva->setTipoReserva(null);
  216. }
  217. }
  218. return $this;
  219. }
  220. }