<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(indexes={
* @ORM\Index(name="idx_grupo_solicitud", columns={"solicitud_accion_formativa_id"}),
* @ORM\Index(name="idx_grupo_deleted_at", columns={"deleted_at"}),
* @ORM\Index(name="idx_grupo_updated_at", columns={"updated_at"}),
* @ORM\Index(name="idx_grupo_deleted_solicitud", columns={"deleted_at","solicitud_accion_formativa_id"}),
* @ORM\Index(name="idx_grupo_deleted_updated", columns={"deleted_at","updated_at"}),
* @ORM\Index(
* name="idx_grupo_deleted_solicitud_updated",
* columns={"deleted_at","solicitud_accion_formativa_id","updated_at"}
* )
* })
*/
class Grupo extends \App\Entity\BaseEntity
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="datetime", nullable=true, name="deleted_at")
*/
private $deletedAt;
/**
* @ORM\Column(type="datetime", nullable=false, name="updated_at", options={"default":"2024-01-01 00:00:00"})
*/
private $updatedAt;
/**
* @ORM\Column(type="datetime", nullable=false, name="created_at", options={"default":"2024-01-01 00:00:00"})
*/
private $createdAt;
/**
* @ORM\Column(type="string", nullable=true, name="id_externo")
*/
private $idExterno;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $fechaInicio;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $fechaFinal;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $fechaLimiteNuevoParticipantes;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $horario;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $numeroGrup;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default":false})
*/
private bool $inscripcionCerrada = false;
/**
* @ORM\OneToMany(targetEntity=\App\Entity\Imparte::class, mappedBy="grupo")
*/
private $impartes;
/**
* @ORM\OneToMany(targetEntity=\App\Entity\ParticipantesGrupo::class, mappedBy="grupo")
*/
private $participantesGrupos;
/**
* @ORM\OneToMany(targetEntity=\App\Entity\GrupoSesiones::class, mappedBy="grupo")
*/
private $grupoSesiones;
/**
* @ORM\OneToMany(targetEntity=\App\Entity\CentroFormacionAcogeGrupo::class, mappedBy="grupo")
*/
private $centroFormacionAcogeGrupos;
/**
* @ORM\ManyToOne(targetEntity=\App\Entity\SolicitudAccionFormativa::class, inversedBy="grupos")
* @ORM\JoinColumn(name="solicitud_accion_formativa_id", referencedColumnName="id")
*/
private $solicitudAccionFormativa;
/**
* @ORM\ManyToMany(targetEntity=\App\Entity\UsuarioHermes::class, mappedBy="gruposInteres")
*/
private $usuarioHermesInteres;
/**
* @ORM\ManyToMany(targetEntity=\App\Entity\UsuarioHermes::class, mappedBy="gruposFavorito")
*/
private $usuarioHermesFavorito;
public function __construct()
{
$this->participantesGrupos = new ArrayCollection();
$this->grupoSesiones = new ArrayCollection();
$this->centroFormacionAcogeGrupos = new ArrayCollection();
$this->impartes = new ArrayCollection();
$this->usuarioHermesFavorito = new ArrayCollection();
$this->usuarioHermesInteres = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
return $this;
}
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deletedAt;
}
public function setDeletedAt(?\DateTimeInterface $deletedAt): static
{
$this->deletedAt = $deletedAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): static
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getIdExterno(): ?string
{
return $this->idExterno;
}
public function setIdExterno(?string $idExterno): static
{
$this->idExterno = $idExterno;
return $this;
}
/**
* @return Collection<int, ParticipantesGrupo>
*/
public function getParticipantesGrupos(): Collection
{
return $this->participantesGrupos;
}
public function addParticipantesGrupo(ParticipantesGrupo $participantesGrupo): static
{
if (!$this->participantesGrupos->contains($participantesGrupo)) {
$this->participantesGrupos->add($participantesGrupo);
$participantesGrupo->setGrupo($this);
}
return $this;
}
public function removeParticipantesGrupo(ParticipantesGrupo $participantesGrupo): static
{
if ($this->participantesGrupos->removeElement($participantesGrupo)) {
// set the owning side to null (unless already changed)
if ($participantesGrupo->getGrupo() === $this) {
$participantesGrupo->setGrupo(null);
}
}
return $this;
}
/**
* @return Collection<int, GrupoSesiones>
*/
public function getGrupoSesiones(): Collection
{
return $this->grupoSesiones;
}
public function addGrupoSesione(GrupoSesiones $grupoSesione): static
{
if (!$this->grupoSesiones->contains($grupoSesione)) {
$this->grupoSesiones->add($grupoSesione);
$grupoSesione->setGrupo($this);
}
return $this;
}
public function removeGrupoSesione(GrupoSesiones $grupoSesione): static
{
if ($this->grupoSesiones->removeElement($grupoSesione)) {
// set the owning side to null (unless already changed)
if ($grupoSesione->getGrupo() === $this) {
$grupoSesione->setGrupo(null);
}
}
return $this;
}
public function getSolicitudAccionFormativa(): ?SolicitudAccionFormativa
{
return $this->solicitudAccionFormativa;
}
public function setSolicitudAccionFormativa(?SolicitudAccionFormativa $solicitudAccionFormativa): static
{
$this->solicitudAccionFormativa = $solicitudAccionFormativa;
return $this;
}
/**
* @return Collection<int, CentroFormacionAcogeGrupo>
*/
public function getCentroFormacionAcogeGrupos(): Collection
{
return $this->centroFormacionAcogeGrupos;
}
public function addCentroFormacionAcogeGrupo(CentroFormacionAcogeGrupo $centroFormacionAcogeGrupo): static
{
if (!$this->centroFormacionAcogeGrupos->contains($centroFormacionAcogeGrupo)) {
$this->centroFormacionAcogeGrupos->add($centroFormacionAcogeGrupo);
$centroFormacionAcogeGrupo->setGrupo($this);
}
return $this;
}
public function removeCentroFormacionAcogeGrupo(CentroFormacionAcogeGrupo $centroFormacionAcogeGrupo): static
{
if ($this->centroFormacionAcogeGrupos->removeElement($centroFormacionAcogeGrupo)) {
// set the owning side to null (unless already changed)
if ($centroFormacionAcogeGrupo->getGrupo() === $this) {
$centroFormacionAcogeGrupo->setGrupo(null);
}
}
return $this;
}
public function getFechaInicio(): ?\DateTimeInterface
{
return $this->fechaInicio;
}
public function setFechaInicio(?\DateTimeInterface $fechaInicio): static
{
$this->fechaInicio = $fechaInicio;
return $this;
}
public function getFechaFinal(): ?\DateTimeInterface
{
return $this->fechaFinal;
}
public function setFechaFinal(?\DateTimeInterface $fechaFinal): static
{
$this->fechaFinal = $fechaFinal;
return $this;
}
public function getFechaLimiteNuevoParticipantes(): ?\DateTimeInterface
{
return $this->fechaLimiteNuevoParticipantes;
}
public function setFechaLimiteNuevoParticipantes(?\DateTimeInterface $fechaLimiteNuevoParticipantes): static
{
$this->fechaLimiteNuevoParticipantes = $fechaLimiteNuevoParticipantes;
return $this;
}
/**
* @return Collection<int, Imparte>
*/
public function getImpartes(): Collection
{
return $this->impartes;
}
public function addImparte(Imparte $imparte): static
{
if (!$this->impartes->contains($imparte)) {
$this->impartes->add($imparte);
$imparte->setGrupo($this);
}
return $this;
}
public function removeImparte(Imparte $imparte): static
{
if ($this->impartes->removeElement($imparte)) {
// set the owning side to null (unless already changed)
if ($imparte->getGrupo() === $this) {
$imparte->setGrupo(null);
}
}
return $this;
}
/**
* @return Collection<int, UsuarioHermes>
*/
public function getUsuarioHermesInteres(): Collection
{
return $this->usuarioHermesInteres;
}
public function addUsuarioHermesIntere(UsuarioHermes $usuarioHermesIntere): static
{
if (!$this->usuarioHermesInteres->contains($usuarioHermesIntere)) {
$this->usuarioHermesInteres->add($usuarioHermesIntere);
$usuarioHermesIntere->addGruposIntere($this);
}
return $this;
}
public function removeUsuarioHermesIntere(UsuarioHermes $usuarioHermesIntere): static
{
if ($this->usuarioHermesInteres->removeElement($usuarioHermesIntere)) {
$usuarioHermesIntere->removeGruposIntere($this);
}
return $this;
}
/**
* @return Collection<int, UsuarioHermes>
*/
public function getUsuarioHermesFavorito(): Collection
{
return $this->usuarioHermesFavorito;
}
public function addUsuarioHermesFavorito(UsuarioHermes $usuarioHermesFavorito): static
{
if (!$this->usuarioHermesFavorito->contains($usuarioHermesFavorito)) {
$this->usuarioHermesFavorito->add($usuarioHermesFavorito);
$usuarioHermesFavorito->addGruposFavorito($this);
}
return $this;
}
public function removeUsuarioHermesFavorito(UsuarioHermes $usuarioHermesFavorito): static
{
if ($this->usuarioHermesFavorito->removeElement($usuarioHermesFavorito)) {
$usuarioHermesFavorito->removeGruposFavorito($this);
}
return $this;
}
public function getCursoNombre(): ?array
{
return $this->getSolicitudAccionFormativa()?->getCurso()?->getNombre();
}
public function getCentroNombre(): ?string
{
$centros = [];
if($this->getCentroFormacionAcogeGrupos()->count())
{
foreach ($this->getCentroFormacionAcogeGrupos() as $centro)
{
$centros[] = $centro->getCentroFormacion()->getRazonSocial();
}
}
return implode(' - ', $centros);
}
public function getHorario(): ?string
{
return $this->horario;
}
public function setHorario(?string $horario): static
{
$this->horario = $horario;
return $this;
}
public function getNumeroGrup(): ?int
{
return $this->numeroGrup;
}
public function setNumeroGrup(?int $numeroGrup): static
{
$this->numeroGrup = $numeroGrup;
return $this;
}
public function isInscripcionCerrada(): bool
{
return $this->inscripcionCerrada;
}
public function setInscripcionCerrada(bool $inscripcionCerrada): self
{
$this->inscripcionCerrada = $inscripcionCerrada;
return $this;
}
/**
* Determina si la inscripción al grupo está cerrada,
* ya sea por fecha límite o por cierre manual.
*/
public function isEfectivamenteCerrado(): bool
{
// Condición 1: Cierre manual activado
if ($this->isInscripcionCerrada()) {
return true;
}
// Condición 2: La fecha límite ha pasado
if ($this->getFechaLimiteNuevoParticipantes() !== null && new \DateTime() > $this->getFechaLimiteNuevoParticipantes()) {
return true;
}
return false;
}
/**
* Determina si un grupo cerrado manualmente puede ser reabierto.
* Un grupo se puede reabrir solo si fue cerrado manualmente
* y si la fecha límite de inscripción aún no ha pasado (o no hay fecha límite).
*/
public function puedeReabrirse(): bool
{
return $this->isInscripcionCerrada() &&
($this->getFechaLimiteNuevoParticipantes() === null || new \DateTime() < $this->getFechaLimiteNuevoParticipantes());
}
}