Email.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. protected 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. #[ORM\JoinColumn(onDelete: 'cascade')]
  34. private Collection $reports;
  35. #[ORM\ManyToOne(cascade: ['persist'])]
  36. #[ORM\JoinColumn(nullable: true)]
  37. private Mail $mailAttached;
  38. #[ORM\ManyToMany(targetEntity: File::class, cascade: ['persist'], orphanRemoval: true)]
  39. #[ORM\JoinTable(name: 'messages_files')]
  40. #[ORM\JoinColumn(name: 'message_id', referencedColumnName: 'id', onDelete: 'cascade')]
  41. #[ORM\InverseJoinColumn(name: 'file_id', referencedColumnName: 'id', onDelete: 'cascade')]
  42. private Collection $files;
  43. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'emails', cascade: ['persist'])]
  44. #[ORM\JoinTable(name: 'tag_message')]
  45. #[ORM\JoinColumn(name: 'message_id', referencedColumnName: 'id', onDelete: 'cascade')]
  46. #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id', onDelete: 'cascade')]
  47. protected Collection $tags;
  48. public function __construct()
  49. {
  50. $this->uuid = Uuid::uuid4();
  51. $this->reports = new ArrayCollection();
  52. $this->files = new ArrayCollection();
  53. $this->tags = new ArrayCollection();
  54. }
  55. public function getDiscr(): ?string
  56. {
  57. return $this->discr;
  58. }
  59. public function setDiscr(string $discr): self
  60. {
  61. $this->discr = $discr;
  62. return $this;
  63. }
  64. public function setIsSystem(bool $isSystem): self
  65. {
  66. $this->isSystem = $isSystem;
  67. return $this;
  68. }
  69. public function getIsSystem(): bool
  70. {
  71. return $this->isSystem;
  72. }
  73. public function getAuthor(): ?Access
  74. {
  75. return $this->author;
  76. }
  77. public function setAuthor(?Access $author): self
  78. {
  79. $this->author = $author;
  80. return $this;
  81. }
  82. /**
  83. * @return Collection<int, ReportEmail>
  84. */
  85. public function getReports(): Collection
  86. {
  87. return $this->reports;
  88. }
  89. public function addReport(ReportEmail $report): self
  90. {
  91. if (!$this->reports->contains($report)) {
  92. $this->reports[] = $report;
  93. $report->setEmail($this);
  94. }
  95. return $this;
  96. }
  97. public function removeReport(ReportEmail $report): self
  98. {
  99. if ($this->reports->removeElement($report)) {
  100. // set the owning side to null (unless already changed)
  101. if ($report->getEmail() === $this) {
  102. $report->setEmail(null);
  103. }
  104. }
  105. return $this;
  106. }
  107. public function getMailAttached(): ?Mail
  108. {
  109. return $this->mailAttached;
  110. }
  111. public function setMailAttached(?Mail $mailAttached): self
  112. {
  113. $this->mailAttached = $mailAttached;
  114. return $this;
  115. }
  116. /**
  117. * @return Collection<int, File>
  118. */
  119. public function getFiles(): Collection
  120. {
  121. return $this->files;
  122. }
  123. public function addFile(File $file): self
  124. {
  125. if (!$this->files->contains($file)) {
  126. $this->files[] = $file;
  127. }
  128. return $this;
  129. }
  130. public function removeFile(File $file): self
  131. {
  132. $this->files->removeElement($file);
  133. return $this;
  134. }
  135. /**
  136. * @return Collection<int, Tagg>
  137. */
  138. public function getTags(): Collection
  139. {
  140. return $this->tags;
  141. }
  142. public function addTag(Tagg $tag): self
  143. {
  144. if (!$this->tags->contains($tag)) {
  145. $this->tags[] = $tag;
  146. }
  147. return $this;
  148. }
  149. public function removeTag(Tagg $tag): self
  150. {
  151. $this->tags->removeElement($tag);
  152. return $this;
  153. }
  154. }