Message.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\MessageRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=MessageRepository::class)
  9. */
  10. class Message
  11. {
  12. /**
  13. * @ORM\Id
  14. * @ORM\GeneratedValue
  15. * @ORM\Column(type="integer")
  16. */
  17. private $id;
  18. /**
  19. * @ORM\Column(type="string", length=255)
  20. */
  21. private $text;
  22. /**
  23. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="messages")
  24. * @ORM\JoinColumn(nullable=false)
  25. */
  26. private $sender;
  27. /**
  28. * @ORM\ManyToMany(targetEntity=User::class)
  29. */
  30. private $mentions;
  31. /**
  32. * @ORM\Column(type="datetime")
  33. */
  34. private $date;
  35. public function __construct()
  36. {
  37. $this->mentions = new ArrayCollection();
  38. }
  39. public function getId(): ?int
  40. {
  41. return $this->id;
  42. }
  43. public function getText(): ?string
  44. {
  45. return $this->text;
  46. }
  47. public function setText(string $text): self
  48. {
  49. $this->text = $text;
  50. return $this;
  51. }
  52. public function getSender(): ?User
  53. {
  54. return $this->sender;
  55. }
  56. public function setSender(?User $sender): self
  57. {
  58. $this->sender = $sender;
  59. return $this;
  60. }
  61. /**
  62. * @return Collection|User[]
  63. */
  64. public function getMentions(): Collection
  65. {
  66. return $this->mentions;
  67. }
  68. public function addMention(User $mention): self
  69. {
  70. if (!$this->mentions->contains($mention)) {
  71. $this->mentions[] = $mention;
  72. }
  73. return $this;
  74. }
  75. public function removeMention(User $mention): self
  76. {
  77. $this->mentions->removeElement($mention);
  78. return $this;
  79. }
  80. public function getDate(): ?\DateTimeInterface
  81. {
  82. return $this->date;
  83. }
  84. public function setDate(\DateTimeInterface $date): self
  85. {
  86. $this->date = $date;
  87. return $this;
  88. }
  89. }