src/Entity/Mensaje.php line 40
<?phpnamespace App\Entity;use App\Entity\User;use Ramsey\Uuid\Uuid;use App\Trait\UuidTrait;use App\Entity\Documento;use ApiPlatform\Metadata\Get;use ApiPlatform\Metadata\Put;use App\Trait\BlameableTrait;use ApiPlatform\Metadata\Post;use Doctrine\DBAL\Types\Types;use ApiPlatform\Metadata\Patch;use ApiPlatform\Metadata\Delete;use Doctrine\ORM\Mapping as ORM;use App\Trait\TimestampableTrait;use ApiPlatform\Metadata\ApiResource;use App\Repository\MensajeRepository;use ApiPlatform\Metadata\GetCollection;use Ramsey\Uuid\Doctrine\UuidGenerator;use Doctrine\Common\Collections\Collection;use Doctrine\Common\Collections\ArrayCollection;use Symfony\Component\Serializer\Annotation\Groups;use Symfony\Component\Validator\Constraints as Assert;#[ORM\Entity(repositoryClass: MensajeRepository::class)]#[ApiResource(operations: [new GetCollection(),new Post(validationContext: ['groups' => ['Default', 'mensaje:create']], denormalizationContext: ['groups' => ['mensaje:create']]),new Get(),new Put(denormalizationContext: ['groups' => ['mensaje:update']]),new Patch(denormalizationContext: ['groups' => ['mensaje:update']]),new Delete(),],normalizationContext: ['groups' => ['mensaje:read', 'uuid']],)]class Mensaje{use BlameableTrait;use TimestampableTrait;use UuidTrait;public const MODULO = 'mensajes';#[Groups(['mensaje:read', 'mensaje:create', 'mensaje:update'])]#[ORM\ManyToMany(targetEntity: User::class)]#[ORM\JoinTable(name: 'mensaje_to_users')]private Collection $toUsers;#[Assert\NotNull(groups: ['mensaje:create'])]#[Groups(['mensaje:read', 'mensaje:create', 'mensaje:update'])]#[ORM\Column(length: 255)]private ?string $asunto = null;#[Groups(['mensaje:read', 'mensaje:create', 'mensaje:update'])]#[ORM\Column(type: Types::TEXT, nullable: true)]private ?string $cuerpo = null;#[Groups(['mensaje:read', 'mensaje:create', 'mensaje:update'])]#[ORM\ManyToMany(targetEntity: Documento::class)]private Collection $documentos;#[Groups(['mensaje:read'])]#[ORM\Column]private ?bool $isRead = null;#[Groups(['mensaje:read'])]#[ORM\Column]private ?bool $isReceived = null;#[Groups(['mensaje:read'])]#[ORM\ManyToMany(targetEntity: User::class)]#[ORM\JoinTable(name: 'mensaje_favorite_users')]private Collection $starredBy;#[Groups(['mensaje:read'])]#[ORM\Column]private ?bool $isSent = null;#[Groups(['mensaje:read', 'mensaje:update'])]#[ORM\ManyToMany(targetEntity: User::class)]#[ORM\JoinTable(name: 'mensaje_readby_users')]private Collection $readBy;public function __construct(){$this->toUsers = new ArrayCollection();$this->documentos = new ArrayCollection();$this->starredBy = new ArrayCollection();$this->readBy = new ArrayCollection();$this->uuid = Uuid::uuid4()->toString();}/*** @return Collection<int, User>*/public function getToUsers(): Collection{return $this->toUsers;}public function addToUser(User $toUser): self{if (!$this->toUsers->contains($toUser)) {$this->toUsers->add($toUser);}return $this;}public function removeToUser(User $toUser): self{$this->toUsers->removeElement($toUser);return $this;}public function getAsunto(): ?string{return $this->asunto;}public function setAsunto(string $asunto): self{$this->asunto = $asunto;return $this;}public function getCuerpo(): ?string{return $this->cuerpo;}public function setCuerpo(?string $cuerpo): self{$this->cuerpo = $cuerpo;return $this;}/*** @return Collection<int, Documento>*/public function getDocumentos(): Collection{return $this->documentos;}public function addDocumento(Documento $documento): self{if (!$this->documentos->contains($documento)) {$this->documentos->add($documento);}return $this;}public function removeDocumento(Documento $documento): self{$this->documentos->removeElement($documento);return $this;}public function isIsRead(): ?bool{return $this->isRead;}public function setIsRead(bool $isRead): self{$this->isRead = $isRead;return $this;}public function isIsReceived(): ?bool{return $this->isReceived;}public function setIsReceived(bool $isReceived): self{$this->isReceived = $isReceived;return $this;}/*** @return Collection<int, User>*/public function getStarredBy(): Collection{return $this->starredBy;}public function addStarredBy(User $starredBy): self{if (!$this->starredBy->contains($starredBy)) {$this->starredBy->add($starredBy);}return $this;}public function removeStarredBy(User $starredBy): self{$this->starredBy->removeElement($starredBy);return $this;}public function isIsSent(): ?bool{return $this->isSent;}public function setIsSent(bool $isSent): self{$this->isSent = $isSent;return $this;}/*** @return Collection<int, User>*/public function getReadBy(): Collection{return $this->readBy;}public function addReadBy(User $readBy): self{if (!$this->readBy->contains($readBy)) {$this->readBy->add($readBy);}return $this;}public function removeReadBy(User $readBy): self{$this->readBy->removeElement($readBy);return $this;}}