src/Entity/Sesion.php line 63

  1. <?php
  2. namespace App\Entity;
  3. use Symfony\Component\Serializer\Annotation\Groups;
  4. use Ramsey\Uuid\Uuid;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use App\Trait\UuidTrait;
  10. use App\Trait\TimestampableTrait;
  11. use App\Trait\BlameableTrait;
  12. use App\State\SesionStateProcessor;
  13. use App\State\SesionStateDeleteProcessor;
  14. use App\Repository\SesionRepository;
  15. use App\Entity\User;
  16. use App\Entity\Muestra;
  17. use App\Controller\InformesController;
  18. use App\Controller\CalculosSesionController;
  19. use ApiPlatform\Metadata\Put;
  20. use ApiPlatform\Metadata\Post;
  21. use ApiPlatform\Metadata\Patch;
  22. use ApiPlatform\Metadata\GetCollection;
  23. use ApiPlatform\Metadata\Get;
  24. use ApiPlatform\Metadata\Delete;
  25. use ApiPlatform\Metadata\ApiResource;
  26. use ApiPlatform\Metadata\ApiFilter;
  27. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  28. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  29. ini_set('memory_limit''-1');
  30. #[ORM\Entity(repositoryClassSesionRepository::class)]
  31. #[ApiResource(
  32.     operations: [
  33.         new GetCollection(uriTemplate'sesiones'normalizationContext: ['groups' => ['sesionCollection:read']]),
  34.         new Post(uriTemplate'sesiones'validationContext: ['groups' => ['Default''sesion:create']], denormalizationContext: ['groups' => ['sesion:create']], processorSesionStateProcessor::class),
  35.         new Get(uriTemplate'sesiones/{uuid}'),
  36.         new Get(uriTemplate'sesiones/{uuid}/calculo'controllerCalculosSesionController::class, security"is_granted('ROLE_ADMIN')"),
  37.         new Put(uriTemplate'sesiones/{uuid}'denormalizationContext: ['groups' => ['sesion:update']], processorSesionStateProcessor::class),
  38.         new Patch(uriTemplate'sesiones/{uuid}'denormalizationContext: ['groups' => ['sesion:update']], processorSesionStateProcessor::class),
  39.         new Delete(uriTemplate'sesiones/{uuid}'processorSesionStateDeleteProcessor::class),
  40.     ],
  41.     normalizationContext: ['groups' => ['sesion:read''uuid']],
  42. )]
  43. #[ApiFilter(
  44.     SearchFilter::class,
  45.     properties: [
  46.         'nombre' => 'exact',
  47.         'codigo' => 'exact',
  48.         'estado' => 'exact',
  49.     ]
  50. )]
  51. #[ApiFilter(
  52.     OrderFilter::class,
  53.     properties: [
  54.         'nombre',
  55.         'estado',
  56.         'fecha',
  57.     ]
  58. )]
  59. class Sesion
  60. {
  61.     public const ESTADO_INICIADA 'iniciada';
  62.     public const ESTADO_VALIDADA 'validada';
  63.     public const ESTADO_CALCULADA 'calculada';
  64.     public const ESTADO_FINALIZADA 'finalizada';
  65.     public const ESTADO_CANCELADA 'cancelada';
  66.     public const ESTADO_PENDIENTE 'pendiente';
  67.     public const MODULO 'sesiones';
  68.     use TimestampableTrait;
  69.     use BlameableTrait;
  70.     use UuidTrait;
  71.     #[Groups(['sesion:read''sesion:create''sesion:update''sesionCollection:read'])]
  72.     #[ORM\Column(length255nullabletrue)]
  73.     private ?string $nombre null;
  74.     #[Groups(['sesion:read''sesion:create''sesion:update'])]
  75.     #[ORM\Column(length255nullabletrue)]
  76.     private ?string $descripcion null;
  77.     #[Groups(['sesion:read''sesion:create''sesion:update''sesionCollection:read'])]
  78.     #[ORM\Column(length255nullabletrue)]
  79.     private ?string $codigo null;
  80.     #[Groups(['sesion:read''sesion:create''sesion:update'])]
  81.     #[ORM\Column(nullabletrue)]
  82.     private ?array $temperatura = [];
  83.     #[Groups(['sesion:read''sesion:create''sesion:update''sesionCollection:read'])]
  84.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  85.     private ?\DateTimeInterface $fecha null;
  86.     #[Groups(['sesion:read''sesion:create''sesion:update'])]
  87.     #[ORM\ManyToMany(targetEntityUser::class)]
  88.     private Collection $evaluadores;
  89.     #[Groups(['sesion:read'])]
  90.     #[ORM\ManyToOne]
  91.     #[ORM\JoinColumn(nullablefalse)]
  92.     private ?Empresa $empresa null;
  93.     #[Groups(['sesion:read''sesion:create''sesion:update''sesionCollection:read'])]
  94.     #[ORM\Column(length255nullabletrue)]
  95.     private ?string $estado null;
  96.     #[Groups(['sesion:create''sesion:update'])]
  97.     #[ORM\OneToMany(mappedBy'sesion'targetEntitySesionesValores::class, orphanRemovaltruecascade: ['persist''remove'])]
  98.     private Collection $sesionesValores;
  99.     #[Groups(['sesion:read''sesionCollection:read'])]
  100.     #[ORM\Column(nullabletrue)]
  101.     private ?array $control = [];
  102.     #[Groups(['sesion:update'])]
  103.     private ?array $evaluacion = [];
  104.     #[Groups(['sesion:read''sesion:create''sesion:update'])]
  105.     #[ORM\Column(nullabletrue)]
  106.     private ?array $organizacion = [];
  107.     #[Groups(['sesion:read''sesion:create''sesion:update'])]
  108.     #[ORM\Column(nullabletrue)]
  109.     private array $parametrosMuestra = [];
  110.     #[Groups(['sesion:read''sesion:create''sesion:update'])]
  111.     #[ORM\OneToMany(mappedBy'sesion'targetEntityMuestra::class, cascade: ['persist'])]
  112.     private Collection $muestras;
  113.     #[ORM\Column(typeTypes::TIME_MUTABLEnullabletrue)]
  114.     #[Groups(['sesion:read''sesion:create''sesion:update''sesionCollection:read'])]
  115.     private ?\DateTimeInterface $horaFin null;
  116.     public function __construct()
  117.     {
  118.         $this->evaluadores = new ArrayCollection();
  119.         $this->sesionesValores = new ArrayCollection();
  120.         $this->uuid Uuid::uuid4()->toString();
  121.         $this->muestras = new ArrayCollection();
  122.     }
  123.     public function getId(): ?string
  124.     {
  125.         return $this->id;
  126.     }
  127.     public function getNombre(): ?string
  128.     {
  129.         return $this->nombre;
  130.     }
  131.     public function setNombre(?string $nombre): self
  132.     {
  133.         $this->nombre $nombre;
  134.         return $this;
  135.     }
  136.     public function getDescripcion(): ?string
  137.     {
  138.         return $this->descripcion;
  139.     }
  140.     public function setDescripcion(?string $descripcion): self
  141.     {
  142.         $this->descripcion $descripcion;
  143.         return $this;
  144.     }
  145.     public function getCodigo(): ?string
  146.     {
  147.         return $this->codigo;
  148.     }
  149.     public function setCodigo(?string $codigo): self
  150.     {
  151.         $this->codigo $codigo;
  152.         return $this;
  153.     }
  154.     public function getTemperatura(): ?array
  155.     {
  156.         return $this->temperatura;
  157.     }
  158.     public function setTemperatura(mixed $temperatura): self
  159.     {
  160.         if ($temperatura === null) {
  161.             $this->temperatura null;
  162.             return $this;
  163.         }
  164.         if (is_array($temperatura)) {
  165.             $this->temperatura $temperatura;
  166.             return $this;
  167.         }
  168.         $this->temperatura = [[
  169.             'etiqueta' => 'De la sala',
  170.             'valor' => (string) $temperatura,
  171.         ]];
  172.         return $this;
  173.     }
  174.     public function getFecha(): ?\DateTimeInterface
  175.     {
  176.         return $this->fecha;
  177.     }
  178.     public function setFecha(?\DateTimeInterface $fecha): self
  179.     {
  180.         $this->fecha $fecha;
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return Collection<int, User>
  185.      */
  186.     public function getEvaluadores(): Collection
  187.     {
  188.         return $this->evaluadores;
  189.     }
  190.     public function addEvaluadore(User $evaluadore): self
  191.     {
  192.         if (!$this->evaluadores->contains($evaluadore)) {
  193.             $this->evaluadores->add($evaluadore);
  194.         }
  195.         return $this;
  196.     }
  197.     public function removeEvaluadore(User $evaluadore): self
  198.     {
  199.         $this->evaluadores->removeElement($evaluadore);
  200.         return $this;
  201.     }
  202.     public function getEmpresa(): ?Empresa
  203.     {
  204.         return $this->empresa;
  205.     }
  206.     public function setEmpresa(?Empresa $empresa): self
  207.     {
  208.         $this->empresa $empresa;
  209.         return $this;
  210.     }
  211.     public function getEstado(): ?string
  212.     {
  213.         return $this->estado;
  214.     }
  215.     public function setEstado(?string $estado): self
  216.     {
  217.         $this->estado $estado;
  218.         return $this;
  219.     }
  220.     /**
  221.      * @return Collection<int, SesionesValores>
  222.      */
  223.     public function getSesionesValores(): Collection
  224.     {
  225.         return $this->sesionesValores;
  226.     }
  227.     public function addSesionesValores(SesionesValores $sesionesValore): self
  228.     {
  229.         if (!$this->sesionesValores->contains($sesionesValore)) {
  230.             $this->sesionesValores->add($sesionesValore);
  231.             $sesionesValore->setSesion($this);
  232.         }
  233.         return $this;
  234.     }
  235.     public function removeSesionesValores(SesionesValores $sesionesValore): self
  236.     {
  237.         if ($this->sesionesValores->removeElement($sesionesValore)) {
  238.             // set the owning side to null (unless already changed)
  239.             if ($sesionesValore->getSesion() === $this) {
  240.                 $sesionesValore->setSesion(null);
  241.             }
  242.         }
  243.         return $this;
  244.     }
  245.     public function getControl(): ?array
  246.     {
  247.         return $this->control;
  248.     }
  249.     public function setControl(?array $control): self
  250.     {
  251.         $this->control $control;
  252.         return $this;
  253.     }
  254.     public function getEvaluacion(): ?array
  255.     {
  256.         return $this->evaluacion;
  257.     }
  258.     public function setEvaluacion(?array $evaluacion): self
  259.     {
  260.         $this->evaluacion $evaluacion;
  261.         return $this;
  262.     }
  263.     public function getOrganizacion(): ?array
  264.     {
  265.         return $this->organizacion;
  266.     }
  267.     public function setOrganizacion(?array $organizacion): self
  268.     {
  269.         $this->organizacion $organizacion;
  270.         return $this;
  271.     }
  272.     public function getParametrosMuestra(): array
  273.     {
  274.         return $this->parametrosMuestra;
  275.     }
  276.     public function setParametrosMuestra(?array $parametrosMuestra): self
  277.     {
  278.         $this->parametrosMuestra $parametrosMuestra;
  279.         return $this;
  280.     }
  281.     /**
  282.      * @return Collection<int, Muestra>
  283.      */
  284.     public function getMuestras(): Collection
  285.     {
  286.         return $this->muestras;
  287.     }
  288.     public function addMuestra(Muestra $muestra): static
  289.     {
  290.         if (!$this->muestras->contains($muestra)) {
  291.             $this->muestras->add($muestra);
  292.             $muestra->setSesion($this);
  293.         }
  294.         return $this;
  295.     }
  296.     public function removeMuestra(Muestra $muestra): static
  297.     {
  298.         if ($this->muestras->removeElement($muestra)) {
  299.             // set the owning side to null (unless already changed)
  300.             if ($muestra->getSesion() === $this) {
  301.                 $muestra->setSesion(null);
  302.             }
  303.         }
  304.         return $this;
  305.     }
  306.     public function getHoraFin(): ?\DateTimeInterface
  307.     {
  308.         return $this->horaFin;
  309.     }
  310.     public function setHoraFin(?\DateTimeInterface $horaFin): static
  311.     {
  312.         $this->horaFin $horaFin;
  313.         return $this;
  314.     }
  315. }