src/Entity/Chat/Message.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Chat;
  3. use App\Repository\Chat\MessageRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  6. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameInterface;
  7. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameTrait;
  8. use Symfony\Component\Serializer\Annotation as Serial;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampInterface;
  12. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampTrait;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. #[ORM\Entity(repositoryClassMessageRepository::class)]
  15. #[ORM\Table(name'chat_messages')]
  16. #[ORM\InheritanceType('JOINED')]
  17. #[
  18.     ORM\DiscriminatorMap(
  19.         [
  20.             'file-message' => FileMessage::class,
  21.             'message' => Message::class
  22.         ]),
  23.     Serial\DiscriminatorMap(
  24.         typeProperty'dtype',
  25.         mapping: [
  26.             'file-message' => FileMessage::class,
  27.             'message' => Message::class
  28.         ]
  29.     )
  30. ]
  31. class Message implements TimestampInterfaceBlameInterface
  32. {
  33.     use BlameTrait;
  34.     use TimestampTrait;
  35.     #[ORM\Id]
  36.     #[ORM\GeneratedValue]
  37.     #[ORM\Column(type'integer')]
  38.     #[Serial\Groups(groups: ['Message''Delete_Message''ChatNotification''Api'])]
  39.     private ?int $id null;
  40.     #[ORM\Column(type'text'nullabletrue)]
  41.     #[Serial\Groups(['PostMessage''Message''ChatNotification''PutMessage''Api'])]
  42.     #[
  43.         Assert\NotBlank(
  44.             message'entity.tchat.message.content.NotBlank',
  45.             groups: ['PostMessage''PutMessage']
  46.         ),
  47.         Assert\Length(
  48.             min2,
  49.             max5000,
  50.             minMessage'entity.tchat.message.content.min',
  51.             maxMessage'entity.tchat.message.content.max',
  52.             groups: ['PostMessage''PutMessage']
  53.         )
  54.     ]
  55.     private ?string $content null;
  56.     #[Serial\Groups(['Message''ChatNotification''Api'])]
  57.     protected $createdBy null;
  58.     #[Serial\Groups(['Message''Delete_Message''Api'])]
  59.     protected $createdAt null;
  60.     #[ORM\Column(type'array'nullabletrue)]
  61.     #[Serial\Groups(groups: ['Message''PostMessage''PutMessage'])]
  62.     private array $tags = [];
  63.     #[ORM\ManyToOne(targetEntityConversation::class, inversedBy'messages')]
  64.     #[IdGroups(groups: ['Message'])]
  65.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  66.     private ?Conversation $conversation null;
  67.     #[ORM\OneToMany(mappedBy'message'targetEntityChatNotification::class, cascade: ['persist''remove'], fetch'EXTRA_LAZY'orphanRemovaltrue)]
  68.     private ?Collection $chatNotifications null;
  69.     #[ORM\Column(type'integer')]
  70.     #[
  71.         Assert\NotBlank(message'entity.tchat.message.messageType.NotBlank'),
  72.         Assert\Type(
  73.             type"integer"
  74.         )
  75.     ]
  76.     #[Serial\Groups(groups: ['Message''PostMessage''PostFileMessage'])]
  77.     private ?int $messageType 0;
  78.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'messageChildren')]
  79.     #[ORM\JoinColumn(nullabletrueonDelete'CASCADE')]
  80.     private ?Message $messageParent null;
  81.     #[ORM\OneToMany(mappedBy'messageParent'targetEntityself::class, cascade: ['persist''remove'])]
  82.     #[Serial\Groups(groups: ['Message''Api'])]
  83.     private ?Collection $messageChildren;
  84.     #[ORM\Column(type'string'nullabletrue)]
  85.     #[Serial\Groups(groups: ['Message''PostMessage''PostFileMessage'])]
  86.     private ?string $pendingPostId null;
  87.     #[ORM\Column(type'boolean'nullablefalse)]
  88.     #[
  89.         Assert\NotNull(groups: ['TogglePinMessage']),
  90.         Assert\Type(type'boolean'groups: ['TogglePinMessage'])
  91.     ]
  92.     #[Serial\Groups(groups: ['Message''TogglePinMessage'])]
  93.     private bool $pinned false;
  94.     public function __construct()
  95.     {
  96.         $this->messageChildren = new ArrayCollection();
  97.         $this->chatNotifications = new ArrayCollection();
  98.     }
  99.     public function getFile(): ?File
  100.     {
  101.         return null;
  102.     }
  103.     public function getFileMessageType(): ?int
  104.     {
  105.         return null;
  106.     }
  107.     public function getId(): ?int
  108.     {
  109.         return $this->id;
  110.     }
  111.     public function getContent(): ?string
  112.     {
  113.         return $this->content;
  114.     }
  115.     public function setContent(string $content): self
  116.     {
  117.         $this->content $content;
  118.         return $this;
  119.     }
  120.     public function getTags(): ?array
  121.     {
  122.         return $this->tags;
  123.     }
  124.     public function setTags(?array $tags): self
  125.     {
  126.         $this->tags $tags;
  127.         return $this;
  128.     }
  129.     public function getMessageType(): ?int
  130.     {
  131.         return $this->messageType;
  132.     }
  133.     public function setMessageType(int $messageType): self
  134.     {
  135.         $this->messageType $messageType;
  136.         return $this;
  137.     }
  138.     public function getMessageParent(): ?self
  139.     {
  140.         return $this->messageParent;
  141.     }
  142.     public function setMessageParent(?self $messageParent): self
  143.     {
  144.         $this->messageParent $messageParent;
  145.         return $this;
  146.     }
  147.     /**
  148.      * @return Collection<int, self>
  149.      */
  150.     public function getMessageChildren(): Collection
  151.     {
  152.         return $this->messageChildren;
  153.     }
  154.     public function addMessageChild(self $messageChild): self
  155.     {
  156.         if (!$this->messageChildren->contains($messageChild)) {
  157.             $this->messageChildren[] = $messageChild;
  158.             $messageChild->setMessageParent($this);
  159.         }
  160.         return $this;
  161.     }
  162.     public function removeMessageChild(self $messageChild): self
  163.     {
  164.         if ($this->messageChildren->removeElement($messageChild)) {
  165.             // set the owning side to null (unless already changed)
  166.             if ($messageChild->getMessageParent() === $this) {
  167.                 $messageChild->setMessageParent(null);
  168.             }
  169.         }
  170.         return $this;
  171.     }
  172.     public function getChatNotifications(): ?Collection
  173.     {
  174.         return $this->chatNotifications;
  175.     }
  176.     public function setChatNotifications(?Collection $chatNotifications): Message
  177.     {
  178.         $this->chatNotifications $chatNotifications;
  179.         return $this;
  180.     }
  181.     public function getConversation(): ?Conversation
  182.     {
  183.         return $this->conversation;
  184.     }
  185.     public function setConversation(?Conversation $conversation): Message
  186.     {
  187.         $this->conversation $conversation;
  188.         return $this;
  189.     }
  190.     public function getPendingPostId(): ?string
  191.     {
  192.         return $this->pendingPostId;
  193.     }
  194.     public function setPendingPostId(?string $pendingPostId): Message
  195.     {
  196.         $this->pendingPostId $pendingPostId;
  197.         return $this;
  198.     }
  199.     public function isPinned(): bool
  200.     {
  201.         return $this->pinned;
  202.     }
  203.     public function setPinned(bool $pinned): Message
  204.     {
  205.         $this->pinned $pinned;
  206.         return $this;
  207.     }
  208. }