Message.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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, inversedBy="mentionedMessages")
  29. */
  30. private $mentions;
  31. /**
  32. * @ORM\Column(type="datetime")
  33. */
  34. private $date;
  35. /**
  36. * @ORM\OneToMany(targetEntity=Retweets::class, mappedBy="ogMessage", orphanRemoval=true)
  37. */
  38. private $retweets;
  39. public function __construct()
  40. {
  41. $this->mentions = new ArrayCollection();
  42. $this->retweets = new ArrayCollection();
  43. }
  44. public function getId(): ?int
  45. {
  46. return $this->id;
  47. }
  48. public function setId($id) {
  49. $this->id = $id;
  50. }
  51. public function getText(): ?string
  52. {
  53. return $this->text;
  54. }
  55. public function setText(string $text): self
  56. {
  57. $this->text = $text;
  58. return $this;
  59. }
  60. public function getSender(): ?User
  61. {
  62. return $this->sender;
  63. }
  64. public function setSender(?User $sender): self
  65. {
  66. $this->sender = $sender;
  67. return $this;
  68. }
  69. /**
  70. * @return Collection|User[]
  71. */
  72. public function getMentions(): Collection
  73. {
  74. return $this->mentions;
  75. }
  76. public function addMention(User $mention): self
  77. {
  78. if (!$this->mentions->contains($mention)) {
  79. $this->mentions[] = $mention;
  80. }
  81. return $this;
  82. }
  83. public function removeMention(User $mention): self
  84. {
  85. $this->mentions->removeElement($mention);
  86. return $this;
  87. }
  88. public function getDate(): ?\DateTimeInterface
  89. {
  90. return $this->date;
  91. }
  92. public function setDate(\DateTimeInterface $date): self
  93. {
  94. $this->date = $date;
  95. return $this;
  96. }
  97. /**
  98. * @return Collection|Retweets[]
  99. */
  100. public function getRetweets(): Collection
  101. {
  102. return $this->retweets;
  103. }
  104. public function addRetweet(Retweets $retweet): self
  105. {
  106. if (!$this->retweets->contains($retweet)) {
  107. $this->retweets[] = $retweet;
  108. $retweet->setOgMessage($this);
  109. }
  110. return $this;
  111. }
  112. public function removeRetweet(Retweets $retweet): self
  113. {
  114. if ($this->retweets->removeElement($retweet)) {
  115. // set the owning side to null (unless already changed)
  116. if ($retweet->getOgMessage() === $this) {
  117. $retweet->setOgMessage(null);
  118. }
  119. }
  120. return $this;
  121. }
  122. }