Mail.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 App\Entity\Education\EducationStudent;
  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\Entity]
  22. class Mail extends AbstractMessage
  23. {
  24. #[ORM\ManyToOne(inversedBy: 'mails')]
  25. #[ORM\JoinColumn(nullable: true)]
  26. private ?Access $author = null;
  27. /** @var Collection<int, Tagg> */
  28. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'mails', cascade: ['persist'])]
  29. #[ORM\JoinTable(name: 'tag_message')]
  30. #[ORM\JoinColumn(name: 'message_id', referencedColumnName: 'id')]
  31. #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  32. protected Collection $tags;
  33. public function __construct()
  34. {
  35. $this->uuid = Uuid::uuid4();
  36. $this->files = new ArrayCollection();
  37. $this->tags = new ArrayCollection();
  38. parent::__construct();
  39. }
  40. public function getAuthor(): ?Access
  41. {
  42. return $this->author;
  43. }
  44. public function setAuthor(?Access $author): self
  45. {
  46. $this->author = $author;
  47. return $this;
  48. }
  49. /**
  50. * @return Collection<int, Tagg>
  51. */
  52. public function getTags(): Collection
  53. {
  54. return $this->tags;
  55. }
  56. public function addTag(Tagg $tag): self
  57. {
  58. if (!$this->tags->contains($tag)) {
  59. $this->tags[] = $tag;
  60. }
  61. return $this;
  62. }
  63. public function removeTag(Tagg $tag): self
  64. {
  65. $this->tags->removeElement($tag);
  66. return $this;
  67. }
  68. }