src/Entity/Mensaje.php line 40

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\User;
  4. use Ramsey\Uuid\Uuid;
  5. use App\Trait\UuidTrait;
  6. use App\Entity\Documento;
  7. use ApiPlatform\Metadata\Get;
  8. use ApiPlatform\Metadata\Put;
  9. use App\Trait\BlameableTrait;
  10. use ApiPlatform\Metadata\Post;
  11. use Doctrine\DBAL\Types\Types;
  12. use ApiPlatform\Metadata\Patch;
  13. use ApiPlatform\Metadata\Delete;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use App\Trait\TimestampableTrait;
  16. use ApiPlatform\Metadata\ApiResource;
  17. use App\Repository\MensajeRepository;
  18. use ApiPlatform\Metadata\GetCollection;
  19. use Ramsey\Uuid\Doctrine\UuidGenerator;
  20. use Doctrine\Common\Collections\Collection;
  21. use Doctrine\Common\Collections\ArrayCollection;
  22. use Symfony\Component\Serializer\Annotation\Groups;
  23. use Symfony\Component\Validator\Constraints as Assert;
  24. #[ORM\Entity(repositoryClassMensajeRepository::class)]
  25. #[ApiResource(
  26.         operations: [
  27.             new GetCollection(),
  28.             new Post(validationContext: ['groups' => ['Default''mensaje:create']], denormalizationContext: ['groups' => ['mensaje:create']]),
  29.             new Get(),
  30.             new Put(denormalizationContext: ['groups' => ['mensaje:update']]),
  31.             new Patch(denormalizationContext: ['groups' => ['mensaje:update']]),
  32.             new Delete(),
  33.         ],
  34.         normalizationContext: ['groups' => ['mensaje:read''uuid']],
  35.     )
  36. ]
  37. class Mensaje
  38. {
  39.     use BlameableTrait;
  40.     use TimestampableTrait;
  41.     use UuidTrait;
  42.     public const MODULO 'mensajes';
  43.     #[Groups(['mensaje:read''mensaje:create''mensaje:update'])]
  44.     #[ORM\ManyToMany(targetEntityUser::class)]
  45.     #[ORM\JoinTable(name'mensaje_to_users')]
  46.     private Collection $toUsers;
  47.     #[Assert\NotNull(groups: ['mensaje:create'])]
  48.     #[Groups(['mensaje:read''mensaje:create''mensaje:update'])]
  49.     #[ORM\Column(length255)]
  50.     private ?string $asunto null;
  51.     #[Groups(['mensaje:read''mensaje:create''mensaje:update'])]
  52.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  53.     private ?string $cuerpo null;
  54.     #[Groups(['mensaje:read''mensaje:create''mensaje:update'])]
  55.     #[ORM\ManyToMany(targetEntityDocumento::class)]
  56.     private Collection $documentos;
  57.     #[Groups(['mensaje:read'])]
  58.     #[ORM\Column]
  59.     private ?bool $isRead null;
  60.     #[Groups(['mensaje:read'])]
  61.     #[ORM\Column]
  62.     private ?bool $isReceived null;
  63.     #[Groups(['mensaje:read'])]
  64.     #[ORM\ManyToMany(targetEntityUser::class)]
  65.     #[ORM\JoinTable(name'mensaje_favorite_users')]
  66.     private Collection $starredBy;
  67.     #[Groups(['mensaje:read'])]
  68.     #[ORM\Column]
  69.     private ?bool $isSent null;
  70.     #[Groups(['mensaje:read''mensaje:update'])]
  71.     #[ORM\ManyToMany(targetEntityUser::class)]
  72.     #[ORM\JoinTable(name'mensaje_readby_users')]
  73.     private Collection $readBy;
  74.     public function __construct()
  75.     {
  76.         $this->toUsers = new ArrayCollection();
  77.         $this->documentos = new ArrayCollection();
  78.         $this->starredBy = new ArrayCollection();
  79.         $this->readBy = new ArrayCollection();
  80.         $this->uuid Uuid::uuid4()->toString();
  81.     }
  82.     /**
  83.      * @return Collection<int, User>
  84.      */
  85.     public function getToUsers(): Collection
  86.     {
  87.         return $this->toUsers;
  88.     }
  89.     public function addToUser(User $toUser): self
  90.     {
  91.         if (!$this->toUsers->contains($toUser)) {
  92.             $this->toUsers->add($toUser);
  93.         }
  94.         return $this;
  95.     }
  96.     public function removeToUser(User $toUser): self
  97.     {
  98.         $this->toUsers->removeElement($toUser);
  99.         return $this;
  100.     }
  101.     public function getAsunto(): ?string
  102.     {
  103.         return $this->asunto;
  104.     }
  105.     public function setAsunto(string $asunto): self
  106.     {
  107.         $this->asunto $asunto;
  108.         return $this;
  109.     }
  110.     public function getCuerpo(): ?string
  111.     {
  112.         return $this->cuerpo;
  113.     }
  114.     public function setCuerpo(?string $cuerpo): self
  115.     {
  116.         $this->cuerpo $cuerpo;
  117.         return $this;
  118.     }
  119.     /**
  120.      * @return Collection<int, Documento>
  121.      */
  122.     public function getDocumentos(): Collection
  123.     {
  124.         return $this->documentos;
  125.     }
  126.     public function addDocumento(Documento $documento): self
  127.     {
  128.         if (!$this->documentos->contains($documento)) {
  129.             $this->documentos->add($documento);
  130.         }
  131.         return $this;
  132.     }
  133.     public function removeDocumento(Documento $documento): self
  134.     {
  135.         $this->documentos->removeElement($documento);
  136.         return $this;
  137.     }
  138.     public function isIsRead(): ?bool
  139.     {
  140.         return $this->isRead;
  141.     }
  142.     public function setIsRead(bool $isRead): self
  143.     {
  144.         $this->isRead $isRead;
  145.         return $this;
  146.     }
  147.     public function isIsReceived(): ?bool
  148.     {
  149.         return $this->isReceived;
  150.     }
  151.     public function setIsReceived(bool $isReceived): self
  152.     {
  153.         $this->isReceived $isReceived;
  154.         return $this;
  155.     }
  156.     /**
  157.      * @return Collection<int, User>
  158.      */
  159.     public function getStarredBy(): Collection
  160.     {
  161.         return $this->starredBy;
  162.     }
  163.     public function addStarredBy(User $starredBy): self
  164.     {
  165.         if (!$this->starredBy->contains($starredBy)) {
  166.             $this->starredBy->add($starredBy);
  167.         }
  168.         return $this;
  169.     }
  170.     public function removeStarredBy(User $starredBy): self
  171.     {
  172.         $this->starredBy->removeElement($starredBy);
  173.         return $this;
  174.     }
  175.     public function isIsSent(): ?bool
  176.     {
  177.         return $this->isSent;
  178.     }
  179.     public function setIsSent(bool $isSent): self
  180.     {
  181.         $this->isSent $isSent;
  182.         return $this;
  183.     }
  184.     /**
  185.      * @return Collection<int, User>
  186.      */
  187.     public function getReadBy(): Collection
  188.     {
  189.         return $this->readBy;
  190.     }
  191.     public function addReadBy(User $readBy): self
  192.     {
  193.         if (!$this->readBy->contains($readBy)) {
  194.             $this->readBy->add($readBy);
  195.         }
  196.         return $this;
  197.     }
  198.     public function removeReadBy(User $readBy): self
  199.     {
  200.         $this->readBy->removeElement($readBy);
  201.         return $this;
  202.     }
  203. }