src/Entity/Grupo.php line 24

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\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity
  9. * @ORM\Table(indexes={
  10. * @ORM\Index(name="idx_grupo_solicitud", columns={"solicitud_accion_formativa_id"}),
  11. * @ORM\Index(name="idx_grupo_deleted_at", columns={"deleted_at"}),
  12. * @ORM\Index(name="idx_grupo_updated_at", columns={"updated_at"}),
  13. * @ORM\Index(name="idx_grupo_deleted_solicitud", columns={"deleted_at","solicitud_accion_formativa_id"}),
  14. * @ORM\Index(name="idx_grupo_deleted_updated", columns={"deleted_at","updated_at"}),
  15. * @ORM\Index(
  16. * name="idx_grupo_deleted_solicitud_updated",
  17. * columns={"deleted_at","solicitud_accion_formativa_id","updated_at"}
  18. * )
  19. * })
  20. */
  21. class Grupo extends \App\Entity\BaseEntity
  22. {
  23. /**
  24. * @ORM\Id
  25. * @ORM\Column(type="integer")
  26. * @ORM\GeneratedValue(strategy="AUTO")
  27. */
  28. private $id;
  29. /**
  30. * @ORM\Column(type="datetime", nullable=true, name="deleted_at")
  31. */
  32. private $deletedAt;
  33. /**
  34. * @ORM\Column(type="datetime", nullable=false, name="updated_at", options={"default":"2024-01-01 00:00:00"})
  35. */
  36. private $updatedAt;
  37. /**
  38. * @ORM\Column(type="datetime", nullable=false, name="created_at", options={"default":"2024-01-01 00:00:00"})
  39. */
  40. private $createdAt;
  41. /**
  42. * @ORM\Column(type="string", nullable=true, name="id_externo")
  43. */
  44. private $idExterno;
  45. /**
  46. * @ORM\Column(type="datetime", nullable=true)
  47. */
  48. private $fechaInicio;
  49. /**
  50. * @ORM\Column(type="datetime", nullable=true)
  51. */
  52. private $fechaFinal;
  53. /**
  54. * @ORM\Column(type="datetime", nullable=true)
  55. */
  56. private $fechaLimiteNuevoParticipantes;
  57. /**
  58. * @ORM\Column(type="string", nullable=true)
  59. */
  60. private $horario;
  61. /**
  62. * @ORM\Column(type="integer", nullable=true)
  63. */
  64. private $numeroGrup;
  65. /**
  66. * @ORM\Column(type="boolean", nullable=true, options={"default":false})
  67. */
  68. private bool $inscripcionCerrada = false;
  69. /**
  70. * @ORM\OneToMany(targetEntity=\App\Entity\Imparte::class, mappedBy="grupo")
  71. */
  72. private $impartes;
  73. /**
  74. * @ORM\OneToMany(targetEntity=\App\Entity\ParticipantesGrupo::class, mappedBy="grupo")
  75. */
  76. private $participantesGrupos;
  77. /**
  78. * @ORM\OneToMany(targetEntity=\App\Entity\GrupoSesiones::class, mappedBy="grupo")
  79. */
  80. private $grupoSesiones;
  81. /**
  82. * @ORM\OneToMany(targetEntity=\App\Entity\CentroFormacionAcogeGrupo::class, mappedBy="grupo")
  83. */
  84. private $centroFormacionAcogeGrupos;
  85. /**
  86. * @ORM\ManyToOne(targetEntity=\App\Entity\SolicitudAccionFormativa::class, inversedBy="grupos")
  87. * @ORM\JoinColumn(name="solicitud_accion_formativa_id", referencedColumnName="id")
  88. */
  89. private $solicitudAccionFormativa;
  90. /**
  91. * @ORM\ManyToMany(targetEntity=\App\Entity\UsuarioHermes::class, mappedBy="gruposInteres")
  92. */
  93. private $usuarioHermesInteres;
  94. /**
  95. * @ORM\ManyToMany(targetEntity=\App\Entity\UsuarioHermes::class, mappedBy="gruposFavorito")
  96. */
  97. private $usuarioHermesFavorito;
  98. public function __construct()
  99. {
  100. $this->participantesGrupos = new ArrayCollection();
  101. $this->grupoSesiones = new ArrayCollection();
  102. $this->centroFormacionAcogeGrupos = new ArrayCollection();
  103. $this->impartes = new ArrayCollection();
  104. $this->usuarioHermesFavorito = new ArrayCollection();
  105. $this->usuarioHermesInteres = new ArrayCollection();
  106. }
  107. public function getId(): ?int
  108. {
  109. return $this->id;
  110. }
  111. public function setId($id)
  112. {
  113. $this->id = $id;
  114. return $this;
  115. }
  116. public function getDeletedAt(): ?\DateTimeInterface
  117. {
  118. return $this->deletedAt;
  119. }
  120. public function setDeletedAt(?\DateTimeInterface $deletedAt): static
  121. {
  122. $this->deletedAt = $deletedAt;
  123. return $this;
  124. }
  125. public function getUpdatedAt(): ?\DateTimeInterface
  126. {
  127. return $this->updatedAt;
  128. }
  129. public function setUpdatedAt(\DateTimeInterface $updatedAt): static
  130. {
  131. $this->updatedAt = $updatedAt;
  132. return $this;
  133. }
  134. public function getCreatedAt(): ?\DateTimeInterface
  135. {
  136. return $this->createdAt;
  137. }
  138. public function setCreatedAt(\DateTimeInterface $createdAt): static
  139. {
  140. $this->createdAt = $createdAt;
  141. return $this;
  142. }
  143. public function getIdExterno(): ?string
  144. {
  145. return $this->idExterno;
  146. }
  147. public function setIdExterno(?string $idExterno): static
  148. {
  149. $this->idExterno = $idExterno;
  150. return $this;
  151. }
  152. /**
  153. * @return Collection<int, ParticipantesGrupo>
  154. */
  155. public function getParticipantesGrupos(): Collection
  156. {
  157. return $this->participantesGrupos;
  158. }
  159. public function addParticipantesGrupo(ParticipantesGrupo $participantesGrupo): static
  160. {
  161. if (!$this->participantesGrupos->contains($participantesGrupo)) {
  162. $this->participantesGrupos->add($participantesGrupo);
  163. $participantesGrupo->setGrupo($this);
  164. }
  165. return $this;
  166. }
  167. public function removeParticipantesGrupo(ParticipantesGrupo $participantesGrupo): static
  168. {
  169. if ($this->participantesGrupos->removeElement($participantesGrupo)) {
  170. // set the owning side to null (unless already changed)
  171. if ($participantesGrupo->getGrupo() === $this) {
  172. $participantesGrupo->setGrupo(null);
  173. }
  174. }
  175. return $this;
  176. }
  177. /**
  178. * @return Collection<int, GrupoSesiones>
  179. */
  180. public function getGrupoSesiones(): Collection
  181. {
  182. return $this->grupoSesiones;
  183. }
  184. public function addGrupoSesione(GrupoSesiones $grupoSesione): static
  185. {
  186. if (!$this->grupoSesiones->contains($grupoSesione)) {
  187. $this->grupoSesiones->add($grupoSesione);
  188. $grupoSesione->setGrupo($this);
  189. }
  190. return $this;
  191. }
  192. public function removeGrupoSesione(GrupoSesiones $grupoSesione): static
  193. {
  194. if ($this->grupoSesiones->removeElement($grupoSesione)) {
  195. // set the owning side to null (unless already changed)
  196. if ($grupoSesione->getGrupo() === $this) {
  197. $grupoSesione->setGrupo(null);
  198. }
  199. }
  200. return $this;
  201. }
  202. public function getSolicitudAccionFormativa(): ?SolicitudAccionFormativa
  203. {
  204. return $this->solicitudAccionFormativa;
  205. }
  206. public function setSolicitudAccionFormativa(?SolicitudAccionFormativa $solicitudAccionFormativa): static
  207. {
  208. $this->solicitudAccionFormativa = $solicitudAccionFormativa;
  209. return $this;
  210. }
  211. /**
  212. * @return Collection<int, CentroFormacionAcogeGrupo>
  213. */
  214. public function getCentroFormacionAcogeGrupos(): Collection
  215. {
  216. return $this->centroFormacionAcogeGrupos;
  217. }
  218. public function addCentroFormacionAcogeGrupo(CentroFormacionAcogeGrupo $centroFormacionAcogeGrupo): static
  219. {
  220. if (!$this->centroFormacionAcogeGrupos->contains($centroFormacionAcogeGrupo)) {
  221. $this->centroFormacionAcogeGrupos->add($centroFormacionAcogeGrupo);
  222. $centroFormacionAcogeGrupo->setGrupo($this);
  223. }
  224. return $this;
  225. }
  226. public function removeCentroFormacionAcogeGrupo(CentroFormacionAcogeGrupo $centroFormacionAcogeGrupo): static
  227. {
  228. if ($this->centroFormacionAcogeGrupos->removeElement($centroFormacionAcogeGrupo)) {
  229. // set the owning side to null (unless already changed)
  230. if ($centroFormacionAcogeGrupo->getGrupo() === $this) {
  231. $centroFormacionAcogeGrupo->setGrupo(null);
  232. }
  233. }
  234. return $this;
  235. }
  236. public function getFechaInicio(): ?\DateTimeInterface
  237. {
  238. return $this->fechaInicio;
  239. }
  240. public function setFechaInicio(?\DateTimeInterface $fechaInicio): static
  241. {
  242. $this->fechaInicio = $fechaInicio;
  243. return $this;
  244. }
  245. public function getFechaFinal(): ?\DateTimeInterface
  246. {
  247. return $this->fechaFinal;
  248. }
  249. public function setFechaFinal(?\DateTimeInterface $fechaFinal): static
  250. {
  251. $this->fechaFinal = $fechaFinal;
  252. return $this;
  253. }
  254. public function getFechaLimiteNuevoParticipantes(): ?\DateTimeInterface
  255. {
  256. return $this->fechaLimiteNuevoParticipantes;
  257. }
  258. public function setFechaLimiteNuevoParticipantes(?\DateTimeInterface $fechaLimiteNuevoParticipantes): static
  259. {
  260. $this->fechaLimiteNuevoParticipantes = $fechaLimiteNuevoParticipantes;
  261. return $this;
  262. }
  263. /**
  264. * @return Collection<int, Imparte>
  265. */
  266. public function getImpartes(): Collection
  267. {
  268. return $this->impartes;
  269. }
  270. public function addImparte(Imparte $imparte): static
  271. {
  272. if (!$this->impartes->contains($imparte)) {
  273. $this->impartes->add($imparte);
  274. $imparte->setGrupo($this);
  275. }
  276. return $this;
  277. }
  278. public function removeImparte(Imparte $imparte): static
  279. {
  280. if ($this->impartes->removeElement($imparte)) {
  281. // set the owning side to null (unless already changed)
  282. if ($imparte->getGrupo() === $this) {
  283. $imparte->setGrupo(null);
  284. }
  285. }
  286. return $this;
  287. }
  288. /**
  289. * @return Collection<int, UsuarioHermes>
  290. */
  291. public function getUsuarioHermesInteres(): Collection
  292. {
  293. return $this->usuarioHermesInteres;
  294. }
  295. public function addUsuarioHermesIntere(UsuarioHermes $usuarioHermesIntere): static
  296. {
  297. if (!$this->usuarioHermesInteres->contains($usuarioHermesIntere)) {
  298. $this->usuarioHermesInteres->add($usuarioHermesIntere);
  299. $usuarioHermesIntere->addGruposIntere($this);
  300. }
  301. return $this;
  302. }
  303. public function removeUsuarioHermesIntere(UsuarioHermes $usuarioHermesIntere): static
  304. {
  305. if ($this->usuarioHermesInteres->removeElement($usuarioHermesIntere)) {
  306. $usuarioHermesIntere->removeGruposIntere($this);
  307. }
  308. return $this;
  309. }
  310. /**
  311. * @return Collection<int, UsuarioHermes>
  312. */
  313. public function getUsuarioHermesFavorito(): Collection
  314. {
  315. return $this->usuarioHermesFavorito;
  316. }
  317. public function addUsuarioHermesFavorito(UsuarioHermes $usuarioHermesFavorito): static
  318. {
  319. if (!$this->usuarioHermesFavorito->contains($usuarioHermesFavorito)) {
  320. $this->usuarioHermesFavorito->add($usuarioHermesFavorito);
  321. $usuarioHermesFavorito->addGruposFavorito($this);
  322. }
  323. return $this;
  324. }
  325. public function removeUsuarioHermesFavorito(UsuarioHermes $usuarioHermesFavorito): static
  326. {
  327. if ($this->usuarioHermesFavorito->removeElement($usuarioHermesFavorito)) {
  328. $usuarioHermesFavorito->removeGruposFavorito($this);
  329. }
  330. return $this;
  331. }
  332. public function getCursoNombre(): ?array
  333. {
  334. return $this->getSolicitudAccionFormativa()?->getCurso()?->getNombre();
  335. }
  336. public function getCentroNombre(): ?string
  337. {
  338. $centros = [];
  339. if($this->getCentroFormacionAcogeGrupos()->count())
  340. {
  341. foreach ($this->getCentroFormacionAcogeGrupos() as $centro)
  342. {
  343. $centros[] = $centro->getCentroFormacion()->getRazonSocial();
  344. }
  345. }
  346. return implode(' - ', $centros);
  347. }
  348. public function getHorario(): ?string
  349. {
  350. return $this->horario;
  351. }
  352. public function setHorario(?string $horario): static
  353. {
  354. $this->horario = $horario;
  355. return $this;
  356. }
  357. public function getNumeroGrup(): ?int
  358. {
  359. return $this->numeroGrup;
  360. }
  361. public function setNumeroGrup(?int $numeroGrup): static
  362. {
  363. $this->numeroGrup = $numeroGrup;
  364. return $this;
  365. }
  366. public function isInscripcionCerrada(): bool
  367. {
  368. return $this->inscripcionCerrada;
  369. }
  370. public function setInscripcionCerrada(bool $inscripcionCerrada): self
  371. {
  372. $this->inscripcionCerrada = $inscripcionCerrada;
  373. return $this;
  374. }
  375. /**
  376. * Determina si la inscripción al grupo está cerrada,
  377. * ya sea por fecha límite o por cierre manual.
  378. */
  379. public function isEfectivamenteCerrado(): bool
  380. {
  381. // Condición 1: Cierre manual activado
  382. if ($this->isInscripcionCerrada()) {
  383. return true;
  384. }
  385. // Condición 2: La fecha límite ha pasado
  386. if ($this->getFechaLimiteNuevoParticipantes() !== null && new \DateTime() > $this->getFechaLimiteNuevoParticipantes()) {
  387. return true;
  388. }
  389. return false;
  390. }
  391. /**
  392. * Determina si un grupo cerrado manualmente puede ser reabierto.
  393. * Un grupo se puede reabrir solo si fue cerrado manualmente
  394. * y si la fecha límite de inscripción aún no ha pasado (o no hay fecha límite).
  395. */
  396. public function puedeReabrirse(): bool
  397. {
  398. return $this->isInscripcionCerrada() &&
  399. ($this->getFechaLimiteNuevoParticipantes() === null || new \DateTime() < $this->getFechaLimiteNuevoParticipantes());
  400. }
  401. }