src/Entity/WorkroomChatMessage.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\WorkroomChatMessageRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * Message du chat workroom (= panneau "Messagerie" en bas-droite des
  7.  * sections workroom). Remplace l'ancienne entité {@see Chat} basée sur un
  8.  * unique BLOB HTML géré par CKEditor Cloud Services.
  9.  *
  10.  * Architecture nouveau chat (Phase 23) :
  11.  *  - Storage : 1 ligne par message (pas de blob)
  12.  *  - Presence : éphémère via Mercure, pas de table
  13.  *  - Auth : membre du workroom (voter `WorkroomVoter::WORKROOM_VIEW`)
  14.  *  - Realtime : Mercure SSE topic `/workroom/{uuid}/chat`
  15.  */
  16. #[ORM\Entity(repositoryClassWorkroomChatMessageRepository::class)]
  17. #[ORM\Table(name'workroom_chat_message')]
  18. #[ORM\Index(name'idx_workroom_created'columns: ['workroom_id''created_at'])]
  19. #[ORM\Index(name'idx_arena_created'columns: ['workroom_arena_id''created_at'])]
  20. class WorkroomChatMessage
  21. {
  22.     #[ORM\Id]
  23.     #[ORM\GeneratedValue]
  24.     #[ORM\Column(type'integer')]
  25.     private ?int $id null;
  26.     /**
  27.      * Container du chat : exactement UN des deux est non-null.
  28.      *  - workroom : chat partagé du workroom (= panneau "Messagerie")
  29.      *  - workroomArena : chat scopé à une arène (fork) — conversation
  30.      *    séparée du chat du workroom parent
  31.      */
  32.     #[ORM\ManyToOne(targetEntityWorkroom::class)]
  33.     #[ORM\JoinColumn(nullabletrueonDelete'CASCADE')]
  34.     private ?Workroom $workroom null;
  35.     #[ORM\ManyToOne(targetEntityWorkroomArena::class)]
  36.     #[ORM\JoinColumn(name'workroom_arena_id'nullabletrueonDelete'CASCADE')]
  37.     private ?WorkroomArena $workroomArena null;
  38.     #[ORM\ManyToOne(targetEntityUser::class)]
  39.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  40.     private ?User $user null;
  41.     /** Cap à 4000 chars — au-delà l'utilisateur passe par un commentaire de
  42.      *  section. Pas de markdown / HTML rich → texte brut, escape côté front. */
  43.     #[ORM\Column(type'string'length4000)]
  44.     private string $text '';
  45.     #[ORM\Column(type'datetime_immutable')]
  46.     private \DateTimeImmutable $createdAt;
  47.     public function __construct()
  48.     {
  49.         $this->createdAt = new \DateTimeImmutable();
  50.     }
  51.     public function getId(): ?int { return $this->id; }
  52.     public function getWorkroom(): ?Workroom { return $this->workroom; }
  53.     public function setWorkroom(?Workroom $w): self $this->workroom $w; return $this; }
  54.     public function getWorkroomArena(): ?WorkroomArena { return $this->workroomArena; }
  55.     public function setWorkroomArena(?WorkroomArena $a): self $this->workroomArena $a; return $this; }
  56.     public function getUser(): ?User { return $this->user; }
  57.     public function setUser(User $u): self $this->user $u; return $this; }
  58.     public function getText(): string { return $this->text; }
  59.     public function setText(string $t): self
  60.     {
  61.         $this->text mb_substr(trim($t), 04000);
  62.         return $this;
  63.     }
  64.     public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; }
  65.     public function toArray(): array
  66.     {
  67.         return [
  68.             'id' => $this->id,
  69.             'text' => $this->text,
  70.             'user' => $this->user ? [
  71.                 'id' => $this->user->getId(),
  72.                 'firstName' => $this->user->getFirstName(),
  73.                 'lastName' => $this->user->getLastName(),
  74.             ] : null,
  75.             'createdAt' => $this->createdAt->format(\DateTimeInterface::ATOM),
  76.         ];
  77.     }
  78. }