Sms.php 3.0 KB

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