Email.php 4.4 KB

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