Mail.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\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. use Ramsey\Uuid\Uuid;
  12. /**
  13. * @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.
  14. * @todo : migration table tag_message
  15. *
  16. * Classe ... qui ...
  17. */
  18. #[ApiResource(operations: [])]
  19. // #[Auditable]
  20. #[ORM\Table(name: 'Message')]
  21. #[ORM\Entity]
  22. class Mail extends AbstractMessage
  23. {
  24. #[ORM\Column(length: 255, nullable: false)]
  25. protected string $discr = 'mail';
  26. #[ORM\ManyToOne(inversedBy: 'mails')]
  27. #[ORM\JoinColumn(nullable: true)]
  28. private Access $author;
  29. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'mails', cascade: ['persist'])]
  30. #[ORM\JoinTable(name: 'tag_message')]
  31. #[ORM\JoinColumn(name: 'message_id', referencedColumnName: 'id')]
  32. #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  33. protected Collection $tags;
  34. public function __construct()
  35. {
  36. $this->uuid = Uuid::uuid4();
  37. $this->files = new ArrayCollection();
  38. $this->tags = new ArrayCollection();
  39. parent::__construct();
  40. }
  41. public function getDiscr(): ?string
  42. {
  43. return $this->discr;
  44. }
  45. public function setDiscr(string $discr): self
  46. {
  47. $this->discr = $discr;
  48. return $this;
  49. }
  50. public function getAuthor(): ?Access
  51. {
  52. return $this->author;
  53. }
  54. public function setAuthor(?Access $author): self
  55. {
  56. $this->author = $author;
  57. return $this;
  58. }
  59. /**
  60. * @return Collection<int, Tagg>
  61. */
  62. public function getTags(): Collection
  63. {
  64. return $this->tags;
  65. }
  66. public function addTag(Tagg $tag): self
  67. {
  68. if (!$this->tags->contains($tag)) {
  69. $this->tags[] = $tag;
  70. }
  71. return $this;
  72. }
  73. public function removeTag(Tagg $tag): self
  74. {
  75. $this->tags->removeElement($tag);
  76. return $this;
  77. }
  78. }