Mail.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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: Tagg::class, inversedBy: 'mails', cascade: ['persist'])]
  31. #[ORM\JoinTable(name: 'tag_message')]
  32. #[ORM\JoinColumn(name: 'message_id', referencedColumnName: 'id')]
  33. #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  34. protected Collection $tags;
  35. public function __construct()
  36. {
  37. $this->uuid = Uuid::uuid4();
  38. $this->files = new ArrayCollection();
  39. $this->tags = new ArrayCollection();
  40. parent::__construct();
  41. }
  42. public function getDiscr(): ?string
  43. {
  44. return $this->discr;
  45. }
  46. public function setDiscr(string $discr): self
  47. {
  48. $this->discr = $discr;
  49. return $this;
  50. }
  51. public function getAuthor(): ?Access
  52. {
  53. return $this->author;
  54. }
  55. public function setAuthor(?Access $author): self
  56. {
  57. $this->author = $author;
  58. return $this;
  59. }
  60. /**
  61. * @return Collection<int, Tagg>
  62. */
  63. public function getTags(): Collection
  64. {
  65. return $this->tags;
  66. }
  67. public function addTag(Tagg $tag): self
  68. {
  69. if (!$this->tags->contains($tag)) {
  70. $this->tags[] = $tag;
  71. }
  72. return $this;
  73. }
  74. public function removeTag(Tagg $tag): self
  75. {
  76. $this->tags->removeElement($tag);
  77. return $this;
  78. }
  79. }