src/Entity/Evento.php line 36

  1. <?php
  2. namespace App\Entity;
  3. use Ramsey\Uuid\Uuid;
  4. use App\Trait\UuidTrait;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\Put;
  7. use App\Trait\BlameableTrait;
  8. use ApiPlatform\Metadata\Post;
  9. use Doctrine\DBAL\Types\Types;
  10. use ApiPlatform\Metadata\Patch;
  11. use ApiPlatform\Metadata\Delete;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use App\Trait\TimestampableTrait;
  14. use App\Repository\EventoRepository;
  15. use ApiPlatform\Metadata\ApiResource;
  16. use ApiPlatform\Metadata\GetCollection;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\Common\Collections\ArrayCollection;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. use Symfony\Component\Validator\Constraints as Assert;
  21. #[ORM\Entity(repositoryClassEventoRepository::class)]
  22. #[ApiResource(
  23.         operations: [
  24.             new GetCollection(),
  25.             new Post(validationContext: ['groups' => ['Default''evento:create']], denormalizationContext: ['groups' => ['evento:create']]),
  26.             new Get(),
  27.             new Put(denormalizationContext: ['groups' => ['evento:update']]),
  28.             new Patch(denormalizationContext: ['groups' => ['evento:update']]),
  29.             new Delete(),
  30.         ],
  31.         normalizationContext: ['groups' => ['evento:read''uuid']],
  32.     )
  33. ]
  34. class Evento
  35. {
  36.     use BlameableTrait;
  37.     use TimestampableTrait;
  38.     use UuidTrait;
  39.     
  40.     public const TIPO_MANUAL 'evento.manual';
  41.     public const TIPO_AUTOMATICO 'evento.automatico';
  42.     #[Assert\NotNull(groups: ['evento:create'])]
  43.     #[Groups(['evento:read','evento:create''evento:update'])]
  44.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  45.     private ?\DateTimeInterface $desde null;
  46.     #[Assert\NotNull(groups: ['evento:create'])]
  47.     #[Groups(['evento:read''evento:create''evento:update'])]
  48.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  49.     private ?\DateTimeInterface $hasta null;
  50.     #[Groups(['evento:read''evento:create''evento:update'])]
  51.     #[ORM\ManyToMany(targetEntityUser::class)]
  52.     private Collection $users;
  53.     #[Assert\NotNull(groups: ['evento:create'])]
  54.     #[Groups(['evento:read''evento:create''evento:update'])]
  55.     #[ORM\Column(length255)]
  56.     private ?string $titulo null;
  57.     #[Groups(['evento:read''evento:create''evento:update'])]
  58.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  59.     private ?string $descripcion null;
  60.     #[Groups(['evento:read'])]
  61.     #[ORM\Column(length255)]
  62.     private ?string $tipo null;
  63.     #[Groups(['evento:read''evento:create''evento:update'])]
  64.     #[ORM\Column(length255nullabletrue)]
  65.     private ?string $modulo null;
  66.     #[Groups(['evento:read''evento:create''evento:update'])]
  67.     #[ORM\Column(length255nullabletrue)]
  68.     private ?string $refUuid null;
  69.     #[ORM\ManyToOne(inversedBy'eventos')]
  70.     #[ORM\JoinColumn(nullablefalse)]
  71.     private ?Empresa $empresa null;
  72.     public function __construct()
  73.     {
  74.         $this->users = new ArrayCollection();
  75.         $this->uuid Uuid::uuid4()->toString();
  76.     }
  77.     public function getDesde(): ?\DateTimeInterface
  78.     {
  79.         return $this->desde;
  80.     }
  81.     public function setDesde(\DateTimeInterface $desde): self
  82.     {
  83.         $this->desde $desde;
  84.         return $this;
  85.     }
  86.     public function getHasta(): ?\DateTimeInterface
  87.     {
  88.         return $this->hasta;
  89.     }
  90.     public function setHasta(\DateTimeInterface $hasta): self
  91.     {
  92.         $this->hasta $hasta;
  93.         return $this;
  94.     }
  95.     /**
  96.      * @return Collection<int, User>
  97.      */
  98.     public function getUsers(): Collection
  99.     {
  100.         return $this->users;
  101.     }
  102.     public function addUser(User $user): self
  103.     {
  104.         if (!$this->users->contains($user)) {
  105.             $this->users->add($user);
  106.         }
  107.         return $this;
  108.     }
  109.     public function removeUser(User $user): self
  110.     {
  111.         $this->users->removeElement($user);
  112.         return $this;
  113.     }
  114.     public function getTitulo(): ?string
  115.     {
  116.         return $this->titulo;
  117.     }
  118.     public function setTitulo(string $titulo): self
  119.     {
  120.         $this->titulo $titulo;
  121.         return $this;
  122.     }
  123.     public function getDescripcion(): ?string
  124.     {
  125.         return $this->descripcion;
  126.     }
  127.     public function setDescripcion(?string $descripcion): self
  128.     {
  129.         $this->descripcion $descripcion;
  130.         return $this;
  131.     }
  132.     public function getTipo(): ?string
  133.     {
  134.         return $this->tipo;
  135.     }
  136.     public function setTipo(string $tipo): self
  137.     {
  138.         $this->tipo $tipo;
  139.         return $this;
  140.     }
  141.     public function getModulo(): ?string
  142.     {
  143.         return $this->modulo;
  144.     }
  145.     public function setModulo(?string $modulo): self
  146.     {
  147.         $this->modulo $modulo;
  148.         return $this;
  149.     }
  150.     public function getRefUuid(): ?string
  151.     {
  152.         return $this->refUuid;
  153.     }
  154.     public function setRefUuid(?string $refUuid): self
  155.     {
  156.         $this->refUuid $refUuid;
  157.         return $this;
  158.     }
  159.     public function getEmpresa(): ?Empresa
  160.     {
  161.         return $this->empresa;
  162.     }
  163.     public function setEmpresa(?Empresa $empresa): self
  164.     {
  165.         $this->empresa $empresa;
  166.         return $this;
  167.     }
  168. }