src/Entity/Messenger/Messages.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Messenger;
  3. use App\Entity\Core\Agencies;
  4. use App\Entity\Core\Users;
  5. use Doctrine\DBAL\Types\Types;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10. * Messages
  11. *
  12. * @ORM\Table("messenger_messages")
  13. * @ORM\Entity(repositoryClass="App\Repository\Messenger\MessagesRepository")
  14. * @ORM\HasLifecycleCallbacks()
  15. */
  16. class Messages
  17. {
  18. /**
  19. * @var integer
  20. *
  21. * @ORM\Column(name="id", type="integer")
  22. * @ORM\Id
  23. * @ORM\GeneratedValue(strategy="AUTO")
  24. */
  25. protected $id;
  26. /**
  27. * @var string
  28. *
  29. * @ORM\Column(name="created_at", type="datetime", nullable=true)
  30. */
  31. private $createdAt;
  32. /**
  33. * @var string
  34. *
  35. * @ORM\Column(name="updated_at", type="datetime", nullable=true)
  36. */
  37. private $updatedAt;
  38. /**
  39. * @var string
  40. *
  41. * @ORM\Column(name="message", type="text", nullable=true)
  42. */
  43. private $message;
  44. /**
  45. * @var \Users
  46. *
  47. * @ORM\ManyToOne(targetEntity="App\Entity\Core\Users")
  48. * @ORM\JoinColumns({
  49. * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true)
  50. * })
  51. */
  52. protected $user;
  53. /**
  54. * @var \Groups
  55. *
  56. * @ORM\ManyToOne(targetEntity="App\Entity\Messenger\Groups")
  57. * @ORM\JoinColumns({
  58. * @ORM\JoinColumn(name="group_id", referencedColumnName="id", nullable=true)
  59. * })
  60. */
  61. protected $group;
  62. /**
  63. * Date de lecture du message par le destinataire
  64. * null = non lu, datetime = lu à cette date
  65. *
  66. * @var \DateTimeInterface|null
  67. *
  68. * @ORM\Column(name="read_at", type="datetime", nullable=true)
  69. */
  70. private $readAt;
  71. /**
  72. * @ORM\PrePersist
  73. */
  74. public function setCreatedAtValue(): void {
  75. $this->setCreatedAt(new \DateTime("now"));
  76. $this->setUpdatedAt(new \DateTime("now"));
  77. }
  78. /**
  79. * @ORM\PreUpdate
  80. */
  81. public function setUpdatedAtValue(): void {
  82. $this->setUpdatedAt(new \DateTime("now"));
  83. }
  84. public function __toString() {
  85. return (string)$this->id;
  86. }
  87. public function getId(): ?int
  88. {
  89. return $this->id;
  90. }
  91. public function getCreatedAt(): ?\DateTimeInterface
  92. {
  93. return $this->createdAt;
  94. }
  95. public function setCreatedAt(?\DateTimeInterface $createdAt): static
  96. {
  97. $this->createdAt = $createdAt;
  98. return $this;
  99. }
  100. public function getUpdatedAt(): ?\DateTimeInterface
  101. {
  102. return $this->updatedAt;
  103. }
  104. public function setUpdatedAt(?\DateTimeInterface $updatedAt): static
  105. {
  106. $this->updatedAt = $updatedAt;
  107. return $this;
  108. }
  109. public function getMessage(): ?string
  110. {
  111. return $this->message;
  112. }
  113. public function setMessage(?string $message): static
  114. {
  115. $this->message = $message;
  116. return $this;
  117. }
  118. public function getUser(): ?Users
  119. {
  120. return $this->user;
  121. }
  122. public function setUser(?Users $user): static
  123. {
  124. $this->user = $user;
  125. return $this;
  126. }
  127. public function getGroup(): ?Groups
  128. {
  129. return $this->group;
  130. }
  131. public function setGroup(?Groups $group): static
  132. {
  133. $this->group = $group;
  134. return $this;
  135. }
  136. // ========================================
  137. // NOUVEAU — readAt (lu/non lu)
  138. // ========================================
  139. public function getReadAt(): ?\DateTimeInterface
  140. {
  141. return $this->readAt;
  142. }
  143. public function setReadAt(?\DateTimeInterface $readAt): static
  144. {
  145. $this->readAt = $readAt;
  146. return $this;
  147. }
  148. /**
  149. * Vérifie si le message a été lu
  150. */
  151. public function isRead(): bool
  152. {
  153. return $this->readAt !== null;
  154. }
  155. }