Email.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Message;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use App\Entity\Access\Access;
  6. use App\Entity\Core\File;
  7. use App\Entity\Core\Tagg;
  8. //use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Ramsey\Uuid\Uuid;
  13. /**
  14. * @todo : A la suite de la migration, il faut supprimer le nom de la table pour avoir une table Email, et supprimer l'attribut discr.
  15. * @todo : migration table tag_message
  16. *
  17. * Classe ... qui ...
  18. */
  19. //#[Auditable]
  20. #[ApiResource(operations: [])]
  21. #[ORM\Table(name: 'Message')]
  22. #[ORM\Entity]
  23. class Email extends AbstractMessage
  24. {
  25. #[ORM\Column(length: 255, nullable: false)]
  26. private string $discr = 'email';
  27. #[ORM\Column(type: 'boolean', options: ['default' => false])]
  28. private bool $isSystem = false;
  29. #[ORM\ManyToOne(inversedBy: 'emails')]
  30. #[ORM\JoinColumn(nullable: true)]
  31. private Access $author;
  32. #[ORM\OneToMany(mappedBy: 'email', targetEntity: ReportEmail::class, cascade: ['persist'], orphanRemoval: true)]
  33. private Collection $reports;
  34. #[ORM\ManyToOne(cascade: ['persist'])]
  35. #[ORM\JoinColumn(nullable: true)]
  36. private Mail $mailAttached;
  37. #[ORM\ManyToMany(targetEntity: File::class, cascade: ['persist'], orphanRemoval: true)]
  38. #[ORM\JoinTable(name: 'messages_files')]
  39. #[ORM\JoinColumn(name: 'message_id', referencedColumnName: 'id', onDelete: 'cascade')]
  40. #[ORM\InverseJoinColumn(name: 'file_id', referencedColumnName: 'id', onDelete: 'cascade')]
  41. private Collection $files;
  42. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'emails', cascade: ['persist'])]
  43. #[ORM\JoinTable(name: 'tag_message')]
  44. #[ORM\JoinColumn(name: 'message_id', referencedColumnName: 'id')]
  45. #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  46. protected Collection $tags;
  47. public function __construct()
  48. {
  49. $this->uuid = Uuid::uuid4();
  50. $this->reports = new ArrayCollection();
  51. $this->files = new ArrayCollection();
  52. $this->tags = new ArrayCollection();
  53. }
  54. public function getDiscr(): ?string
  55. {
  56. return $this->discr;
  57. }
  58. public function setDiscr(string $discr): self
  59. {
  60. $this->discr = $discr;
  61. return $this;
  62. }
  63. public function setIsSystem(bool $isSystem): self
  64. {
  65. $this->isSystem = $isSystem;
  66. return $this;
  67. }
  68. public function getIsSystem(): bool
  69. {
  70. return $this->isSystem;
  71. }
  72. public function getAuthor(): ?Access
  73. {
  74. return $this->author;
  75. }
  76. public function setAuthor(?Access $author): self
  77. {
  78. $this->author = $author;
  79. return $this;
  80. }
  81. /**
  82. * @return Collection<int, ReportEmail>
  83. */
  84. public function getReports(): Collection
  85. {
  86. return $this->reports;
  87. }
  88. public function addReport(ReportEmail $report): self
  89. {
  90. if (!$this->reports->contains($report)) {
  91. $this->reports[] = $report;
  92. $report->setEmail($this);
  93. }
  94. return $this;
  95. }
  96. public function removeReport(ReportEmail $report): self
  97. {
  98. if ($this->reports->removeElement($report)) {
  99. // set the owning side to null (unless already changed)
  100. if ($report->getEmail() === $this) {
  101. $report->setEmail(null);
  102. }
  103. }
  104. return $this;
  105. }
  106. public function getMailAttached(): ?Mail
  107. {
  108. return $this->mailAttached;
  109. }
  110. public function setMailAttached(?Mail $mailAttached): self
  111. {
  112. $this->mailAttached = $mailAttached;
  113. return $this;
  114. }
  115. /**
  116. * @return Collection<int, File>
  117. */
  118. public function getFiles(): Collection
  119. {
  120. return $this->files;
  121. }
  122. public function addFile(File $file): self
  123. {
  124. if (!$this->files->contains($file)) {
  125. $this->files[] = $file;
  126. }
  127. return $this;
  128. }
  129. public function removeFile(File $file): self
  130. {
  131. $this->files->removeElement($file);
  132. return $this;
  133. }
  134. /**
  135. * @return Collection<int, Tagg>
  136. */
  137. public function getTags(): Collection
  138. {
  139. return $this->tags;
  140. }
  141. public function addTag(Tagg $tag): self
  142. {
  143. if (!$this->tags->contains($tag)) {
  144. $this->tags[] = $tag;
  145. }
  146. return $this;
  147. }
  148. public function removeTag(Tagg $tag): self
  149. {
  150. $this->tags->removeElement($tag);
  151. return $this;
  152. }
  153. }