Mail.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 Mail, et supprimer l'attribut discr.
  15. * @todo : migration table tag_message
  16. *
  17. * Classe ... qui ...
  18. */
  19. #[ApiResource(operations: [])]
  20. // #[Auditable]
  21. #[ORM\Table(name: 'Message')]
  22. #[ORM\Entity]
  23. class Mail extends AbstractMessage
  24. {
  25. #[ORM\Column(length: 255, nullable: false)]
  26. protected string $discr = 'mail';
  27. #[ORM\ManyToOne(inversedBy: 'mails')]
  28. #[ORM\JoinColumn(nullable: true)]
  29. private Access $author;
  30. #[ORM\ManyToMany(targetEntity: File::class, cascade: ['persist'], orphanRemoval: true)]
  31. #[ORM\JoinTable(name: 'messages_files')]
  32. #[ORM\JoinColumn(name: 'message_id', referencedColumnName: 'id', onDelete: 'cascade')]
  33. #[ORM\InverseJoinColumn(name: 'file_id', referencedColumnName: 'id', onDelete: 'cascade')]
  34. private Collection $files;
  35. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'mails', cascade: ['persist'])]
  36. #[ORM\JoinTable(name: 'tag_message')]
  37. #[ORM\JoinColumn(name: 'message_id', referencedColumnName: 'id')]
  38. #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  39. protected Collection $tags;
  40. public function __construct()
  41. {
  42. $this->uuid = Uuid::uuid4();
  43. $this->files = new ArrayCollection();
  44. $this->tags = new ArrayCollection();
  45. }
  46. public function getDiscr(): ?string
  47. {
  48. return $this->discr;
  49. }
  50. public function setDiscr(string $discr): self
  51. {
  52. $this->discr = $discr;
  53. return $this;
  54. }
  55. public function getAuthor(): ?Access
  56. {
  57. return $this->author;
  58. }
  59. public function setAuthor(?Access $author): self
  60. {
  61. $this->author = $author;
  62. return $this;
  63. }
  64. /**
  65. * @return Collection<int, File>
  66. */
  67. public function getFiles(): Collection
  68. {
  69. return $this->files;
  70. }
  71. public function addFile(File $file): self
  72. {
  73. if (!$this->files->contains($file)) {
  74. $this->files[] = $file;
  75. }
  76. return $this;
  77. }
  78. public function removeFile(File $file): self
  79. {
  80. $this->files->removeElement($file);
  81. return $this;
  82. }
  83. /**
  84. * @return Collection<int, Tagg>
  85. */
  86. public function getTags(): Collection
  87. {
  88. return $this->tags;
  89. }
  90. public function addTag(Tagg $tag): self
  91. {
  92. if (!$this->tags->contains($tag)) {
  93. $this->tags[] = $tag;
  94. }
  95. return $this;
  96. }
  97. public function removeTag(Tagg $tag): self
  98. {
  99. $this->tags->removeElement($tag);
  100. return $this;
  101. }
  102. }